-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mobile_scanner/mobile_scanner.dart'; | ||
|
||
class MobileQrScanner extends StatefulWidget { | ||
const MobileQrScanner({super.key}); | ||
|
||
@override | ||
State<MobileQrScanner> createState() => _MobileQrScannerState(); | ||
} | ||
|
||
class _MobileQrScannerState extends State<MobileQrScanner> { | ||
Barcode? _barcode; | ||
|
||
Widget _buildBarcode(Barcode? value) { | ||
if (value == null) { | ||
return const Text( | ||
'Scan something!', | ||
overflow: TextOverflow.fade, | ||
style: TextStyle(color: Colors.white), | ||
); | ||
} | ||
|
||
return Text( | ||
value.displayValue ?? 'No display value.', | ||
overflow: TextOverflow.fade, | ||
style: const TextStyle(color: Colors.white), | ||
); | ||
} | ||
|
||
void _handleBarcode(BarcodeCapture barcodes) { | ||
if (mounted) { | ||
setState(() { | ||
_barcode = barcodes.barcodes.firstOrNull; | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Simple scanner')), | ||
backgroundColor: Colors.black, | ||
body: Stack( | ||
children: [ | ||
MobileScanner( | ||
onDetect: _handleBarcode, | ||
), | ||
Align( | ||
alignment: Alignment.bottomCenter, | ||
child: Container( | ||
alignment: Alignment.bottomCenter, | ||
height: 100, | ||
color: Colors.black.withOpacity(0.4), | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||
children: [ | ||
Expanded(child: Center(child: _buildBarcode(_barcode))), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |