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
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));

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/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<CreatorPage> {
child: ContainerX(
child: Column(
children: [
ZxingWriterWidget(
WriterWidget(
onSuccess: (result, bytes) {
setState(() {
encode = Encode.fromEncodeResult(result, bytes);
@ -61,18 +62,7 @@ class _CreatorPageState extends State<CreatorPage> {
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(),

2
example/lib/pages/scanner_page.dart

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

4
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';

8
lib/zxing_reader_widget.dart → 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<ZxingReaderWidget> createState() => _ZxingReaderWidgetState();
State<ReaderWidget> createState() => _ReaderWidgetState();
}
class _ZxingReaderWidgetState extends State<ZxingReaderWidget>
class _ReaderWidgetState extends State<ReaderWidget>
with TickerProviderStateMixin {
late List<CameraDescription> cameras;
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';
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<ZxingWriterWidget> createState() => _ZxingWriterWidgetState();
State<WriterWidget> createState() => _WriterWidgetState();
}
class _ZxingWriterWidgetState extends State<ZxingWriterWidget>
class _WriterWidgetState extends State<WriterWidget>
with TickerProviderStateMixin {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _textController = TextEditingController();
Loading…
Cancel
Save