From 37adee79090f0c95bc2ac6d863eb37d008844e80 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Thu, 17 Feb 2022 09:15:03 +0100 Subject: [PATCH 1/2] style: add docs --- README.md | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f13f7cfae..4e0e8c495 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,112 @@ # mobile_scanner +[![pub package](https://img.shields.io/pub/v/mobile_scanner.svg)](https://pub.dev/packages/mobile_scanner) +[![mobile_scanner](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml/badge.svg)](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml) + An universal scanner for Flutter based on MLKit. -## Getting Started +## Platform Support + +| Android | iOS | MacOS | Web | Linux | Windows | +| :-----: | :-: | :---: | :-: | :---: | :-----: | +| ✔️ | ✔️ | | | | | + +# Usage + +Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller. + +If you don't provide a controller, you can't control functions like the torch(flash) or switching camera. + +Example without controller: + +```dart +import 'package:mobile_scanner/mobile_scanner.dart'; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Mobile Scanner')), + body: MobileScanner( + onDetect: (barcode, args) { + final String code = barcode.rawValue; + debugPrint('Barcode found! $code'); + }), + ); + } +``` + +Example with controller and initial values: + +```dart +import 'package:mobile_scanner/mobile_scanner.dart'; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('Mobile Scanner')), + body: MobileScanner( + controller: MobileScannerController( + facing: CameraFacing.front, torchEnabled: true), + onDetect: (barcode, args) { + final String code = barcode.rawValue; + debugPrint('Barcode found! $code'); + }), + ); + } +``` + +Example with controller and torch & camera controls: -This project is a starting point for a Flutter -[plug-in package](https://flutter.dev/developing-packages/), -a specialized package that includes platform-specific implementation code for -Android and/or iOS. +```dart +import 'package:mobile_scanner/mobile_scanner.dart'; -For help getting started with Flutter, view our -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. + MobileScannerController cameraController = MobileScannerController(); + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Mobile Scanner'), + actions: [ + IconButton( + color: Colors.white, + icon: ValueListenableBuilder( + valueListenable: cameraController.torchState, + builder: (context, state, child) { + switch (state as TorchState) { + case TorchState.off: + return const Icon(Icons.flash_off, color: Colors.grey); + case TorchState.on: + return const Icon(Icons.flash_on, color: Colors.yellow); + } + }, + ), + iconSize: 32.0, + onPressed: () => cameraController.toggleTorch(), + ), + IconButton( + color: Colors.white, + icon: ValueListenableBuilder( + valueListenable: cameraController.cameraFacingState, + builder: (context, state, child) { + switch (state as CameraFacing) { + case CameraFacing.front: + return const Icon(Icons.camera_front); + case CameraFacing.back: + return const Icon(Icons.camera_rear); + } + }, + ), + iconSize: 32.0, + onPressed: () => cameraController.switchCamera(), + ), + ], + ), + body: MobileScanner( + controller: cameraController, + onDetect: (barcode, args) { + final String code = barcode.rawValue; + debugPrint('Barcode found! $code'); + })); + } +``` From 3ae8f126d050bb35eadf9e68d93fb0e4e95bdb92 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Thu, 17 Feb 2022 09:39:33 +0100 Subject: [PATCH 2/2] doc: add min sdk --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4e0e8c495..51af7b65e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ An universal scanner for Flutter based on MLKit. | :-----: | :-: | :---: | :-: | :---: | :-----: | | ✔️ | ✔️ | | | | | +CameraX for Android requires at least SDK 21. + +MLKit for iOS requires at least iOS 11 and a [64bit device](https://developers.google.com/ml-kit/migration/ios). + # Usage Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller.