diff --git a/moneymgr_mobile/lib/main.dart b/moneymgr_mobile/lib/main.dart index 9caaf26..d360117 100644 --- a/moneymgr_mobile/lib/main.dart +++ b/moneymgr_mobile/lib/main.dart @@ -9,6 +9,7 @@ import 'package:moneymgr_mobile/services/storage/prefs.dart'; import 'package:moneymgr_mobile/services/storage/secure_storage.dart'; import 'package:moneymgr_mobile/utils/provider_observer.dart'; import 'package:moneymgr_mobile/utils/theme_utils.dart'; +import 'package:scanbot_sdk/scanbot_sdk.dart'; // Inspired from https://github.com/dhafinrayhan/dummymart @@ -27,6 +28,14 @@ Future main() async { print('${record.level.name}: ${record.time}: ${record.message}'), ); + // Initialize scanbot sdk + var config = ScanbotSdkConfig( + loggingEnabled: true, + allowGpuAcceleration: true, + allowXnnpackAcceleration: true, + ); + ScanbotSdk.initScanbotSdk(config); + runApp( ProviderScope( observers: [AppProviderObserver()], diff --git a/moneymgr_mobile/lib/routes/scan/scan_screen.dart b/moneymgr_mobile/lib/routes/scan/scan_screen.dart new file mode 100644 index 0000000..7abf979 --- /dev/null +++ b/moneymgr_mobile/lib/routes/scan/scan_screen.dart @@ -0,0 +1,39 @@ +import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:scanbot_sdk/scanbot_sdk_ui_v2.dart'; + +part 'scan_screen.g.dart'; + +@riverpod +Future _scanDocument(Ref ref) async { + var configuration = DocumentScanningFlow( + appearance: DocumentFlowAppearanceConfiguration( + statusBarMode: StatusBarMode.DARK, + ), + cleanScanningSession: true, + outputSettings: DocumentScannerOutputSettings(pagesScanLimit: 1), + screens: DocumentScannerScreens( + review: ReviewScreenConfiguration(enabled: false), + ), + ); + var documentResult = await ScanbotSdkUiV2.startDocumentScanner(configuration); + print("@@@"); + print(documentResult); + print("####"); + + return "changeme"; +} + +class ScanScreen extends HookConsumerWidget { + @override + Widget build(BuildContext context, WidgetRef ref) { + final boredSuggestion = ref.watch(_scanDocumentProvider); + // Perform a switch-case on the result to handle loading/error states + return switch (boredSuggestion) { + AsyncData(:final value) => Text('data: $value'), + AsyncError(:final error) => Text('error: $error'), + _ => const Center(child: CircularProgressIndicator()), + }; + } +} diff --git a/moneymgr_mobile/lib/services/router/router.dart b/moneymgr_mobile/lib/services/router/router.dart index 23d02bd..3572fc0 100644 --- a/moneymgr_mobile/lib/services/router/router.dart +++ b/moneymgr_mobile/lib/services/router/router.dart @@ -6,6 +6,7 @@ import 'package:moneymgr_mobile/routes/login/login_screen.dart'; import 'package:moneymgr_mobile/routes/login/manual_auth_screen.dart'; import 'package:moneymgr_mobile/routes/login/qr_auth_screen.dart'; import 'package:moneymgr_mobile/routes/profile/profile_screen.dart'; +import 'package:moneymgr_mobile/routes/scan/scan_screen.dart'; import 'package:moneymgr_mobile/routes/settings/settings_screen.dart'; import 'package:moneymgr_mobile/services/router/routes_list.dart'; import 'package:moneymgr_mobile/widgets/load_startup_data.dart'; @@ -34,20 +35,11 @@ GoRouter router(Ref ref) { // see [AuthState] enum. final navigationItems = [ NavigationItem( - path: '/products', - body: (_) => const Text("product screen"), - icon: Icons.widgets_outlined, - selectedIcon: Icons.widgets, - label: 'Products', - routes: [ - GoRoute( - path: ':id', - builder: (_, state) { - final id = int.parse(state.pathParameters['id']!); - return Text("product screen $id"); - }, - ), - ], + path: scanPage, + body: (_) => ScanScreen(), + icon: Icons.camera_alt_outlined, + selectedIcon: Icons.camera_alt, + label: "Scan", ), NavigationItem( path: profilePage, diff --git a/moneymgr_mobile/lib/services/router/routes_list.dart b/moneymgr_mobile/lib/services/router/routes_list.dart index c2dd99d..1feef5d 100644 --- a/moneymgr_mobile/lib/services/router/routes_list.dart +++ b/moneymgr_mobile/lib/services/router/routes_list.dart @@ -13,5 +13,8 @@ const manualAuthPage = "/login/manual"; /// Settings path const settingsPage = "/settings"; -// Profile path +/// Scan URL path +const scanPage = "/scan"; + +/// Profile path const profilePage = "/profile"; \ No newline at end of file diff --git a/moneymgr_mobile/lib/widgets/load_startup_data.dart b/moneymgr_mobile/lib/widgets/load_startup_data.dart index c8f720d..e6d117f 100644 --- a/moneymgr_mobile/lib/widgets/load_startup_data.dart +++ b/moneymgr_mobile/lib/widgets/load_startup_data.dart @@ -32,8 +32,13 @@ class LoadStartupData extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final serverConfig = ref.watch(_loadStartupElementsProvider); - tryAgain() { - ref.refresh(_loadStartupElementsProvider); + tryAgain() async { + try { + final val = ref.refresh(_loadStartupElementsProvider); + Logger.root.info("Load again startup result: $val"); + } catch (e, s) { + Logger.root.shout("Failed to try again startup loading! $e $s"); + } } handleSignOut() { diff --git a/moneymgr_mobile/pubspec.lock b/moneymgr_mobile/pubspec.lock index 7f386fb..e724eec 100644 --- a/moneymgr_mobile/pubspec.lock +++ b/moneymgr_mobile/pubspec.lock @@ -816,6 +816,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.6.5" + scanbot_sdk: + dependency: "direct main" + description: + name: scanbot_sdk + sha256: adbd24643e9d7ade1050a0ed4310ace76088cec258970488a7dbe08c3dc5a872 + url: "https://pub.dev" + source: hosted + version: "7.0.0" shared_preferences: dependency: "direct main" description: diff --git a/moneymgr_mobile/pubspec.yaml b/moneymgr_mobile/pubspec.yaml index 3613805..6182b34 100644 --- a/moneymgr_mobile/pubspec.yaml +++ b/moneymgr_mobile/pubspec.yaml @@ -80,6 +80,11 @@ dependencies: confirm_dialog: ^1.0.4 alert_dialog: ^1.0.2 + # Document scanner + # flutter_doc_scanner: ^0.0.16 # no bundled support yet + # https://developers.google.com/ml-kit/tips/installation-paths + scanbot_sdk: ^7.0.0 + dev_dependencies: flutter_test: sdk: flutter