From d011e542b671af421efe34862092f41bf3c11da7 Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Wed, 11 May 2022 21:00:10 +0400 Subject: [PATCH] code refactore --- README.md | 2 +- example/lib/pages/creator_page.dart | 16 +++------------- example/lib/pages/scanner_page.dart | 2 +- lib/flutter_zxing.dart | 4 ++-- ...ing_reader_widget.dart => reader_widget.dart} | 8 ++++---- ...ing_writer_widget.dart => writer_widget.dart} | 8 ++++---- 6 files changed, 15 insertions(+), 25 deletions(-) rename lib/{zxing_reader_widget.dart => reader_widget.dart} (96%) rename lib/{zxing_writer_widget.dart => writer_widget.dart} (97%) diff --git a/README.md b/README.md index a759acc..94ad49f 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Widget build(BuildContext context) { // Or use FlutterZxing to create barcode directly final text = 'Text to encode'; -final result = FlutterZxing.encodeBarcode(text, 300, 300, Format.Any, 10, 0); +final result = FlutterZxing.encodeBarcode(text, 300, 300, Format.QRCode, 10, 0); if (result.isValidBool) { final img = imglib.Image.fromBytes(width, height, result.bytes); final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img)); diff --git a/example/lib/pages/creator_page.dart b/example/lib/pages/creator_page.dart index 95c7570..ce01404 100644 --- a/example/lib/pages/creator_page.dart +++ b/example/lib/pages/creator_page.dart @@ -6,6 +6,7 @@ import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:flutter_zxing_example/configs/constants.dart'; import 'package:flutter_zxing_example/models/encode.dart'; import 'package:flutter_zxing_example/utils/db_service.dart'; +import 'package:flutter_zxing_example/utils/extensions.dart'; import 'package:flutter_zxing_example/widgets/common_widgets.dart'; import 'package:path_provider/path_provider.dart'; import 'package:share_plus/share_plus.dart'; @@ -51,7 +52,7 @@ class _CreatorPageState extends State { child: ContainerX( child: Column( children: [ - ZxingWriterWidget( + WriterWidget( onSuccess: (result, bytes) { setState(() { encode = Encode.fromEncodeResult(result, bytes); @@ -61,18 +62,7 @@ class _CreatorPageState extends State { setState(() { encode = null; }); - ScaffoldMessenger.of(context).hideCurrentSnackBar(); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Padding( - padding: const EdgeInsets.only(bottom: 30.0), - child: Text( - error, - textAlign: TextAlign.center, - ), - ), - ), - ); + context.showToast(error); }, ), if (encode != null) buildWriteResult(), diff --git a/example/lib/pages/scanner_page.dart b/example/lib/pages/scanner_page.dart index 19ba5b2..8f24fd8 100644 --- a/example/lib/pages/scanner_page.dart +++ b/example/lib/pages/scanner_page.dart @@ -27,7 +27,7 @@ class _ScannerPageState extends State { appBar: AppBar( title: const Text('Scanner'), ), - body: ZxingReaderWidget( + body: ReaderWidget( onScan: (result) async { addCode(result); }, diff --git a/lib/flutter_zxing.dart b/lib/flutter_zxing.dart index 3eab0ca..0c433d6 100644 --- a/lib/flutter_zxing.dart +++ b/lib/flutter_zxing.dart @@ -10,8 +10,8 @@ import 'package:flutter/services.dart'; import 'generated_bindings.dart'; export 'generated_bindings.dart'; -export 'zxing_reader_widget.dart'; -export 'zxing_writer_widget.dart'; +export 'reader_widget.dart'; +export 'writer_widget.dart'; export 'image_converter.dart'; export 'scanner_overlay.dart'; diff --git a/lib/zxing_reader_widget.dart b/lib/reader_widget.dart similarity index 96% rename from lib/zxing_reader_widget.dart rename to lib/reader_widget.dart index b9f3bcf..6a3646a 100644 --- a/lib/zxing_reader_widget.dart +++ b/lib/reader_widget.dart @@ -11,8 +11,8 @@ import 'flutter_zxing.dart'; import 'isolate_utils.dart'; -class ZxingReaderWidget extends StatefulWidget { - const ZxingReaderWidget({ +class ReaderWidget extends StatefulWidget { + const ReaderWidget({ Key? key, required this.onScan, this.onControllerCreated, @@ -34,10 +34,10 @@ class ZxingReaderWidget extends StatefulWidget { final ResolutionPreset resolution; @override - State createState() => _ZxingReaderWidgetState(); + State createState() => _ReaderWidgetState(); } -class _ZxingReaderWidgetState extends State +class _ReaderWidgetState extends State with TickerProviderStateMixin { late List cameras; CameraController? controller; diff --git a/lib/zxing_writer_widget.dart b/lib/writer_widget.dart similarity index 97% rename from lib/zxing_writer_widget.dart rename to lib/writer_widget.dart index aa8d029..45f7309 100644 --- a/lib/zxing_writer_widget.dart +++ b/lib/writer_widget.dart @@ -5,8 +5,8 @@ import 'package:image/image.dart' as imglib; import 'flutter_zxing.dart'; -class ZxingWriterWidget extends StatefulWidget { - const ZxingWriterWidget({ +class WriterWidget extends StatefulWidget { + const WriterWidget({ Key? key, this.onSuccess, this.onError, @@ -16,10 +16,10 @@ class ZxingWriterWidget extends StatefulWidget { final Function(String)? onError; @override - State createState() => _ZxingWriterWidgetState(); + State createState() => _WriterWidgetState(); } -class _ZxingWriterWidgetState extends State +class _WriterWidgetState extends State with TickerProviderStateMixin { final GlobalKey _formKey = GlobalKey(); final TextEditingController _textController = TextEditingController();