Revert "remove obsolete example"
This reverts commit 6957e103.
Showing
2 changed files
with
81 additions
and
0 deletions
| 1 | +import 'package:flutter/material.dart'; | ||
| 2 | +import 'package:mobile_scanner/mobile_scanner.dart'; | ||
| 3 | + | ||
| 4 | +class BarcodeScannerWithoutController extends StatefulWidget { | ||
| 5 | + const BarcodeScannerWithoutController({Key? key}) : super(key: key); | ||
| 6 | + | ||
| 7 | + @override | ||
| 8 | + _BarcodeScannerWithoutControllerState createState() => | ||
| 9 | + _BarcodeScannerWithoutControllerState(); | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +class _BarcodeScannerWithoutControllerState | ||
| 13 | + extends State<BarcodeScannerWithoutController> | ||
| 14 | + with SingleTickerProviderStateMixin { | ||
| 15 | + BarcodeCapture? capture; | ||
| 16 | + | ||
| 17 | + @override | ||
| 18 | + Widget build(BuildContext context) { | ||
| 19 | + return Scaffold( | ||
| 20 | + backgroundColor: Colors.black, | ||
| 21 | + body: Builder( | ||
| 22 | + builder: (context) { | ||
| 23 | + return Stack( | ||
| 24 | + children: [ | ||
| 25 | + MobileScanner( | ||
| 26 | + fit: BoxFit.contain, | ||
| 27 | + onDetect: (capture) { | ||
| 28 | + setState(() { | ||
| 29 | + this.capture = capture; | ||
| 30 | + }); | ||
| 31 | + }, | ||
| 32 | + ), | ||
| 33 | + Align( | ||
| 34 | + alignment: Alignment.bottomCenter, | ||
| 35 | + child: Container( | ||
| 36 | + alignment: Alignment.bottomCenter, | ||
| 37 | + height: 100, | ||
| 38 | + color: Colors.black.withOpacity(0.4), | ||
| 39 | + child: Row( | ||
| 40 | + mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
| 41 | + children: [ | ||
| 42 | + Center( | ||
| 43 | + child: SizedBox( | ||
| 44 | + width: MediaQuery.of(context).size.width - 120, | ||
| 45 | + height: 50, | ||
| 46 | + child: FittedBox( | ||
| 47 | + child: Text( | ||
| 48 | + capture?.barcodes.first.rawValue ?? | ||
| 49 | + 'Scan something!', | ||
| 50 | + overflow: TextOverflow.fade, | ||
| 51 | + style: Theme.of(context) | ||
| 52 | + .textTheme | ||
| 53 | + .headline4! | ||
| 54 | + .copyWith(color: Colors.white), | ||
| 55 | + ), | ||
| 56 | + ), | ||
| 57 | + ), | ||
| 58 | + ), | ||
| 59 | + ], | ||
| 60 | + ), | ||
| 61 | + ), | ||
| 62 | + ), | ||
| 63 | + ], | ||
| 64 | + ); | ||
| 65 | + }, | ||
| 66 | + ), | ||
| 67 | + ); | ||
| 68 | + } | ||
| 69 | +} |
| @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; | @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; | ||
| 2 | import 'package:mobile_scanner_example/barcode_list_scanner_controller.dart'; | 2 | import 'package:mobile_scanner_example/barcode_list_scanner_controller.dart'; |
| 3 | import 'package:mobile_scanner_example/barcode_scanner_controller.dart'; | 3 | import 'package:mobile_scanner_example/barcode_scanner_controller.dart'; |
| 4 | import 'package:mobile_scanner_example/barcode_scanner_returning_image.dart'; | 4 | import 'package:mobile_scanner_example/barcode_scanner_returning_image.dart'; |
| 5 | +import 'package:mobile_scanner_example/barcode_scanner_without_controller.dart'; | ||
| 5 | 6 | ||
| 6 | void main() => runApp(const MaterialApp(home: MyHome())); | 7 | void main() => runApp(const MaterialApp(home: MyHome())); |
| 7 | 8 | ||
| @@ -50,6 +51,17 @@ class MyHome extends StatelessWidget { | @@ -50,6 +51,17 @@ class MyHome extends StatelessWidget { | ||
| 50 | child: | 51 | child: |
| 51 | const Text('MobileScanner with Controller (returning image)'), | 52 | const Text('MobileScanner with Controller (returning image)'), |
| 52 | ), | 53 | ), |
| 54 | + ElevatedButton( | ||
| 55 | + onPressed: () { | ||
| 56 | + Navigator.of(context).push( | ||
| 57 | + MaterialPageRoute( | ||
| 58 | + builder: (context) => | ||
| 59 | + const BarcodeScannerWithoutController(), | ||
| 60 | + ), | ||
| 61 | + ); | ||
| 62 | + }, | ||
| 63 | + child: const Text('MobileScanner without Controller'), | ||
| 64 | + ), | ||
| 53 | ], | 65 | ], |
| 54 | ), | 66 | ), |
| 55 | ), | 67 | ), |
-
Please register or login to post a comment