Background Remover Flutter Plugin

This Flutter plugin allows users to remove the background from images using a simple interface. It utilizes the backraund plugin to remove the background from an image selected from the gallery. Below is a guide on how to use the plugin in your Flutter application.

Installation

  1. Add the backraund and image_picker dependencies to your pubspec.yaml file:
dependencies:
  flutter:
    sdk: flutter
  backraund: ^latest_version # replace with the latest version
  image_picker: ^latest_version # replace with the latest version 
  

Here’s how to use the Background Remover plugin in your Flutter app:

Import necessary packages:
import 'dart:io';
import 'package:backraund/backraund.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

Create a simple Flutter app with image picker and background removal functionality:

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final backraundPlugin = Backraund();
  File? file;
  var result;

  // Call the plugin to remove the background
  callPlugin() async {
    result = await backraundPlugin.remomeBackrond(path: file!.path);
    setState(() {});
  }

  // Use Image Picker to pick an image from the gallery
  imagePiker() async {
    var selected = await ImagePicker().pickImage(source: ImageSource.gallery);
    if (selected == null) {
      return;
    }
    file = File(selected.path);
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Background Remover'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            // Display selected or processed image
            result != null
                ? Image.memory(
                    result!,
                    fit: BoxFit.fill,
                    height: 350,
                  )
                : file != null
                    ? Image.file(
                        file!,
                        fit: BoxFit.fill,
                        height: 350,
                      )
                    : const SizedBox(),

            const SizedBox(height: 20),
            
            // Button to pick an image
            ElevatedButton(
              onPressed: () async {
                imagePiker();
              },
              child: const Text('Pick Image'),
            ),
            
            // Button to remove the background
            ElevatedButton(
              onPressed: () async {
                callPlugin();
              },
              child: const Text('Remove Background'),
            ),
          ],
        ),
      ),
    );
  }
}

Steps: Pick Image: The first button (Pick Image) allows you to choose an image from your gallery.

Remove Background: The second button (Remove Background) calls the background removal functionality and displays the processed image.

Result: After selecting an image and removing the background, the processed image will be displayed in your app.

Additional Information Make sure you have appropriate permissions for accessing the device’s gallery.

The backraund plugin processes the image asynchronously, so ensure you handle the Future properly in your application.

This example assumes you are building for platforms that support the image_picker plugin, like Android and iOS.

License This project is licensed under the MIT License - see the LICENSE file for details.

Key Explanations:

  1. Installation: The plugin dependencies are added to the pubspec.yaml file, and the user is instructed to run flutter pub get to install them.
  2. Usage: The core logic for using the plugin is explained, with the sample code provided in a clear and structured manner.
  3. Buttons: Users can pick an image and remove its background with the two buttons provided in the UI.
  4. Image Handling: The image picked from the gallery is either displayed or the background is removed and displayed.

This should help users easily understand how to use your Flutter plugin!