Julian Steenbakker

Merge remote-tracking branch 'origin/master'

Showing 1 changed file with 109 additions and 8 deletions
1 # mobile_scanner 1 # mobile_scanner
2 2
  3 +[![pub package](https://img.shields.io/pub/v/mobile_scanner.svg)](https://pub.dev/packages/mobile_scanner)
  4 +[![mobile_scanner](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml/badge.svg)](https://github.com/juliansteenbakker/mobile_scanner/actions/workflows/flutter.yml)
  5 +
3 An universal scanner for Flutter based on MLKit. 6 An universal scanner for Flutter based on MLKit.
4 7
5 -## Getting Started 8 +## Platform Support
  9 +
  10 +| Android | iOS | MacOS | Web | Linux | Windows |
  11 +| :-----: | :-: | :---: | :-: | :---: | :-----: |
  12 +| ✔️ | ✔️ | | | | |
  13 +
  14 +CameraX for Android requires at least SDK 21.
  15 +
  16 +MLKit for iOS requires at least iOS 11 and a [64bit device](https://developers.google.com/ml-kit/migration/ios).
  17 +
  18 +# Usage
  19 +
  20 +Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller.
  21 +
  22 +If you don't provide a controller, you can't control functions like the torch(flash) or switching camera.
  23 +
  24 +Example without controller:
  25 +
  26 +```dart
  27 +import 'package:mobile_scanner/mobile_scanner.dart';
  28 +
  29 + @override
  30 + Widget build(BuildContext context) {
  31 + return Scaffold(
  32 + appBar: AppBar(title: const Text('Mobile Scanner')),
  33 + body: MobileScanner(
  34 + onDetect: (barcode, args) {
  35 + final String code = barcode.rawValue;
  36 + debugPrint('Barcode found! $code');
  37 + }),
  38 + );
  39 + }
  40 +```
  41 +
  42 +Example with controller and initial values:
  43 +
  44 +```dart
  45 +import 'package:mobile_scanner/mobile_scanner.dart';
  46 +
  47 + @override
  48 + Widget build(BuildContext context) {
  49 + return Scaffold(
  50 + appBar: AppBar(title: const Text('Mobile Scanner')),
  51 + body: MobileScanner(
  52 + controller: MobileScannerController(
  53 + facing: CameraFacing.front, torchEnabled: true),
  54 + onDetect: (barcode, args) {
  55 + final String code = barcode.rawValue;
  56 + debugPrint('Barcode found! $code');
  57 + }),
  58 + );
  59 + }
  60 +```
  61 +
  62 +Example with controller and torch & camera controls:
6 63
7 -This project is a starting point for a Flutter  
8 -[plug-in package](https://flutter.dev/developing-packages/),  
9 -a specialized package that includes platform-specific implementation code for  
10 -Android and/or iOS. 64 +```dart
  65 +import 'package:mobile_scanner/mobile_scanner.dart';
11 66
12 -For help getting started with Flutter, view our  
13 -[online documentation](https://flutter.dev/docs), which offers tutorials,  
14 -samples, guidance on mobile development, and a full API reference. 67 + MobileScannerController cameraController = MobileScannerController();
15 68
  69 + @override
  70 + Widget build(BuildContext context) {
  71 + return Scaffold(
  72 + appBar: AppBar(
  73 + title: const Text('Mobile Scanner'),
  74 + actions: [
  75 + IconButton(
  76 + color: Colors.white,
  77 + icon: ValueListenableBuilder(
  78 + valueListenable: cameraController.torchState,
  79 + builder: (context, state, child) {
  80 + switch (state as TorchState) {
  81 + case TorchState.off:
  82 + return const Icon(Icons.flash_off, color: Colors.grey);
  83 + case TorchState.on:
  84 + return const Icon(Icons.flash_on, color: Colors.yellow);
  85 + }
  86 + },
  87 + ),
  88 + iconSize: 32.0,
  89 + onPressed: () => cameraController.toggleTorch(),
  90 + ),
  91 + IconButton(
  92 + color: Colors.white,
  93 + icon: ValueListenableBuilder(
  94 + valueListenable: cameraController.cameraFacingState,
  95 + builder: (context, state, child) {
  96 + switch (state as CameraFacing) {
  97 + case CameraFacing.front:
  98 + return const Icon(Icons.camera_front);
  99 + case CameraFacing.back:
  100 + return const Icon(Icons.camera_rear);
  101 + }
  102 + },
  103 + ),
  104 + iconSize: 32.0,
  105 + onPressed: () => cameraController.switchCamera(),
  106 + ),
  107 + ],
  108 + ),
  109 + body: MobileScanner(
  110 + controller: cameraController,
  111 + onDetect: (barcode, args) {
  112 + final String code = barcode.rawValue;
  113 + debugPrint('Barcode found! $code');
  114 + }));
  115 + }
  116 +```