diff --git a/lib/api.dart b/lib/api.dart index ee016ee..3f6f4fd 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -39,9 +39,10 @@ class API { flowInfos = flowResp.map((key, value) => MapEntry(key, FlowInfo(value))); } - Future init() async { + Future init(Function refresh) async { pref = await SharedPreferences.getInstance(); instance = pref!.getString("instance") ?? ""; + refresh(); } bool isInit() { diff --git a/lib/main.dart b/lib/main.dart index a194491..815427e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -20,11 +20,15 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { bool init = false; + refresh() { + setState(() {}); + } + @override void initState() { super.initState(); () async { - await API().init(); + await API().init(refresh); if (API().isInit()) { await API().prefetch(); setState(() { @@ -47,7 +51,7 @@ class _MyAppState extends State { ? (API().isPrefetched() ? const MyHomePage() : const Scaffold( - body: CircularProgressIndicator(), + body: Center(child: CircularProgressIndicator()), )) : const SetupPage()); } diff --git a/lib/pages/flow/flows_page.dart b/lib/pages/flow/flows_page.dart index 5bfaf35..f172bea 100644 --- a/lib/pages/flow/flows_page.dart +++ b/lib/pages/flow/flows_page.dart @@ -2,9 +2,8 @@ import 'package:cdb_ui/api.dart' as API; import 'package:cdb_ui/pages/expandable_list.dart'; import 'package:cdb_ui/pages/flow/active_flow_page.dart'; import 'package:cdb_ui/pages/flow/flow_info_page.dart'; -import 'package:cdb_ui/pages/transaction.dart'; +import 'package:cdb_ui/pages/supply.dart'; import 'package:flutter/material.dart'; -import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class FlowsPage extends StatefulWidget { const FlowsPage({super.key}); @@ -156,24 +155,18 @@ class _FlowsPageState extends State { _ => const Text("..."), }, floatingActionButton: FloatingActionButton( - onPressed: () { + onPressed: () async { // scan flow code - QrBarCodeScannerDialog().getScannedQrBarCode( - context: context, - onCode: (code) { - // library is retarded - code = code!.replaceFirst("Code scanned = ", ""); + var code = await scanQRCode(context, title: "Scan Flow Code"); - API.API().getFlow(code).then((flow) { - var info = API.API().getFlowInfo(flow.kind); - Navigator.of(context).push(MaterialPageRoute( - builder: (context) { - return ActiveFlowPage(flow, info); - }, - )); - }); - }, - ); + API.API().getFlow(code!).then((flow) { + var info = API.API().getFlowInfo(flow.kind); + Navigator.of(context).push(MaterialPageRoute( + builder: (context) { + return ActiveFlowPage(flow, info); + }, + )); + }); }, child: const Icon(Icons.qr_code), ), diff --git a/lib/pages/items.dart b/lib/pages/items.dart index 70304e5..71fc15c 100644 --- a/lib/pages/items.dart +++ b/lib/pages/items.dart @@ -1,8 +1,8 @@ import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/itemview.dart'; +import 'package:cdb_ui/pages/supply.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; -import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class ItemsPage extends StatelessWidget { const ItemsPage({super.key}); @@ -18,21 +18,15 @@ class ItemsPage extends StatelessWidget { return ItemTile(x); }).toList()), floatingActionButton: FloatingActionButton( - onPressed: () { + onPressed: () async { // scan transaction code - QrBarCodeScannerDialog().getScannedQrBarCode( - context: context, - onCode: (code) { - // library is retarded - code = code!.replaceFirst("Code scanned = ", ""); + var code = await scanQRCode(context, title: "Scan Transaction Code"); - API().getTransaction(code).then((t) { - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => TransactionPage(t), - )); - }); - }, - ); + API().getTransaction(code!).then((t) { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => TransactionPage(t), + )); + }); }, child: const Icon(Icons.qr_code), ), diff --git a/lib/pages/locations.dart b/lib/pages/locations.dart index ca12c23..5ddb754 100644 --- a/lib/pages/locations.dart +++ b/lib/pages/locations.dart @@ -1,8 +1,8 @@ import 'package:cdb_ui/api.dart'; +import 'package:cdb_ui/pages/supply.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; import 'package:flutter_simple_treeview/flutter_simple_treeview.dart'; -import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class LocationsPage extends StatefulWidget { const LocationsPage({super.key}); @@ -63,25 +63,20 @@ class _LocationsPageState extends State { return buildTree(context, key); }).toList()), floatingActionButton: FloatingActionButton( - onPressed: () { + onPressed: () async { // scan location code - QrBarCodeScannerDialog().getScannedQrBarCode( - context: context, - onCode: (code) { - // library is retarded - code = code!.replaceFirst("Code scanned = ", ""); - if (!locations!.containsKey(code)) { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('The location $code does not exist.')), - ); - return; - } + var code = await scanQRCode(context, title: "Scan Location Code"); - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => LocationView(locations![code]!), - )); - }, - ); + if (!locations!.containsKey(code)) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('The location $code does not exist.')), + ); + return; + } + + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => LocationView(locations![code]!), + )); }, child: const Icon(Icons.qr_code), ), diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index bb3dad3..792b766 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -1,6 +1,21 @@ import 'package:cdb_ui/api.dart'; import 'package:flutter/material.dart'; -import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; +import 'package:simple_barcode_scanner/enum.dart'; +import 'package:simple_barcode_scanner/simple_barcode_scanner.dart'; + +Future scanQRCode(BuildContext context, + {String title = "Scan QR Code"}) async { + var res = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => SimpleBarcodeScannerPage( + scanType: ScanType.qr, + appBarTitle: title, + ), + )); + + return res; +} class SupplyPage extends StatefulWidget { final Item item; @@ -202,15 +217,13 @@ class _SupplyPageState extends State { width: 12, ), IconButton( - onPressed: () { - QrBarCodeScannerDialog().getScannedQrBarCode( - context: context, - onCode: (code) { - setState(() { - _selectedLocation = code!; - }); - }, - ); + onPressed: () async { + var code = await scanQRCode(context); + setState(() { + if (API().getLocations().keys.contains(code)) { + _selectedLocation = code!; + } + }); }, icon: const Icon(Icons.qr_code), ), @@ -240,7 +253,7 @@ class _SupplyPageState extends State { } Future> _fetchData() async { - var locations = await API().getLocations(); + var locations = API().getLocations(); var origins = await API().getUniqueField(widget.item.id, variant, "origin"); origins.insert(0, ""); locations[""] = Location.zero(); diff --git a/lib/pages/transaction.dart b/lib/pages/transaction.dart index 7faee85..acad5dc 100644 --- a/lib/pages/transaction.dart +++ b/lib/pages/transaction.dart @@ -1,9 +1,9 @@ import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/consume.dart'; +import 'package:cdb_ui/pages/supply.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:qr_bar_code/qr/qr.dart'; -import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; class TransactionPage extends StatefulWidget { final Transaction transaction; @@ -78,34 +78,27 @@ class _TransactionPageState extends State { }).toList(), ), IconButton( - onPressed: () { + onPressed: () async { var locations = API().getLocations(); - QrBarCodeScannerDialog().getScannedQrBarCode( - context: context, - onCode: (code) { - // library is retarded - code = code! - .replaceFirst("Code scanned = ", ""); - if (!locations.containsKey(code)) { - ScaffoldMessenger.of(context) - .showSnackBar( - SnackBar( - content: Text( - 'The location $code does not exist.')), - ); - return; - } + var code = await scanQRCode(context, + title: "Scan Location Code"); + if (!locations.containsKey(code)) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + 'The location $code does not exist.')), + ); + return; + } - API() - .moveTransaction( - widget.transaction.uuid, - selectedLocationID!) - .then( - (x) { - Navigator.of(context).pop(); - }, - ); - }); + API() + .moveTransaction(widget.transaction.uuid, + selectedLocationID!) + .then( + (x) { + Navigator.of(context).pop(); + }, + ); setState(() {}); }, icon: const Icon(Icons.qr_code)) diff --git a/pubspec.lock b/pubspec.lock index 8626fab..92bae6e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -94,6 +94,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_barcode_scanner: + dependency: transitive + description: + name: flutter_barcode_scanner + sha256: a4ba37daf9933f451a5e812c753ddd045d6354e4a3280342d895b07fecaab3fa + url: "https://pub.dev" + source: hosted + version: "2.0.0" flutter_lints: dependency: "direct dev" description: @@ -102,6 +110,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + flutter_plugin_android_lifecycle: + dependency: transitive + description: + name: flutter_plugin_android_lifecycle + sha256: "9ee02950848f61c4129af3d6ec84a1cfc0e47931abc746b03e7a3bc3e8ff6eda" + url: "https://pub.dev" + source: hosted + version: "2.0.22" flutter_simple_treeview: dependency: "direct main" description: @@ -144,30 +160,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.18.1" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -196,18 +204,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" path: dependency: transitive description: @@ -240,6 +248,54 @@ packages: url: "https://pub.dev" source: hosted version: "2.3.0" + permission_handler: + dependency: transitive + description: + name: permission_handler + sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb" + url: "https://pub.dev" + source: hosted + version: "11.3.1" + permission_handler_android: + dependency: transitive + description: + name: permission_handler_android + sha256: "76e4ab092c1b240d31177bb64d2b0bea43f43d0e23541ec866151b9f7b2490fa" + url: "https://pub.dev" + source: hosted + version: "12.0.12" + permission_handler_apple: + dependency: transitive + description: + name: permission_handler_apple + sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0 + url: "https://pub.dev" + source: hosted + version: "9.4.5" + permission_handler_html: + dependency: transitive + description: + name: permission_handler_html + sha256: af26edbbb1f2674af65a8f4b56e1a6f526156bc273d0e65dd8075fab51c78851 + url: "https://pub.dev" + source: hosted + version: "0.1.3+2" + permission_handler_platform_interface: + dependency: transitive + description: + name: permission_handler_platform_interface + sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9 + url: "https://pub.dev" + source: hosted + version: "4.2.3" + permission_handler_windows: + dependency: transitive + description: + name: permission_handler_windows + sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e" + url: "https://pub.dev" + source: hosted + version: "0.2.1" platform: dependency: transitive description: @@ -264,22 +320,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.0" - qr_bar_code_scanner_dialog: - dependency: "direct main" - description: - name: qr_bar_code_scanner_dialog - sha256: dcb937816d4e562141530265bd1ca39fe00f57000fd79e26c163c957d443e9e4 - url: "https://pub.dev" - source: hosted - version: "0.0.5" - qr_code_scanner: - dependency: transitive - description: - name: qr_code_scanner - sha256: f23b68d893505a424f0bd2e324ebea71ed88465d572d26bb8d2e78a4749591fd - url: "https://pub.dev" - source: hosted - version: "1.0.1" shared_preferences: dependency: "direct main" description: @@ -336,6 +376,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.4.1" + simple_barcode_scanner: + dependency: "direct main" + description: + name: simple_barcode_scanner + sha256: "52b30082ebd6fab1e6314cb9bfc1aca5372890616dcb89d0e254edf7b7ef4951" + url: "https://pub.dev" + source: hosted + version: "0.1.2" sky_engine: dependency: transitive description: flutter @@ -385,10 +433,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" typed_data: dependency: transitive description: @@ -409,10 +457,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" web: dependency: transitive description: @@ -421,6 +469,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + webview_windows: + dependency: transitive + description: + name: webview_windows + sha256: "47fcad5875a45db29dbb5c9e6709bf5c88dcc429049872701343f91ed7255730" + url: "https://pub.dev" + source: hosted + version: "0.4.0" xdg_directories: dependency: transitive description: @@ -430,5 +486,5 @@ packages: source: hosted version: "1.0.4" sdks: - dart: ">=3.4.0 <4.0.0" + dart: ">=3.5.3 <4.0.0" flutter: ">=3.22.0" diff --git a/pubspec.yaml b/pubspec.yaml index 7370483..461ce7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,7 @@ dependencies: sdk: flutter flutter_simple_treeview: ^3.0.2 qr_bar_code: ^1.3.0 - qr_bar_code_scanner_dialog: ^0.0.5 + simple_barcode_scanner: ^0.1.2 intl: ^0.18.0 shared_preferences: ^2.1.0 fl_chart: ^0.69.0 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index e8bdf58..966ec1a 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,15 @@ #include "generated_plugin_registrant.h" +#include #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + PermissionHandlerWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); QrBarCodePluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("QrBarCodePluginCApi")); + WebviewWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("WebviewWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 6108823..038df8f 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,7 +3,9 @@ # list(APPEND FLUTTER_PLUGIN_LIST + permission_handler_windows qr_bar_code + webview_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST