background_remover 0.0.3 copy "background_remover: ^0.0.3" to clipboard
background_remover: ^0.0.3 copied to clipboard

PlatformAndroid

Flutter package that remove background of a selfie

example/lib/main.dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:background_remover/background_remover.dart';
import 'package:image_picker/image_picker.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Background remover'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Uint8List? image;
  bool isLoading = false;

  Future<void> _pickImage() async {
    setState(() {
      image = null;
    });
    final ImagePicker picker = ImagePicker();
    final XFile? pickedFile =
        await picker.pickImage(source: ImageSource.gallery);

    if (pickedFile != null) {
      setState(() {
        isLoading = true;
      });
      final Uint8List imageBytes = await pickedFile.readAsBytes();
      image = await removeBackground(imageBytes: imageBytes);
      setState(() {
        isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            if (image != null) Image.memory(image!),
            if (isLoading) const LinearProgressIndicator()
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _pickImage,
        child: const Icon(Icons.image),
      ),
    );
  }
}
22
likes
130
pub points
86%
popularity

Publisher

unverified uploader

Flutter package that remove background of a selfie

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

flutter

More

Packages that depend on background_remover