Browse Source

code refactore

pull/3/head
Khoren Markosyan 3 years ago
parent
commit
d011e542b6
  1. 2
      README.md
  2. 16
      example/lib/pages/creator_page.dart
  3. 2
      example/lib/pages/scanner_page.dart
  4. 4
      lib/flutter_zxing.dart
  5. 8
      lib/reader_widget.dart
  6. 8
      lib/writer_widget.dart

2
README.md

@ -69,7 +69,7 @@ Widget build(BuildContext context) {
// Or use FlutterZxing to create barcode directly // Or use FlutterZxing to create barcode directly
final text = 'Text to encode'; 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) { if (result.isValidBool) {
final img = imglib.Image.fromBytes(width, height, result.bytes); final img = imglib.Image.fromBytes(width, height, result.bytes);
final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img)); final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img));

16
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/configs/constants.dart';
import 'package:flutter_zxing_example/models/encode.dart'; import 'package:flutter_zxing_example/models/encode.dart';
import 'package:flutter_zxing_example/utils/db_service.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:flutter_zxing_example/widgets/common_widgets.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
@ -51,7 +52,7 @@ class _CreatorPageState extends State<CreatorPage> {
child: ContainerX( child: ContainerX(
child: Column( child: Column(
children: [ children: [
ZxingWriterWidget( WriterWidget(
onSuccess: (result, bytes) { onSuccess: (result, bytes) {
setState(() { setState(() {
encode = Encode.fromEncodeResult(result, bytes); encode = Encode.fromEncodeResult(result, bytes);
@ -61,18 +62,7 @@ class _CreatorPageState extends State<CreatorPage> {
setState(() { setState(() {
encode = null; encode = null;
}); });
ScaffoldMessenger.of(context).hideCurrentSnackBar(); context.showToast(error);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Padding(
padding: const EdgeInsets.only(bottom: 30.0),
child: Text(
error,
textAlign: TextAlign.center,
),
),
),
);
}, },
), ),
if (encode != null) buildWriteResult(), if (encode != null) buildWriteResult(),

2
example/lib/pages/scanner_page.dart

@ -27,7 +27,7 @@ class _ScannerPageState extends State<ScannerPage> {
appBar: AppBar( appBar: AppBar(
title: const Text('Scanner'), title: const Text('Scanner'),
), ),
body: ZxingReaderWidget( body: ReaderWidget(
onScan: (result) async { onScan: (result) async {
addCode(result); addCode(result);
}, },

4
lib/flutter_zxing.dart

@ -10,8 +10,8 @@ import 'package:flutter/services.dart';
import 'generated_bindings.dart'; import 'generated_bindings.dart';
export 'generated_bindings.dart'; export 'generated_bindings.dart';
export 'zxing_reader_widget.dart'; export 'reader_widget.dart';
export 'zxing_writer_widget.dart'; export 'writer_widget.dart';
export 'image_converter.dart'; export 'image_converter.dart';
export 'scanner_overlay.dart'; export 'scanner_overlay.dart';

8
lib/zxing_reader_widget.dart → lib/reader_widget.dart

@ -11,8 +11,8 @@ import 'flutter_zxing.dart';
import 'isolate_utils.dart'; import 'isolate_utils.dart';
class ZxingReaderWidget extends StatefulWidget { class ReaderWidget extends StatefulWidget {
const ZxingReaderWidget({ const ReaderWidget({
Key? key, Key? key,
required this.onScan, required this.onScan,
this.onControllerCreated, this.onControllerCreated,
@ -34,10 +34,10 @@ class ZxingReaderWidget extends StatefulWidget {
final ResolutionPreset resolution; final ResolutionPreset resolution;
@override @override
State<ZxingReaderWidget> createState() => _ZxingReaderWidgetState(); State<ReaderWidget> createState() => _ReaderWidgetState();
} }
class _ZxingReaderWidgetState extends State<ZxingReaderWidget> class _ReaderWidgetState extends State<ReaderWidget>
with TickerProviderStateMixin { with TickerProviderStateMixin {
late List<CameraDescription> cameras; late List<CameraDescription> cameras;
CameraController? controller; CameraController? controller;

8
lib/zxing_writer_widget.dart → lib/writer_widget.dart

@ -5,8 +5,8 @@ import 'package:image/image.dart' as imglib;
import 'flutter_zxing.dart'; import 'flutter_zxing.dart';
class ZxingWriterWidget extends StatefulWidget { class WriterWidget extends StatefulWidget {
const ZxingWriterWidget({ const WriterWidget({
Key? key, Key? key,
this.onSuccess, this.onSuccess,
this.onError, this.onError,
@ -16,10 +16,10 @@ class ZxingWriterWidget extends StatefulWidget {
final Function(String)? onError; final Function(String)? onError;
@override @override
State<ZxingWriterWidget> createState() => _ZxingWriterWidgetState(); State<WriterWidget> createState() => _WriterWidgetState();
} }
class _ZxingWriterWidgetState extends State<ZxingWriterWidget> class _WriterWidgetState extends State<WriterWidget>
with TickerProviderStateMixin { with TickerProviderStateMixin {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _textController = TextEditingController(); final TextEditingController _textController = TextEditingController();
Loading…
Cancel
Save