camera_package 0.0.6 copy "camera_package: ^0.0.6" to clipboard
camera_package: ^0.0.6 copied to clipboard

Bio Camera

example/main.dart

import 'dart:io';
import 'package:camera_package/camera_singleton/FaceDetectionController.dart';
import 'package:camera_package/camera_singleton/FaceDetectionView.dart';
import 'package:camera_package/camera_singleton/Utills.dart';
import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // NOT running on the web! You can check for additional platforms here.
  runApp(CamWidget());
}

class CamWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Utills.setOrientation();
    return MaterialApp(
      title: 'Capture Options',
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.white, // Set background to white
        appBar: AppBar(
          title: Text('Capture Options'),
          backgroundColor: Colors.white,
          foregroundColor: Colors.black, // Makes title text black
          elevation: 1, // Optional: adds subtle shadow
        ),
        body: Center(
          child: TwoButtonWidget(),
        ),
      ),
    );
  }
}

class TwoButtonWidget extends StatefulWidget {
  @override
  _TwoButtonWidgetState createState() => _TwoButtonWidgetState();
}

class _TwoButtonWidgetState extends State<TwoButtonWidget> {
  void _onPressed(bool autoClik, bool showButton, ActionStatus registration,
      String title, bool navigateFlag) {
    // restartFaceDetection
    Navigator.push(
      context,
      MaterialPageRoute(
          builder: (_) => FaceDetectionView(
                actionType: registration,
                screenTitle: title,
                defalutCam: camCall.Front,
                showCameraIcon: showButton,
                showSwitchCameraIcon: true,
                callWithNavigate: navigateFlag,
                autoClickCamera: autoClik,
                batterySaverBrightness: false,
                showLogo: false,
                // switchCameraButton: Positioned(
                //   bottom: 30,
                //   right: 20,
                //   child: Center(
                //     child: Icon(
                //       size: 50,
                //       Icons.refresh,
                //       color: Colors.white,
                //     ),
                //   ),
                // ),
                // captureButton: SizedBox(
                //   width: 200,
                //   child: ButtonView(
                //     text: "Click",
                //     fontSize: 15.sp,
                //     showIcon: false,
                //     showLoader: true,
                //   ),
                // ),
                onFieldSubmitted: (value) {
                  Utills.printLogs("FaceImagePath $value");
                  FaceDetectionController.instance
                      .setStatus(Status.Warning, "Face already register");
                  Future.delayed(const Duration(seconds: 2), () {
                    FaceDetectionController.instance.reTake();
                  });
                  // Navigator.pushReplacement(
                  //   context,
                  //   MaterialPageRoute(
                  //     builder: (context) =>
                  //         HomeWidget(imagePath: value),
                  //     settings: RouteSettings(arguments: {"imagePath": value}),
                  //   ),
                  // );
                },
              )),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        SizedBox(
          height: 30,
        ),
        SizedBox(
          width: 300,
          child: ElevatedButton(
            onPressed: () => _onPressed(true, false, ActionStatus.Registration,
                'Face Registration', true),
            child: Text('Auto Capture – Registration',
                style: TextStyle(fontSize: 16)),
          ),
        ),
        SizedBox(height: 16),
        SizedBox(
          width: 300,
          child: ElevatedButton(
            onPressed: () => _onPressed(true, false,
                ActionStatus.Authentication, "Face authentication", false),
            child: Text(
              'Auto Capture – Authentication',
              style: TextStyle(fontSize: 16),
            ),
          ),
        ),
        SizedBox(height: 16),
        SizedBox(
          width: 300,
          child: ElevatedButton(
            onPressed: () => _onPressed(false, true, ActionStatus.Registration,
                'Face Registration', false),
            child: Text('Manual Capture- Registration',
                style: TextStyle(fontSize: 16)),
          ),
        ),
        SizedBox(height: 16),
        SizedBox(
          width: 300,
          child: ElevatedButton(
            onPressed: () => _onPressed(false, true,
                ActionStatus.Authentication, 'Face authentication', false),
            child: Text('Manual Capture – Authentication',
                style: TextStyle(fontSize: 16)),
          ),
        ),
      ],
    );
  }
}

class HomeWidget extends StatelessWidget {
  final String imagePath;

  const HomeWidget({required this.imagePath, super.key});

  @override
  Widget build(BuildContext context) {
    Utills.setOrientation();
    return PopScope(
      canPop: false,
      onPopInvokedWithResult: (bool didPop, Object? result) async {
        Navigator.pushReplacement(
          context,
          MaterialPageRoute(builder: (_) => CamWidget()),
        );
      },
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: const Text('Home'),
          leading: BackButton(
            onPressed: () {
              Navigator.pushReplacement(
                context,
                MaterialPageRoute(builder: (_) => CamWidget()),
              );
            },
          ),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Image.file(
                File(imagePath),
                width: 250,
                height: 250,
                fit: BoxFit.cover,
              ),
              const SizedBox(height: 20),
              const Text(
                'Your Image',
                style: TextStyle(fontSize: 24, fontWeight: FontWeight.normal),
              ),
            ],
          ),
        ),
      ),
    );
  }
}