Julian Steenbakker
Committed by GitHub

style: add docs

Showing 1 changed file with 105 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 +# Usage
  15 +
  16 +Import `package:mobile_scanner/mobile_scanner.dart`, and use the widget with or without the controller.
  17 +
  18 +If you don't provide a controller, you can't control functions like the torch(flash) or switching camera.
  19 +
  20 +Example without controller:
  21 +
  22 +```dart
  23 +import 'package:mobile_scanner/mobile_scanner.dart';
  24 +
  25 + @override
  26 + Widget build(BuildContext context) {
  27 + return Scaffold(
  28 + appBar: AppBar(title: const Text('Mobile Scanner')),
  29 + body: MobileScanner(
  30 + onDetect: (barcode, args) {
  31 + final String code = barcode.rawValue;
  32 + debugPrint('Barcode found! $code');
  33 + }),
  34 + );
  35 + }
  36 +```
  37 +
  38 +Example with controller and initial values:
  39 +
  40 +```dart
  41 +import 'package:mobile_scanner/mobile_scanner.dart';
  42 +
  43 + @override
  44 + Widget build(BuildContext context) {
  45 + return Scaffold(
  46 + appBar: AppBar(title: const Text('Mobile Scanner')),
  47 + body: MobileScanner(
  48 + controller: MobileScannerController(
  49 + facing: CameraFacing.front, torchEnabled: true),
  50 + onDetect: (barcode, args) {
  51 + final String code = barcode.rawValue;
  52 + debugPrint('Barcode found! $code');
  53 + }),
  54 + );
  55 + }
  56 +```
  57 +
  58 +Example with controller and torch & camera controls:
6 59
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. 60 +```dart
  61 +import 'package:mobile_scanner/mobile_scanner.dart';
11 62
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. 63 + MobileScannerController cameraController = MobileScannerController();
15 64
  65 + @override
  66 + Widget build(BuildContext context) {
  67 + return Scaffold(
  68 + appBar: AppBar(
  69 + title: const Text('Mobile Scanner'),
  70 + actions: [
  71 + IconButton(
  72 + color: Colors.white,
  73 + icon: ValueListenableBuilder(
  74 + valueListenable: cameraController.torchState,
  75 + builder: (context, state, child) {
  76 + switch (state as TorchState) {
  77 + case TorchState.off:
  78 + return const Icon(Icons.flash_off, color: Colors.grey);
  79 + case TorchState.on:
  80 + return const Icon(Icons.flash_on, color: Colors.yellow);
  81 + }
  82 + },
  83 + ),
  84 + iconSize: 32.0,
  85 + onPressed: () => cameraController.toggleTorch(),
  86 + ),
  87 + IconButton(
  88 + color: Colors.white,
  89 + icon: ValueListenableBuilder(
  90 + valueListenable: cameraController.cameraFacingState,
  91 + builder: (context, state, child) {
  92 + switch (state as CameraFacing) {
  93 + case CameraFacing.front:
  94 + return const Icon(Icons.camera_front);
  95 + case CameraFacing.back:
  96 + return const Icon(Icons.camera_rear);
  97 + }
  98 + },
  99 + ),
  100 + iconSize: 32.0,
  101 + onPressed: () => cameraController.switchCamera(),
  102 + ),
  103 + ],
  104 + ),
  105 + body: MobileScanner(
  106 + controller: cameraController,
  107 + onDetect: (barcode, args) {
  108 + final String code = barcode.rawValue;
  109 + debugPrint('Barcode found! $code');
  110 + }));
  111 + }
  112 +```