bgremove_flutter 0.0.5
bgremove_flutter: ^0.0.5 copied to clipboard
AI-powered background removal for Flutter apps. Fast, client-side image processing with WebGPU acceleration.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:bgremove_flutter/bgremove_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _status = 'Not initialized';
bool _webGpuSupported = false;
@override
void initState() {
super.initState();
initPlugin();
}
Future<void> initPlugin() async {
try {
await BgRemoveFlutter.initialize();
final caps = await BgRemoveFlutter.getCapabilities();
final webGpuSupported = await BgRemoveFlutter.isWebGpuSupported();
if (!mounted) return;
setState(() {
_status = 'Initialized successfully\nDevice: ${caps.device}\nDtype: ${caps.dtype}';
_webGpuSupported = webGpuSupported;
});
} on PlatformException catch (e) {
if (!mounted) return;
setState(() {
_status = 'Failed to initialize: ${e.message}';
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('BgRemove Flutter Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_status, textAlign: TextAlign.center),
const SizedBox(height: 16),
Text('WebGPU Supported: $_webGpuSupported'),
],
),
),
),
);
}
}