wip: work on adding data from OCR

This commit is contained in:
Matyáš Caras 2023-11-01 15:37:17 +01:00
parent f8f40f6db6
commit d82a5f4b1f
Signed by untrusted user who does not match committer: hernik
GPG key ID: 2A3175F98820C5C6
2 changed files with 7 additions and 55 deletions

View file

@ -15,7 +15,6 @@ import 'package:prasule/network/tessdata.dart';
import 'package:prasule/pw/platformbutton.dart'; import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart'; import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/views/create_entry.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/settings.dart';
import 'package:prasule/views/settings/tessdata_list.dart'; import 'package:prasule/views/settings/tessdata_list.dart';
import 'package:prasule/views/setup.dart'; import 'package:prasule/views/setup.dart';
@ -321,16 +320,15 @@ class _HomeViewState extends State<HomeView> {
var data = <EntryData>[]; var data = <EntryData>[];
for (var line in lines) { 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).pop();
Navigator.of(context).push( // TODO: send to create
MaterialPageRoute(
builder: (c) => MultientryCreateView(
linesToAdd: data,
),
),
);
}, },
child: const Text("Ok")), child: const Text("Ok")),
TextButton( TextButton(

View file

@ -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<EntryData> linesToAdd;
@override
State<MultientryCreateView> createState() => _MultientryCreateViewState();
}
class _MultientryCreateViewState extends State<MultientryCreateView> {
final _isOpen = <bool>[];
@override
void initState() {
super.initState();
_isOpen.clear();
_isOpen.addAll(List<bool>.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]),
),
),
),
);
}
}