Ready to implement expense editor screen
This commit is contained in:
		@@ -1,12 +1,16 @@
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:flutter_hooks/flutter_hooks.dart';
 | 
			
		||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
 | 
			
		||||
import 'package:logging/logging.dart';
 | 
			
		||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
 | 
			
		||||
import 'package:scanbot_sdk/scanbot_sdk_ui_v2.dart';
 | 
			
		||||
 | 
			
		||||
import '../../services/storage/expenses.dart';
 | 
			
		||||
 | 
			
		||||
part 'scan_screen.g.dart';
 | 
			
		||||
 | 
			
		||||
@riverpod
 | 
			
		||||
Future<String> _scanDocument(Ref ref) async {
 | 
			
		||||
Future<String?> _scanDocument(Ref ref) async {
 | 
			
		||||
  var configuration = DocumentScanningFlow(
 | 
			
		||||
    appearance: DocumentFlowAppearanceConfiguration(
 | 
			
		||||
      statusBarMode: StatusBarMode.DARK,
 | 
			
		||||
@@ -18,22 +22,93 @@ Future<String> _scanDocument(Ref ref) async {
 | 
			
		||||
    ),
 | 
			
		||||
  );
 | 
			
		||||
  var documentResult = await ScanbotSdkUiV2.startDocumentScanner(configuration);
 | 
			
		||||
  print("@@@");
 | 
			
		||||
  print(documentResult);
 | 
			
		||||
  print("####");
 | 
			
		||||
 | 
			
		||||
  return "changeme";
 | 
			
		||||
  return documentResult.data?.pdfURI;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ScanScreen extends HookConsumerWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context, WidgetRef ref) {
 | 
			
		||||
    final boredSuggestion = ref.watch(_scanDocumentProvider);
 | 
			
		||||
 | 
			
		||||
    restartScan() async {
 | 
			
		||||
      try {
 | 
			
		||||
        final val = ref.refresh(_scanDocumentProvider);
 | 
			
		||||
        Logger.root.info("Load again startup result: $val");
 | 
			
		||||
      } catch (e, s) {
 | 
			
		||||
        Logger.root.shout("Failed to try again startup loading! $e $s");
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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'),
 | 
			
		||||
      AsyncData(:final value) when value != null => ExpenseEditor(
 | 
			
		||||
        filePath: value,
 | 
			
		||||
        onFinished: (e) {},
 | 
			
		||||
      ),
 | 
			
		||||
 | 
			
		||||
      // No data
 | 
			
		||||
      AsyncData(:final value) when value == null => ScanErrorScreen(
 | 
			
		||||
        message: "No document scanned!",
 | 
			
		||||
        onTryAgain: restartScan,
 | 
			
		||||
      ),
 | 
			
		||||
 | 
			
		||||
      // Error
 | 
			
		||||
      AsyncError(:final error) => ScanErrorScreen(
 | 
			
		||||
        message: error.toString(),
 | 
			
		||||
        onTryAgain: restartScan,
 | 
			
		||||
      ),
 | 
			
		||||
      _ => const Center(child: CircularProgressIndicator()),
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ScanErrorScreen extends StatelessWidget {
 | 
			
		||||
  final String message;
 | 
			
		||||
  final Function() onTryAgain;
 | 
			
		||||
 | 
			
		||||
  const ScanErrorScreen({
 | 
			
		||||
    super.key,
 | 
			
		||||
    required this.message,
 | 
			
		||||
    required this.onTryAgain,
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Center(
 | 
			
		||||
      child: Column(
 | 
			
		||||
        mainAxisAlignment: MainAxisAlignment.center,
 | 
			
		||||
        crossAxisAlignment: CrossAxisAlignment.center,
 | 
			
		||||
        children: [
 | 
			
		||||
          Spacer(flex: 5),
 | 
			
		||||
          Text("An error occurred while scanning"),
 | 
			
		||||
          Spacer(flex: 1),
 | 
			
		||||
          Text(message),
 | 
			
		||||
          Spacer(flex: 1),
 | 
			
		||||
          MaterialButton(
 | 
			
		||||
            onPressed: onTryAgain,
 | 
			
		||||
            child: Text("Try again".toUpperCase()),
 | 
			
		||||
          ),
 | 
			
		||||
          Spacer(flex: 5),
 | 
			
		||||
        ],
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ExpenseEditor extends HookWidget {
 | 
			
		||||
  final String filePath;
 | 
			
		||||
  final Function(Expense) onFinished;
 | 
			
		||||
 | 
			
		||||
  const ExpenseEditor({
 | 
			
		||||
    super.key,
 | 
			
		||||
    required this.filePath,
 | 
			
		||||
    required this.onFinished,
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    // TODO: implement build
 | 
			
		||||
    throw UnimplementedError();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user