libvips_ffi 0.0.1+8.16.0
libvips_ffi: ^0.0.1+8.16.0 copied to clipboard
Flutter FFI bindings for libvips - a fast, multi-threaded image processing library. Supports resize, crop, rotate, blur, sharpen, and more.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:libvips_ffi/libvips_ffi.dart';
import 'pages/developer_tools_page.dart';
import 'pages/examples_page.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Vips Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String _vipsVersion = 'Loading...';
String _status = 'Initializing...';
@override
void initState() {
super.initState();
_initVips();
}
Future<void> _initVips() async {
try {
initVips();
final major = vipsVersion(0);
final minor = vipsVersion(1);
final micro = vipsVersion(2);
setState(() {
_vipsVersion = '$major.$minor.$micro';
_status = 'libvips initialized successfully ✓';
});
} catch (e) {
setState(() {
_vipsVersion = 'Error';
_status = 'Failed to initialize: $e';
});
}
}
@override
void dispose() {
shutdownVips();
VipsImageAsync.shutdown();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Vips Example'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Version Card
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
const Icon(Icons.image, size: 48, color: Colors.blue),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'libvips $_vipsVersion',
style: Theme.of(context).textTheme.titleLarge,
),
const SizedBox(height: 4),
Text(
_status,
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
],
),
),
),
const SizedBox(height: 24),
// Navigation Buttons
Text(
'Get Started / 开始使用',
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 16),
_buildNavButton(
context,
title: 'Examples / 示例',
subtitle: 'Learn with code examples and try them live',
icon: Icons.code,
color: Colors.green,
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const ExamplesPage()),
),
),
const SizedBox(height: 12),
_buildNavButton(
context,
title: 'Developer Tools / 开发者工具',
subtitle: 'Testing, benchmarking, and diagnostics',
icon: Icons.developer_mode,
color: Colors.orange,
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const DeveloperToolsPage()),
),
),
const Spacer(),
// Info
Card(
color: Colors.blue.shade50,
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.info_outline, color: Colors.blue.shade700),
const SizedBox(width: 8),
Text(
'About',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.blue.shade700,
),
),
],
),
const SizedBox(height: 8),
const Text(
'This example demonstrates the libvips_ffi plugin, '
'which provides FFI bindings for the libvips image processing library.\n\n'
'• Sync API: Direct calls, may block UI\n'
'• Async API: Runs in isolate, keeps UI responsive',
style: TextStyle(fontSize: 13),
),
],
),
),
),
],
),
),
);
}
Widget _buildNavButton(
BuildContext context, {
required String title,
required String subtitle,
required IconData icon,
required VoidCallback onTap,
Color color = Colors.blue,
}) {
return Card(
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: color.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
),
child: Icon(icon, size: 32, color: color),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context).textTheme.titleMedium,
),
Text(
subtitle,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
const Icon(Icons.chevron_right),
],
),
),
),
);
}
}