my_filter_camera 3.0.0 copy "my_filter_camera: ^3.0.0" to clipboard
my_filter_camera: ^3.0.0 copied to clipboard

This package lets you use the camera with advanced digital filters, apply real-time effects, and customize your camera experience easily.

example/lib/main.dart

import 'dart:async';

import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:my_filter_camera/my_filter_camera.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runApp(const MaterialApp(home: CameraTestScreen()));
}

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

  @override
  State<CameraTestScreen> createState() => _CameraTestScreenState();
}

class _CameraTestScreenState extends State<CameraTestScreen> {
  final CameraViewController controller = CameraViewController();

  bool isStarted = false;

  @override
  void initState() {
    super.initState();

    // Subscribe to the video data state from the camera controller

    controller.applyImageSample();
    _loadPreferences();
  }

  // Initialize video player with the recorded video file
  double _currentSliderValue = 0;
  Future<void> _loadPreferences() async {
    // final prefs = await SharedPreferences.getInstance();
    // final int? brightnessValue = prefs.getInt('brightnessValue');
  }

  Future<void> _setPreferences({required double brightnessValue}) async {
    final prefs = await SharedPreferences.getInstance();
    await prefs.setDouble('brightnessValue', brightnessValue);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Stack(
        children: [
          Positioned.fill(
            child: CameraView(
              autoDispose: false,
              controller: controller,
              enablePinchToZoom: true,
              enableTapToFocus: true,
              onDetect: (data, args) {
                setState(() {});
              },
            ),
          ),
          // Bottom control panel
          Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              height: 200,
              color: Colors.black.withValues(alpha: 0.4),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  ValueListenableBuilder<CameraArguments?>(
                    valueListenable: controller.args,
                    builder: (context, camera, child) {
                      final supported = camera?.supportsExposureOffset == true;
                      final minimum = supported
                          ? camera!.minExposureOffset
                          : -1.0;
                      final maximum = supported
                          ? camera!.maxExposureOffset
                          : 1.0;
                      final value = _currentSliderValue
                          .clamp(minimum, maximum)
                          .toDouble();
                      return Slider(
                        value: value,
                        max: maximum,
                        min: minimum,
                        divisions: supported
                            ? ((maximum - minimum) * 10).round().clamp(1, 100)
                            : null,
                        label: value.toStringAsFixed(1),
                        onChanged: supported
                            ? (value) {
                                setState(() => _currentSliderValue = value);
                                unawaited(controller.setExposureOffset(value));
                                unawaited(
                                  _setPreferences(brightnessValue: value),
                                );
                              }
                            : null,
                      );
                    },
                  ),
                  // Filter selection and controls
                  SizedBox(
                    height: 50,
                    child: ListView.builder(
                      itemCount: PluginFilterEnum.values.length,
                      scrollDirection: Axis.horizontal,
                      itemBuilder: (context, index) {
                        return ElevatedButton(
                          onPressed: () async {
                            await controller.updateFilter(
                              filterType: PluginFilterEnum.values[index].code,
                            );
                          },
                          child: Text(PluginFilterEnum.values[index].name),
                        );
                      },
                    ),
                  ),
                  // Record, stop, and camera switch controls
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: [
                      IconButton(
                        color: Colors.white,
                        icon: ValueListenableBuilder(
                          valueListenable: controller.cameraFacingState,
                          builder: (context, state, child) {
                            switch (state) {
                              case CameraFacing.front:
                                return const Icon(Icons.camera_front);
                              case CameraFacing.back:
                                return const Icon(Icons.camera_rear);
                            }
                          },
                        ),
                        iconSize: 32.0,
                        onPressed: () => controller.switchCamera(),
                      ),
                      IconButton(
                        icon: const Icon(
                          Icons.camera_alt_outlined,
                          size: 40,
                          color: Colors.white,
                        ),
                        onPressed: () async {
                          final xFile = await controller.capture();
                          final utf8 = await xFile.readAsBytes();
                          if (!context.mounted) return;
                          showDialog(
                            context: context,
                            builder: (BuildContext context) {
                              return AlertDialog(
                                title: const Text('Image preview'),
                                content: ExtendedImage.memory(
                                  utf8,
                                  fit: BoxFit.cover,
                                  filterQuality: FilterQuality.high,
                                ),
                                actions: <Widget>[
                                  TextButton(
                                    child: const Text('Close'),
                                    onPressed: () {
                                      Navigator.of(context)
                                          .pop(); // Đóng dialog
                                    },
                                  ),
                                ],
                              );
                            },
                          );
                        },
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }
}
5
likes
160
points
185
downloads
screenshot

Documentation

API reference

Publisher

verified publisherwongcoupon.com

Weekly Downloads

This package lets you use the camera with advanced digital filters, apply real-time effects, and customize your camera experience easily.

Repository (GitHub)
View/report issues

Topics

#camera #photo-filters #real-time-effects #photography #media

Funding

Consider supporting this project:

github.com
www.buymeacoffee.com

License

MIT (license)

Dependencies

cross_file, flutter

More

Packages that depend on my_filter_camera

Packages that implement my_filter_camera