Browse Source

code improvements

pull/3/head
Khoren Markosyan 3 years ago
parent
commit
ca3425d45b
  1. 6
      example/ios/Podfile.lock
  2. 2
      example/ios/Runner/Info.plist
  3. 12
      example/lib/pages/barcodes_page.dart
  4. 7
      example/lib/pages/creator_page.dart
  5. 15
      example/lib/pages/help_page.dart
  6. 13
      example/lib/pages/history_page.dart
  7. 4
      example/lib/pages/home_page.dart
  8. 42
      example/lib/pages/scanner_page.dart
  9. 17
      example/lib/utils/extensions.dart
  10. 56
      example/pubspec.lock
  11. 2
      example/pubspec.yaml
  12. 8
      ios/Classes/src/native_zxing.cpp
  13. 6
      ios/Classes/src/native_zxing.h
  14. 2
      lib/flutter_zxing.dart
  15. 4
      lib/generated_bindings.dart
  16. 154
      lib/zxing_writer_widget.dart

6
example/ios/Podfile.lock

@ -12,6 +12,8 @@ PODS:
- fluttertoast (0.0.2): - fluttertoast (0.0.2):
- Flutter - Flutter
- Toast - Toast
- image_picker_ios (0.0.1):
- Flutter
- nb_utils (0.0.1): - nb_utils (0.0.1):
- Flutter - Flutter
- path_provider_ios (0.0.1): - path_provider_ios (0.0.1):
@ -32,6 +34,7 @@ DEPENDENCIES:
- flutter_beep (from `.symlinks/plugins/flutter_beep/ios`) - flutter_beep (from `.symlinks/plugins/flutter_beep/ios`)
- flutter_zxing (from `.symlinks/plugins/flutter_zxing/ios`) - flutter_zxing (from `.symlinks/plugins/flutter_zxing/ios`)
- fluttertoast (from `.symlinks/plugins/fluttertoast/ios`) - fluttertoast (from `.symlinks/plugins/fluttertoast/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- nb_utils (from `.symlinks/plugins/nb_utils/ios`) - nb_utils (from `.symlinks/plugins/nb_utils/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`) - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
- share_plus (from `.symlinks/plugins/share_plus/ios`) - share_plus (from `.symlinks/plugins/share_plus/ios`)
@ -56,6 +59,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_zxing/ios" :path: ".symlinks/plugins/flutter_zxing/ios"
fluttertoast: fluttertoast:
:path: ".symlinks/plugins/fluttertoast/ios" :path: ".symlinks/plugins/fluttertoast/ios"
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
nb_utils: nb_utils:
:path: ".symlinks/plugins/nb_utils/ios" :path: ".symlinks/plugins/nb_utils/ios"
path_provider_ios: path_provider_ios:
@ -74,6 +79,7 @@ SPEC CHECKSUMS:
flutter_beep: 54fb393b22dfa0f0e4573c81b1c74dd71c4e5af8 flutter_beep: 54fb393b22dfa0f0e4573c81b1c74dd71c4e5af8
flutter_zxing: 19a866d17c8a87ee1026d68521c69d2f008635f6 flutter_zxing: 19a866d17c8a87ee1026d68521c69d2f008635f6
fluttertoast: 16fbe6039d06a763f3533670197d01fc73459037 fluttertoast: 16fbe6039d06a763f3533670197d01fc73459037
image_picker_ios: b786a5dcf033a8336a657191401bfdf12017dabb
nb_utils: ada4338858d8827ec92fdab2a545206b4ba4cfb1 nb_utils: ada4338858d8827ec92fdab2a545206b4ba4cfb1
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825

2
example/ios/Runner/Info.plist

@ -43,6 +43,8 @@
</array> </array>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(APP_DISPLAY_NAME) needs photo library access to scan barcodes</string>
<key>NSCameraUsageDescription</key> <key>NSCameraUsageDescription</key>
<string>$(APP_DISPLAY_NAME) needs camera access to scan barcodes</string> <string>$(APP_DISPLAY_NAME) needs camera access to scan barcodes</string>
</dict> </dict>

12
example/lib/pages/barcodes_page.dart

@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_zxing_example/models/models.dart'; import 'package:flutter_zxing_example/models/models.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/router.dart'; import 'package:flutter_zxing_example/utils/router.dart';
import 'package:flutter_zxing_example/widgets/common_widgets.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
@ -49,7 +50,8 @@ class _BarcodesPageState extends State<BarcodesPage> {
itemCount: results.length, itemCount: results.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final result = results[index]; final result = results[index];
return ListTile( return ContainerX(
child: ListTile(
leading: Image.memory(result.data ?? Uint8List(0)), leading: Image.memory(result.data ?? Uint8List(0)),
title: Text(result.text ?? ''), title: Text(result.text ?? ''),
subtitle: Text(result.formatName), subtitle: Text(result.formatName),
@ -57,8 +59,8 @@ class _BarcodesPageState extends State<BarcodesPage> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
// Copy button // Copy button
TextButton( IconButton(
child: const Text('Copy'), icon: const Icon(FontAwesomeIcons.copy),
onPressed: () { onPressed: () {
Clipboard.setData( Clipboard.setData(
ClipboardData(text: result.text)); ClipboardData(text: result.text));
@ -66,7 +68,8 @@ class _BarcodesPageState extends State<BarcodesPage> {
), ),
// Remove button // Remove button
IconButton( IconButton(
icon: const Icon(Icons.delete, color: Colors.red), icon: const Icon(FontAwesomeIcons.trash,
color: Colors.red),
onPressed: () { onPressed: () {
DbService.instance.deleteEncode(result); DbService.instance.deleteEncode(result);
setState(() {}); setState(() {});
@ -74,6 +77,7 @@ class _BarcodesPageState extends State<BarcodesPage> {
), ),
], ],
), ),
),
); );
}, },
); );

7
example/lib/pages/creator_page.dart

@ -3,8 +3,10 @@ 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';
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/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';
@ -46,6 +48,7 @@ class _CreatorPageState extends State<CreatorPage> {
title: const Text('Creator'), title: const Text('Creator'),
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
child: ContainerX(
child: Column( child: Column(
children: [ children: [
ZxingWriterWidget( ZxingWriterWidget(
@ -76,6 +79,7 @@ class _CreatorPageState extends State<CreatorPage> {
], ],
), ),
), ),
),
); );
} }
@ -84,7 +88,7 @@ class _CreatorPageState extends State<CreatorPage> {
children: [ children: [
// Barcode image // Barcode image
Image.memory(encode?.data ?? Uint8List(0)), Image.memory(encode?.data ?? Uint8List(0)),
const SizedBox(height: 20), const SizedBox(height: spaceLarge),
// Share button // Share button
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@ -112,6 +116,7 @@ class _CreatorPageState extends State<CreatorPage> {
), ),
], ],
), ),
const SizedBox(height: spaceLarge),
], ],
); );
} }

15
example/lib/pages/help_page.dart

@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
class HelpPage extends StatelessWidget {
const HelpPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Help'),
),
body: Container(),
);
}
}

13
example/lib/pages/history_page.dart

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_zxing_example/models/code.dart'; import 'package:flutter_zxing_example/models/code.dart';
import 'package:flutter_zxing_example/utils/db_service.dart'; import 'package:flutter_zxing_example/utils/db_service.dart';
import 'package:flutter_zxing_example/widgets/common_widgets.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:hive_flutter/hive_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart';
class HistoryPage extends StatefulWidget { class HistoryPage extends StatefulWidget {
@ -39,15 +41,16 @@ class _HistoryPageState extends State<HistoryPage> {
itemCount: results.length, itemCount: results.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final result = results[index]; final result = results[index];
return ListTile( return ContainerX(
child: ListTile(
title: Text(result.text ?? ''), title: Text(result.text ?? ''),
subtitle: Text(result.formatName), subtitle: Text(result.formatName),
trailing: ButtonBar( trailing: ButtonBar(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
// Copy button // Copy button
TextButton( IconButton(
child: const Text('Copy'), icon: const Icon(FontAwesomeIcons.copy),
onPressed: () { onPressed: () {
Clipboard.setData( Clipboard.setData(
ClipboardData(text: result.text)); ClipboardData(text: result.text));
@ -55,7 +58,8 @@ class _HistoryPageState extends State<HistoryPage> {
), ),
// Remove button // Remove button
IconButton( IconButton(
icon: const Icon(Icons.delete, color: Colors.red), icon: const Icon(FontAwesomeIcons.trash,
color: Colors.red),
onPressed: () { onPressed: () {
DbService.instance.deleteCode(result); DbService.instance.deleteCode(result);
setState(() {}); setState(() {});
@ -63,6 +67,7 @@ class _HistoryPageState extends State<HistoryPage> {
), ),
], ],
), ),
),
); );
}, },
); );

4
example/lib/pages/home_page.dart

@ -1,7 +1,7 @@
import 'package:convex_bottom_bar/convex_bottom_bar.dart'; import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_zxing_example/pages/barcodes_page.dart'; import 'package:flutter_zxing_example/pages/barcodes_page.dart';
import 'package:flutter_zxing_example/pages/creator_page.dart'; import 'package:flutter_zxing_example/pages/help_page.dart';
import 'package:flutter_zxing_example/pages/history_page.dart'; import 'package:flutter_zxing_example/pages/history_page.dart';
import 'package:flutter_zxing_example/pages/scanner_page.dart'; import 'package:flutter_zxing_example/pages/scanner_page.dart';
import 'package:flutter_zxing_example/pages/settings_page.dart'; import 'package:flutter_zxing_example/pages/settings_page.dart';
@ -20,7 +20,7 @@ class _HomePageState extends State<HomePage> {
final barcodesPage = const BarcodesPage(); final barcodesPage = const BarcodesPage();
final historyPage = const HistoryPage(); final historyPage = const HistoryPage();
final scannerPage = const ScannerPage(); final scannerPage = const ScannerPage();
final helpPage = Container(); final helpPage = const HelpPage();
final settingsPage = const SettingsPage(); final settingsPage = const SettingsPage();
dynamic pages() => [ dynamic pages() => [

42
example/lib/pages/scanner_page.dart

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_zxing/flutter_zxing.dart'; import 'package:flutter_zxing/flutter_zxing.dart';
import 'package:flutter_zxing_example/models/models.dart'; import 'package:flutter_zxing_example/models/models.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:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:image/image.dart' as imglib; import 'package:image/image.dart' as imglib;
@ -33,10 +34,24 @@ class _ScannerPageState extends State<ScannerPage> {
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
child: const Icon(FontAwesomeIcons.image), child: const Icon(FontAwesomeIcons.image),
onPressed: () async { onPressed: pickImage,
final XFile? file = ),
await _picker.pickImage(source: ImageSource.gallery); );
}
pickImage() async {
try {
final XFile? file = await _picker.pickImage(source: ImageSource.gallery);
if (file != null) { if (file != null) {
readCodeFromImage(file);
}
} catch (e) {
debugPrint(e.toString());
context.showToast(e.toString());
}
}
readCodeFromImage(XFile file) async {
final Uint8List bytes = await file.readAsBytes(); final Uint8List bytes = await file.readAsBytes();
imglib.Image? image = imglib.decodeImage(bytes); imglib.Image? image = imglib.decodeImage(bytes);
if (image != null) { if (image != null) {
@ -50,30 +65,15 @@ class _ScannerPageState extends State<ScannerPage> {
); );
if (result.isValidBool) { if (result.isValidBool) {
addCode(result); addCode(result);
} else {
context.showToast('No code found');
} }
} }
} }
},
),
);
}
void addCode(CodeResult result) { void addCode(CodeResult result) {
Code code = Code.fromCodeResult(result); Code code = Code.fromCodeResult(result);
DbService.instance.addCode(code); DbService.instance.addCode(code);
context.showToast('Code added:\n${code.text ?? ''}');
// show snackbar
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Padding(
padding: const EdgeInsets.only(bottom: 30.0),
child: Text(
code.text ?? '',
textAlign: TextAlign.center,
),
),
),
);
} }
} }

17
example/lib/utils/extensions.dart

@ -1,4 +1,4 @@
import 'dart:ui'; import 'package:flutter/material.dart';
extension LocaleParsing on String { extension LocaleParsing on String {
Locale parseLocale() { Locale parseLocale() {
@ -46,3 +46,18 @@ extension LocaleParsing on String {
return split('_').first; return split('_').first;
} }
} }
// context extension to show a toast message
extension ContextExtension on BuildContext {
void showToast(String message) {
ScaffoldMessenger.of(this).hideCurrentSnackBar();
ScaffoldMessenger.of(this).showSnackBar(
SnackBar(
content: Padding(
padding: const EdgeInsets.only(bottom: 30.0),
child: Text(message, textAlign: TextAlign.center),
),
),
);
}
}

56
example/pubspec.lock

@ -98,14 +98,14 @@ packages:
name: built_value name: built_value
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "8.2.3" version: "8.3.0"
camera: camera:
dependency: transitive dependency: transitive
description: description:
name: camera name: camera
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.9.4+21" version: "0.9.4+22"
camera_platform_interface: camera_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -119,7 +119,7 @@ packages:
name: camera_web name: camera_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.2.1+3" version: "0.2.1+5"
characters: characters:
dependency: transitive dependency: transitive
description: description:
@ -325,7 +325,7 @@ packages:
name: flutter_plugin_android_lifecycle name: flutter_plugin_android_lifecycle
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.5" version: "2.0.6"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -433,28 +433,28 @@ packages:
name: image_picker name: image_picker
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5" version: "0.8.5+1"
image_picker_android: image_picker_android:
dependency: transitive dependency: transitive
description: description:
name: image_picker_android name: image_picker_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.4+11" version: "0.8.4+12"
image_picker_for_web: image_picker_for_web:
dependency: transitive dependency: transitive
description: description:
name: image_picker_for_web name: image_picker_for_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.6" version: "2.1.7"
image_picker_ios: image_picker_ios:
dependency: transitive dependency: transitive
description: description:
name: image_picker_ios name: image_picker_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.5" version: "0.8.5+1"
image_picker_platform_interface: image_picker_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -580,35 +580,35 @@ packages:
name: path_provider name: path_provider
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.9" version: "2.0.10"
path_provider_android: path_provider_android:
dependency: transitive dependency: transitive
description: description:
name: path_provider_android name: path_provider_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.13" version: "2.0.14"
path_provider_ios: path_provider_ios:
dependency: transitive dependency: transitive
description: description:
name: path_provider_ios name: path_provider_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.8" version: "2.0.9"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
name: path_provider_linux name: path_provider_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.5" version: "2.1.6"
path_provider_macos: path_provider_macos:
dependency: transitive dependency: transitive
description: description:
name: path_provider_macos name: path_provider_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.5" version: "2.0.6"
path_provider_platform_interface: path_provider_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -622,7 +622,7 @@ packages:
name: path_provider_windows name: path_provider_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.5" version: "2.0.6"
petitparser: petitparser:
dependency: transitive dependency: transitive
description: description:
@ -727,35 +727,35 @@ packages:
name: shared_preferences name: shared_preferences
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.13" version: "2.0.14"
shared_preferences_android: shared_preferences_android:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_android name: shared_preferences_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.11" version: "2.0.12"
shared_preferences_ios: shared_preferences_ios:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_ios name: shared_preferences_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
shared_preferences_linux: shared_preferences_linux:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_linux name: shared_preferences_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
shared_preferences_macos: shared_preferences_macos:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_macos name: shared_preferences_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.3" version: "2.0.4"
shared_preferences_platform_interface: shared_preferences_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -769,14 +769,14 @@ packages:
name: shared_preferences_web name: shared_preferences_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.3" version: "2.0.4"
shared_preferences_windows: shared_preferences_windows:
dependency: transitive dependency: transitive
description: description:
name: shared_preferences_windows name: shared_preferences_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" version: "2.1.1"
shelf: shelf:
dependency: transitive dependency: transitive
description: description:
@ -879,35 +879,35 @@ packages:
name: url_launcher name: url_launcher
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.1.0" version: "6.1.1"
url_launcher_android: url_launcher_android:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_android name: url_launcher_android
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.16" version: "6.0.17"
url_launcher_ios: url_launcher_ios:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_ios name: url_launcher_ios
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "6.0.15" version: "6.0.16"
url_launcher_linux: url_launcher_linux:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_linux name: url_launcher_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0" version: "3.0.1"
url_launcher_macos: url_launcher_macos:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_macos name: url_launcher_macos
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0" version: "3.0.1"
url_launcher_platform_interface: url_launcher_platform_interface:
dependency: transitive dependency: transitive
description: description:
@ -921,14 +921,14 @@ packages:
name: url_launcher_web name: url_launcher_web
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.9" version: "2.0.10"
url_launcher_windows: url_launcher_windows:
dependency: transitive dependency: transitive
description: description:
name: url_launcher_windows name: url_launcher_windows
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.0" version: "3.0.1"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:

2
example/pubspec.yaml

@ -22,7 +22,7 @@ dependencies:
hive_flutter: ^1.1.0 hive_flutter: ^1.1.0
image_picker: ^0.8.5 image_picker: ^0.8.5
nb_utils: ^4.5.0 nb_utils: ^4.5.0
path_provider: ^2.0.9 path_provider: ^2.0.10
share_plus: ^4.0.4 share_plus: ^4.0.4
flutter_intl: flutter_intl:

8
ios/Classes/src/native_zxing.cpp

@ -10,7 +10,7 @@ using namespace ZXing;
extern "C" extern "C"
{ {
FUNCTION_ATTRIBUTE FUNCTION_ATTRIBUTE
char *version() char const *version()
{ {
return "1.3.0"; return "1.3.0";
} }
@ -21,7 +21,7 @@ extern "C"
long long start = get_now(); long long start = get_now();
long length = width * height; long length = width * height;
uint8_t *data = new uint8_t[length]; auto *data = new uint8_t[length];
memcpy(data, bytes, length); memcpy(data, bytes, length);
BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any; BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any;
@ -57,7 +57,7 @@ extern "C"
long long start = get_now(); long long start = get_now();
long length = width * height; long length = width * height;
uint8_t *data = new uint8_t[length]; auto *data = new uint8_t[length];
memcpy(data, bytes, length); memcpy(data, bytes, length);
BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any; BarcodeFormats formats = BarcodeFormat(format); // BarcodeFormat::Any;
@ -69,7 +69,7 @@ extern "C"
} }
Results results = ReadBarcodes(image, hints); Results results = ReadBarcodes(image, hints);
struct CodeResult *codes = new struct CodeResult [results.size()]; auto *codes = new struct CodeResult [results.size()];
int i = 0; int i = 0;
for (auto &result : results) for (auto &result : results)
{ {

6
ios/Classes/src/native_zxing.h

@ -46,11 +46,11 @@ extern "C"
}; };
/** /**
* Returns the version of the zxing library. * Returns the version of the zxing-cpp library.
* *
* @return The version of the zxing library. * @return The version of the zxing-cpp library.
*/ */
char *version(); char const *version();
/** /**
* @brief Reads barcode from image. * @brief Reads barcode from image.

2
lib/flutter_zxing.dart

@ -23,7 +23,7 @@ class FlutterZxing {
static final bindings = GeneratedBindings(dylib); static final bindings = GeneratedBindings(dylib);
static bool logEnabled = true; static bool logEnabled = false;
static String version() { static String version() {
return bindings.version().cast<Utf8>().toDartString(); return bindings.version().cast<Utf8>().toDartString();

4
lib/generated_bindings.dart

@ -19,9 +19,9 @@ class GeneratedBindings {
lookup) lookup)
: _lookup = lookup; : _lookup = lookup;
/// Returns the version of the zxing library. /// Returns the version of the zxing-cpp library.
/// ///
/// @return The version of the zxing library. /// @return The version of the zxing-cpp library.
ffi.Pointer<ffi.Int8> version() { ffi.Pointer<ffi.Int8> version() {
return _version(); return _version();
} }

154
lib/zxing_writer_widget.dart

@ -23,6 +23,13 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget>
with TickerProviderStateMixin { with TickerProviderStateMixin {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>(); final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController _textController = TextEditingController(); final TextEditingController _textController = TextEditingController();
final TextEditingController _widthController =
TextEditingController(text: "300");
final TextEditingController _heightController =
TextEditingController(text: "300");
final TextEditingController _marginController =
TextEditingController(text: "10");
final TextEditingController _eccController = TextEditingController(text: "0");
bool isAndroid() => Theme.of(context).platform == TargetPlatform.android; bool isAndroid() => Theme.of(context).platform == TargetPlatform.android;
@ -41,6 +48,30 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget>
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
const SizedBox(height: 20),
// Input multiline text
TextFormField(
controller: _textController,
keyboardType: TextInputType.multiline,
maxLines: null,
maxLength: _maxTextLength,
onChanged: (value) {
setState(() {});
},
decoration: InputDecoration(
border: const OutlineInputBorder(),
filled: true,
labelText: 'Enter barcode text here',
counterText:
'${_textController.value.text.length} / $_maxTextLength',
),
validator: (value) {
if (value?.isEmpty == true) {
return 'Please enter some text';
}
return null;
},
),
const SizedBox(height: 20), const SizedBox(height: 20),
// Format DropDown button // Format DropDown button
DropdownButtonFormField<int>( DropdownButtonFormField<int>(
@ -58,41 +89,111 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget>
}, },
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
// Input multiline text Row(
TextFormField( children: [
controller: _textController, Flexible(
keyboardType: TextInputType.multiline, child: TextFormField(
maxLines: null, controller: _widthController,
maxLength: _maxTextLength, keyboardType: TextInputType.number,
onChanged: (value) { decoration: const InputDecoration(
setState(() {}); labelText: 'Width',
),
validator: (value) {
final width = int.tryParse(value ?? '');
if (width == null) {
return 'Invalid number';
}
return null;
}, },
decoration: InputDecoration(
border: const OutlineInputBorder(),
filled: true,
hintText: 'Enter text to create a barcode',
counterText:
'${_textController.value.text.length} / $_maxTextLength',
), ),
), ),
const SizedBox(width: 8),
Flexible(
child: TextFormField(
controller: _heightController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Height',
),
validator: (value) {
final width = int.tryParse(value ?? '');
if (width == null) {
return 'Invalid number';
}
return null;
},
),
),
],
),
const SizedBox(height: 20),
Row(
children: [
Flexible(
child: TextFormField(
controller: _marginController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'Margin',
),
validator: (value) {
final width = int.tryParse(value ?? '');
if (width == null) {
return 'Invalid number';
}
return null;
},
),
),
const SizedBox(width: 8),
Flexible(
child: TextFormField(
controller: _eccController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
labelText: 'ECC Level',
),
validator: (value) {
final width = int.tryParse(value ?? '');
if (width == null) {
return 'Invalid number';
}
return null;
},
),
),
],
),
const SizedBox(height: 20),
// Write button // Write button
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: createBarcode,
child: const Text('Create'),
),
const SizedBox(height: 20),
],
),
),
),
);
}
void createBarcode() {
if (_formKey.currentState?.validate() ?? false) { if (_formKey.currentState?.validate() ?? false) {
_formKey.currentState?.save(); _formKey.currentState?.save();
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
final text = _textController.value.text; final text = _textController.value.text;
const width = 300; final width = int.parse(_widthController.value.text);
const height = 300; final height = int.parse(_heightController.value.text);
final margin = int.parse(_marginController.value.text);
final ecc = int.parse(_eccController.value.text);
var result = FlutterZxing.encodeBarcode( var result = FlutterZxing.encodeBarcode(
text, width, height, _codeFormat, 5, 0); text, width, height, _codeFormat, margin, ecc);
String? error; String? error;
if (result.isValidBool) { if (result.isValidBool) {
try { try {
final img = final img = imglib.Image.fromBytes(width, height, result.bytes);
imglib.Image.fromBytes(width, height, result.bytes); final encodedBytes = Uint8List.fromList(imglib.encodeJpg(img));
final encodedBytes =
Uint8List.fromList(imglib.encodeJpg(img));
widget.onSuccess?.call(result, encodedBytes); widget.onSuccess?.call(result, encodedBytes);
} on Exception catch (e) { } on Exception catch (e) {
error = e.toString(); error = e.toString();
@ -105,14 +206,5 @@ class _ZxingWriterWidgetState extends State<ZxingWriterWidget>
widget.onError?.call(error); widget.onError?.call(error);
} }
} }
},
child: const Text('Create'),
),
const SizedBox(height: 20),
],
),
),
),
);
} }
} }

Loading…
Cancel
Save