|
|
@ -1,3 +1,5 @@ |
|
|
|
|
|
|
|
import 'dart:typed_data'; |
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_zxing/flutter_zxing.dart'; |
|
|
|
import 'package:flutter_zxing/flutter_zxing.dart'; |
|
|
|
|
|
|
|
|
|
|
@ -16,9 +18,26 @@ class _MyAppState extends State<MyApp> { |
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
FlutterZxing.setLogEnabled(true); |
|
|
|
FlutterZxing.setLogEnabled(true); |
|
|
|
return MaterialApp( |
|
|
|
return const MaterialApp( |
|
|
|
title: 'Flutter Zxing Example', |
|
|
|
title: 'Flutter Zxing Example', |
|
|
|
home: DefaultTabController( |
|
|
|
home: DemoPage(), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DemoPage extends StatefulWidget { |
|
|
|
|
|
|
|
const DemoPage({Key? key}) : super(key: key); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
State<DemoPage> createState() => _DemoPageState(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _DemoPageState extends State<DemoPage> { |
|
|
|
|
|
|
|
Uint8List? createdCodeBytes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
|
|
|
return DefaultTabController( |
|
|
|
length: 2, |
|
|
|
length: 2, |
|
|
|
child: Scaffold( |
|
|
|
child: Scaffold( |
|
|
|
appBar: AppBar( |
|
|
|
appBar: AppBar( |
|
|
@ -35,16 +54,37 @@ class _MyAppState extends State<MyApp> { |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
ReaderWidget( |
|
|
|
ReaderWidget( |
|
|
|
onScan: (value) { |
|
|
|
onScan: (value) { |
|
|
|
debugPrint(value.textString ?? ''); |
|
|
|
showMessage(context, 'Scanned: ${value.textString ?? ''}'); |
|
|
|
}, |
|
|
|
}, |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
ListView( |
|
|
|
|
|
|
|
children: [ |
|
|
|
WriterWidget( |
|
|
|
WriterWidget( |
|
|
|
onSuccess: (result, bytes) {}, |
|
|
|
onSuccess: (result, bytes) { |
|
|
|
onError: (error) {}, |
|
|
|
setState(() { |
|
|
|
|
|
|
|
createdCodeBytes = bytes; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
onError: (error) { |
|
|
|
|
|
|
|
showMessage(context, 'Error: $error'); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
if (createdCodeBytes != null) |
|
|
|
|
|
|
|
Image.memory(createdCodeBytes ?? Uint8List(0), height: 200), |
|
|
|
|
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showMessage(BuildContext context, String message) { |
|
|
|
|
|
|
|
debugPrint(message); |
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar(); |
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar( |
|
|
|
|
|
|
|
SnackBar( |
|
|
|
|
|
|
|
content: Text(message), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|