From d82a5f4b1f003c975ab0fe0e01ecdb42df1eb945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Caras?= Date: Wed, 1 Nov 2023 15:37:17 +0100 Subject: [PATCH] wip: work on adding data from OCR --- lib/views/home.dart | 16 +++++------ lib/views/multientry_creator.dart | 46 ------------------------------- 2 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 lib/views/multientry_creator.dart diff --git a/lib/views/home.dart b/lib/views/home.dart index 6aa127b..df60c85 100644 --- a/lib/views/home.dart +++ b/lib/views/home.dart @@ -15,7 +15,6 @@ import 'package:prasule/network/tessdata.dart'; import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformdialog.dart'; import 'package:prasule/views/create_entry.dart'; -import 'package:prasule/views/multientry_creator.dart'; import 'package:prasule/views/settings/settings.dart'; import 'package:prasule/views/settings/tessdata_list.dart'; import 'package:prasule/views/setup.dart'; @@ -321,16 +320,15 @@ class _HomeViewState extends State { var data = []; for (var line in lines) { - var regex = RegExp(r''); + var regex = RegExp(r'\d+(?:\.|,)\d+'); + var price = 0.0; + for (var match in regex.allMatches(line)) { + price += double.tryParse(match.group(0).toString()) ?? 0; + } + data.add(EntryData(name: "Idk", amount: price)); } Navigator.of(context).pop(); - Navigator.of(context).push( - MaterialPageRoute( - builder: (c) => MultientryCreateView( - linesToAdd: data, - ), - ), - ); + // TODO: send to create }, child: const Text("Ok")), TextButton( diff --git a/lib/views/multientry_creator.dart b/lib/views/multientry_creator.dart deleted file mode 100644 index 57af283..0000000 --- a/lib/views/multientry_creator.dart +++ /dev/null @@ -1,46 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:prasule/api/entry_data.dart'; - -class MultientryCreateView extends StatefulWidget { - const MultientryCreateView({super.key, required this.linesToAdd}); - final List linesToAdd; - @override - State createState() => _MultientryCreateViewState(); -} - -class _MultientryCreateViewState extends State { - final _isOpen = []; - @override - void initState() { - super.initState(); - _isOpen.clear(); - _isOpen.addAll(List.filled(widget.linesToAdd.length, false)); - setState(() {}); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text("Add from OCR"), - ), - body: SingleChildScrollView( - child: ExpansionPanelList( - expansionCallback: (i, expanded) { - _isOpen[i] = !_isOpen[i]; - setState(() {}); - }, - children: List.generate( - widget.linesToAdd.length, - (index) => ExpansionPanel( - headerBuilder: (c, expanded) => const Text(""), - body: Text( - widget.linesToAdd[index].name, - ), - isExpanded: _isOpen[index]), - ), - ), - ), - ); - } -}