Ready to implement expense editor screen
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2025-07-14 08:18:59 +02:00
parent 51ba649b6e
commit 6531d73c93

View File

@ -1,12 +1,16 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:scanbot_sdk/scanbot_sdk_ui_v2.dart'; import 'package:scanbot_sdk/scanbot_sdk_ui_v2.dart';
import '../../services/storage/expenses.dart';
part 'scan_screen.g.dart'; part 'scan_screen.g.dart';
@riverpod @riverpod
Future<String> _scanDocument(Ref ref) async { Future<String?> _scanDocument(Ref ref) async {
var configuration = DocumentScanningFlow( var configuration = DocumentScanningFlow(
appearance: DocumentFlowAppearanceConfiguration( appearance: DocumentFlowAppearanceConfiguration(
statusBarMode: StatusBarMode.DARK, statusBarMode: StatusBarMode.DARK,
@ -18,22 +22,93 @@ Future<String> _scanDocument(Ref ref) async {
), ),
); );
var documentResult = await ScanbotSdkUiV2.startDocumentScanner(configuration); var documentResult = await ScanbotSdkUiV2.startDocumentScanner(configuration);
print("@@@");
print(documentResult);
print("####");
return "changeme"; return documentResult.data?.pdfURI;
} }
class ScanScreen extends HookConsumerWidget { class ScanScreen extends HookConsumerWidget {
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final boredSuggestion = ref.watch(_scanDocumentProvider); 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 // Perform a switch-case on the result to handle loading/error states
return switch (boredSuggestion) { return switch (boredSuggestion) {
AsyncData(:final value) => Text('data: $value'), AsyncData(:final value) when value != null => ExpenseEditor(
AsyncError(:final error) => Text('error: $error'), 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()), _ => 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();
}
}