feat: create basic function to load from ocr
This commit is contained in:
parent
4852cf1839
commit
f614c4dfac
11 changed files with 93 additions and 77 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"conventionalCommits.scopes": [
|
"conventionalCommits.scopes": [
|
||||||
"ocr",
|
"ocr",
|
||||||
"ui"
|
"ui",
|
||||||
|
"translations"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -4,9 +4,10 @@ part 'entry_data.g.dart';
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class EntryData {
|
class EntryData {
|
||||||
String name;
|
String name;
|
||||||
|
String description;
|
||||||
double amount;
|
double amount;
|
||||||
|
|
||||||
EntryData({required this.name, required this.amount});
|
EntryData({required this.name, required this.amount, this.description = ""});
|
||||||
|
|
||||||
factory EntryData.fromJson(Map<String, dynamic> json) =>
|
factory EntryData.fromJson(Map<String, dynamic> json) =>
|
||||||
_$EntryDataFromJson(json);
|
_$EntryDataFromJson(json);
|
||||||
|
|
|
@ -9,9 +9,11 @@ part of 'entry_data.dart';
|
||||||
EntryData _$EntryDataFromJson(Map<String, dynamic> json) => EntryData(
|
EntryData _$EntryDataFromJson(Map<String, dynamic> json) => EntryData(
|
||||||
name: json['name'] as String,
|
name: json['name'] as String,
|
||||||
amount: (json['amount'] as num).toDouble(),
|
amount: (json['amount'] as num).toDouble(),
|
||||||
|
description: json['description'] as String? ?? "",
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$EntryDataToJson(EntryData instance) => <String, dynamic>{
|
Map<String, dynamic> _$EntryDataToJson(EntryData instance) => <String, dynamic>{
|
||||||
'name': instance.name,
|
'name': instance.name,
|
||||||
|
'description': instance.description,
|
||||||
'amount': instance.amount,
|
'amount': instance.amount,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:prasule/api/category.dart';
|
|
||||||
import 'package:prasule/api/entry_data.dart';
|
|
||||||
part 'multientry.g.dart';
|
|
||||||
|
|
||||||
@JsonSerializable()
|
|
||||||
class MultiEntry {
|
|
||||||
EntryType type;
|
|
||||||
List<EntryData> data;
|
|
||||||
DateTime date;
|
|
||||||
WalletCategory category;
|
|
||||||
int id;
|
|
||||||
|
|
||||||
MultiEntry(
|
|
||||||
{required this.data,
|
|
||||||
required this.type,
|
|
||||||
required this.date,
|
|
||||||
required this.category,
|
|
||||||
required this.id});
|
|
||||||
|
|
||||||
factory MultiEntry.fromJson(Map<String, dynamic> json) =>
|
|
||||||
_$MultiEntryFromJson(json);
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$MultiEntryToJson(this);
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'multientry.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonSerializableGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
MultiEntry _$MultiEntryFromJson(Map<String, dynamic> json) => MultiEntry(
|
|
||||||
data: (json['data'] as List<dynamic>)
|
|
||||||
.map((e) => EntryData.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList(),
|
|
||||||
type: $enumDecode(_$EntryTypeEnumMap, json['type']),
|
|
||||||
date: DateTime.parse(json['date'] as String),
|
|
||||||
category:
|
|
||||||
WalletCategory.fromJson(json['category'] as Map<String, dynamic>),
|
|
||||||
id: json['id'] as int,
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> _$MultiEntryToJson(MultiEntry instance) =>
|
|
||||||
<String, dynamic>{
|
|
||||||
'type': _$EntryTypeEnumMap[instance.type]!,
|
|
||||||
'data': instance.data,
|
|
||||||
'date': instance.date.toIso8601String(),
|
|
||||||
'category': instance.category,
|
|
||||||
'id': instance.id,
|
|
||||||
};
|
|
||||||
|
|
||||||
const _$EntryTypeEnumMap = {
|
|
||||||
EntryType.expense: 'expense',
|
|
||||||
EntryType.income: 'income',
|
|
||||||
};
|
|
|
@ -29,4 +29,13 @@ class Wallet {
|
||||||
|
|
||||||
/// Connect the generated [_$PersonToJson] function to the `toJson` method.
|
/// Connect the generated [_$PersonToJson] function to the `toJson` method.
|
||||||
Map<String, dynamic> toJson() => _$WalletToJson(this);
|
Map<String, dynamic> toJson() => _$WalletToJson(this);
|
||||||
|
|
||||||
|
/// Getter for the next unused unique number ID in the wallet's entry list
|
||||||
|
int get nextId {
|
||||||
|
var id = 1;
|
||||||
|
while (entries.where((element) => element.id == id).isNotEmpty) {
|
||||||
|
id++; // create unique ID
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
"settings": "Nastavení",
|
"settings": "Nastavení",
|
||||||
"about": "O aplikaci",
|
"about": "O aplikaci",
|
||||||
"noEntries": "Žádné záznamy :(",
|
"noEntries": "Žádné záznamy :(",
|
||||||
"noEntriesSub": "Přidejte nějaký skrz plovoucího tlačítka vpravo dole.",
|
"noEntriesSub": "Přidejte nějaký skrz plovoucí tlačítka vpravo dole.",
|
||||||
"sureDialog": "Jste si jisti?",
|
"sureDialog": "Jste si jisti?",
|
||||||
"deleteSure": "Opravdu chcete smazat tento záznam?",
|
"deleteSure": "Opravdu chcete smazat tento záznam?",
|
||||||
"missingOcr": "Nemáte stažené žádné jazyky pro OCR!",
|
"missingOcr": "Nemáte stažené žádné jazyky pro OCR!",
|
||||||
|
|
|
@ -15,6 +15,7 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
|
||||||
final List<String>? autofillHints;
|
final List<String>? autofillHints;
|
||||||
final TextStyle? textStyle;
|
final TextStyle? textStyle;
|
||||||
final TextAlign textAlign;
|
final TextAlign textAlign;
|
||||||
|
final int? maxLines;
|
||||||
const PlatformField(
|
const PlatformField(
|
||||||
{super.key,
|
{super.key,
|
||||||
this.controller,
|
this.controller,
|
||||||
|
@ -27,7 +28,8 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.autofillHints,
|
this.autofillHints,
|
||||||
this.textStyle,
|
this.textStyle,
|
||||||
this.textAlign = TextAlign.start});
|
this.textAlign = TextAlign.start,
|
||||||
|
this.maxLines = 1});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TextField createAndroidWidget(BuildContext context) => TextField(
|
TextField createAndroidWidget(BuildContext context) => TextField(
|
||||||
|
@ -44,6 +46,7 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
|
||||||
inputFormatters: inputFormatters,
|
inputFormatters: inputFormatters,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
autofillHints: autofillHints,
|
autofillHints: autofillHints,
|
||||||
|
maxLines: maxLines,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -51,13 +54,14 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
|
||||||
CupertinoTextField(
|
CupertinoTextField(
|
||||||
textAlign: textAlign,
|
textAlign: textAlign,
|
||||||
controller: controller,
|
controller: controller,
|
||||||
enabled: enabled,
|
enabled: enabled ?? true,
|
||||||
obscureText: obscureText,
|
obscureText: obscureText,
|
||||||
prefix: (labelText == null) ? null : Text(labelText!),
|
prefix: (labelText == null) ? null : Text(labelText!),
|
||||||
autocorrect: autocorrect,
|
autocorrect: autocorrect,
|
||||||
keyboardType: keyboardType,
|
keyboardType: keyboardType,
|
||||||
inputFormatters: inputFormatters,
|
inputFormatters: inputFormatters,
|
||||||
onChanged: onChanged,
|
onChanged: onChanged,
|
||||||
|
maxLines: maxLines,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
9
lib/pw/platformroute.dart
Normal file
9
lib/pw/platformroute.dart
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
Route<T> platformRoute<T>(Widget Function(BuildContext) builder) =>
|
||||||
|
(Platform.isIOS)
|
||||||
|
? CupertinoPageRoute<T>(builder: builder)
|
||||||
|
: MaterialPageRoute<T>(builder: builder);
|
|
@ -26,12 +26,8 @@ class _CreateEntryViewState extends State<CreateEntryView> {
|
||||||
if (widget.editEntry != null) {
|
if (widget.editEntry != null) {
|
||||||
newEntry = widget.editEntry!;
|
newEntry = widget.editEntry!;
|
||||||
} else {
|
} else {
|
||||||
var id = 1;
|
|
||||||
while (widget.w.entries.where((element) => element.id == id).isNotEmpty) {
|
|
||||||
id++; // create unique ID
|
|
||||||
}
|
|
||||||
newEntry = WalletSingleEntry(
|
newEntry = WalletSingleEntry(
|
||||||
id: id,
|
id: widget.w.nextId,
|
||||||
data: EntryData(amount: 0, name: ""),
|
data: EntryData(amount: 0, name: ""),
|
||||||
type: EntryType.expense,
|
type: EntryType.expense,
|
||||||
date: DateTime.now(),
|
date: DateTime.now(),
|
||||||
|
@ -152,6 +148,28 @@ class _CreateEntryViewState extends State<CreateEntryView> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
Text(AppLocalizations.of(context)!.description),
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 300,
|
||||||
|
width: MediaQuery.of(context).size.width * 0.8,
|
||||||
|
child: PlatformField(
|
||||||
|
keyboardType: TextInputType.multiline,
|
||||||
|
maxLines: null,
|
||||||
|
controller: TextEditingController(
|
||||||
|
text: newEntry.data.description,
|
||||||
|
),
|
||||||
|
onChanged: (v) {
|
||||||
|
newEntry.data.description = v;
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 15,
|
height: 15,
|
||||||
),
|
),
|
||||||
|
@ -173,9 +191,9 @@ class _CreateEntryViewState extends State<CreateEntryView> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
widget.w.entries.add(newEntry);
|
widget.w.entries.add(newEntry);
|
||||||
WalletManager.saveWallet(widget.w).then((value) =>
|
WalletManager.saveWallet(widget.w).then(
|
||||||
Navigator.of(context)
|
(value) => Navigator.of(context).pop(widget.w),
|
||||||
.pop(widget.w)); // TODO loading circle?
|
); // TODO loading circle?
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'package:grouped_list/grouped_list.dart';
|
||||||
import 'package:image_picker/image_picker.dart';
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:prasule/api/category.dart';
|
||||||
import 'package:prasule/api/entry_data.dart';
|
import 'package:prasule/api/entry_data.dart';
|
||||||
import 'package:prasule/api/walletentry.dart';
|
import 'package:prasule/api/walletentry.dart';
|
||||||
import 'package:prasule/api/wallet.dart';
|
import 'package:prasule/api/wallet.dart';
|
||||||
|
@ -14,6 +15,7 @@ import 'package:prasule/main.dart';
|
||||||
import 'package:prasule/network/tessdata.dart';
|
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/pw/platformroute.dart';
|
||||||
import 'package:prasule/views/create_entry.dart';
|
import 'package:prasule/views/create_entry.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';
|
||||||
|
@ -317,18 +319,45 @@ class _HomeViewState extends State<HomeView> {
|
||||||
element.trim();
|
element.trim();
|
||||||
return element.isEmpty;
|
return element.isEmpty;
|
||||||
});
|
});
|
||||||
|
|
||||||
var data = <EntryData>[];
|
|
||||||
for (var line in lines) {
|
|
||||||
var regex = RegExp(r'\d+(?:\.|,)\d+');
|
|
||||||
var price = 0.0;
|
var price = 0.0;
|
||||||
|
var description = "";
|
||||||
|
for (var line in lines) {
|
||||||
|
// find numbered prices on each line
|
||||||
|
var regex = RegExp(r'\d+(?:(?:\.|,) {0,}\d{0,})+');
|
||||||
for (var match in regex.allMatches(line)) {
|
for (var match in regex.allMatches(line)) {
|
||||||
price += double.tryParse(match.group(0).toString()) ?? 0;
|
price += double.tryParse(match.group(0).toString()) ?? 0;
|
||||||
}
|
}
|
||||||
data.add(EntryData(name: "Idk", amount: price));
|
description += "${line.replaceAll(regex, "")}\n";
|
||||||
}
|
}
|
||||||
Navigator.of(context).pop();
|
Navigator.of(ctx).pop();
|
||||||
// TODO: send to create
|
// show edit
|
||||||
|
Navigator.of(context)
|
||||||
|
.push<WalletSingleEntry>(
|
||||||
|
platformRoute<WalletSingleEntry>(
|
||||||
|
(c) => CreateEntryView(
|
||||||
|
w: selectedWallet!,
|
||||||
|
editEntry: WalletSingleEntry(
|
||||||
|
data: EntryData(
|
||||||
|
name: "",
|
||||||
|
amount: price,
|
||||||
|
description: description),
|
||||||
|
type: EntryType.expense,
|
||||||
|
date: DateTime.now(),
|
||||||
|
category: selectedWallet!.categories.first,
|
||||||
|
id: selectedWallet!.nextId,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.then(
|
||||||
|
(newEntry) {
|
||||||
|
// save entry if we didn't return empty
|
||||||
|
if (newEntry == null) return;
|
||||||
|
selectedWallet!.entries.add(newEntry);
|
||||||
|
WalletManager.saveWallet(selectedWallet!);
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
child: const Text("Ok")),
|
child: const Text("Ok")),
|
||||||
TextButton(
|
TextButton(
|
||||||
|
|
Loading…
Reference in a new issue