Compare commits
5 commits
271a51f5b0
...
fca139af48
Author | SHA1 | Date | |
---|---|---|---|
|
fca139af48 | ||
|
4846a9134d | ||
|
574180c5f2 | ||
|
f614c4dfac | ||
|
4852cf1839 |
15 changed files with 317 additions and 173 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"conventionalCommits.scopes": [
|
"conventionalCommits.scopes": [
|
||||||
"ocr",
|
"ocr",
|
||||||
"ui"
|
"ui",
|
||||||
|
"translations"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,17 @@ import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:prasule/api/wallet.dart';
|
import 'package:prasule/api/wallet.dart';
|
||||||
|
|
||||||
class WalletManager {
|
class WalletManager {
|
||||||
static Future<List<String>> listWallets() async {
|
static Future<List<Wallet>> listWallets() async {
|
||||||
var path =
|
var path =
|
||||||
Directory("${(await getApplicationDocumentsDirectory()).path}/wallets");
|
Directory("${(await getApplicationDocumentsDirectory()).path}/wallets");
|
||||||
if (!path.existsSync()) {
|
if (!path.existsSync()) {
|
||||||
path.createSync();
|
path.createSync();
|
||||||
}
|
}
|
||||||
return path.listSync().map((e) => e.path.split("/").last).toList();
|
var wallets = <Wallet>[];
|
||||||
|
for (var w in path.listSync().map((e) => e.path.split("/").last).toList()) {
|
||||||
|
wallets.add(await loadWallet(w));
|
||||||
|
}
|
||||||
|
return wallets;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Wallet> loadWallet(String name) async {
|
static Future<Wallet> loadWallet(String name) async {
|
||||||
|
@ -27,14 +31,16 @@ class WalletManager {
|
||||||
return Wallet.fromJson(jsonDecode(wallet.readAsStringSync()));
|
return Wallet.fromJson(jsonDecode(wallet.readAsStringSync()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> saveWallet(Wallet w) async {
|
static Future<bool> saveWallet(Wallet w) async {
|
||||||
var path =
|
var path =
|
||||||
Directory("${(await getApplicationDocumentsDirectory()).path}/wallets");
|
Directory("${(await getApplicationDocumentsDirectory()).path}/wallets");
|
||||||
var wallet = File("${path.path}/${w.name}");
|
var wallet = File("${path.path}/${w.name}");
|
||||||
if (!path.existsSync()) {
|
if (!path.existsSync()) {
|
||||||
path.createSync();
|
path.createSync();
|
||||||
}
|
}
|
||||||
|
if (wallet.existsSync()) return false;
|
||||||
wallet.writeAsStringSync(jsonEncode(w.toJson()));
|
wallet.writeAsStringSync(jsonEncode(w.toJson()));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> deleteWallet(Wallet w) async {
|
static Future<void> deleteWallet(Wallet w) async {
|
||||||
|
|
60
lib/l10n/app_cs.arb
Normal file
60
lib/l10n/app_cs.arb
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
{
|
||||||
|
"categoryHealth": "Zdraví",
|
||||||
|
"categoryCar": "Auto",
|
||||||
|
"categoryFood": "Jídlo",
|
||||||
|
"categoryTravel": "Cestování",
|
||||||
|
"next": "Další",
|
||||||
|
"back": "Zpět",
|
||||||
|
"finish": "Dokončit",
|
||||||
|
"errorEmptyName": "Název nemůže být prázdný!",
|
||||||
|
"welcome": "Vítejte!",
|
||||||
|
"welcomeAboutPrasule": "Prašule je správce výdajů navržený pro lidi, kteří nechtějí vyplňovat každý malý detail.",
|
||||||
|
"welcomeInstruction": "Na této obrazovce si nastavíte svoji 'peněženku', ve které budou zaznamenány vaše výdaje uspořádané do kategorií, které si nastavíte hned potom.",
|
||||||
|
"setupWalletNameCurrency": "Nastavte si název a měnu peněženky",
|
||||||
|
"setupNamePlaceholder": "Moje super peněženka",
|
||||||
|
"setupCurrency": "Měna: {currency}",
|
||||||
|
"setupCategoriesHeading": "Vytvořit kategorie",
|
||||||
|
"setupCategoriesEditHint": "Pro upravení klepněte na ikonu nebo název kategorie",
|
||||||
|
"ok": "Ok",
|
||||||
|
"cancel": "Zrušit",
|
||||||
|
"setupCategoriesEditingName": "Upravit název",
|
||||||
|
"setupWalletNamePlaceholder": "Uprav mě",
|
||||||
|
"addNew": "Přidat nový",
|
||||||
|
"addCamera": "Přidat skrz kameru",
|
||||||
|
"addGallery": "Přidat skrz uložený obrázek",
|
||||||
|
"home": "Domů",
|
||||||
|
"settings": "Nastavení",
|
||||||
|
"about": "O aplikaci",
|
||||||
|
"noEntries": "Žádné záznamy :(",
|
||||||
|
"noEntriesSub": "Přidejte nějaký skrz plovoucí tlačítka vpravo dole.",
|
||||||
|
"sureDialog": "Jste si jisti?",
|
||||||
|
"deleteSure": "Opravdu chcete smazat tento záznam?",
|
||||||
|
"missingOcr": "Nemáte stažené žádné jazyky pro OCR!",
|
||||||
|
"download": "Stáhnout",
|
||||||
|
"ocrLoading": "Načítám text z obrázku, vyčkejte chvíli...",
|
||||||
|
"yes": "Ano",
|
||||||
|
"no": "Ne",
|
||||||
|
"ocrSelect": "Vybrat jazyky pro OCR",
|
||||||
|
"createEntry": "Vytvořit nový záznam",
|
||||||
|
"name": "Název",
|
||||||
|
"amount": "Částka",
|
||||||
|
"type": "Druh",
|
||||||
|
"expense": "Výdaj",
|
||||||
|
"income": "Příjem",
|
||||||
|
"category": "Kategorie",
|
||||||
|
"save": "Uložit",
|
||||||
|
"downloadedOcr": "Zobrazit stažená data pro OCR",
|
||||||
|
"downloadedOcrDesc": "Tato data používá OCR engine ke zjištění znaků z obrázků",
|
||||||
|
"ocr": "OCR",
|
||||||
|
"ocrData": "OCR Data",
|
||||||
|
"downloaded": "Staženo",
|
||||||
|
"deleteOcr": "Opravdu chcete smazat '$lang' OCR data?\nJiž tato data nebudete moct použít při skenování obrázků.",
|
||||||
|
"langDownloadDialog": "Stahuji $lang, vyčkejte prosím...",
|
||||||
|
"langDownloadProgress": "Postup: $progress %",
|
||||||
|
"addingFromOcr": "Přidat skrz OCR",
|
||||||
|
"license":"©️ 2023 Matyáš Caras\nVydáno pod licencí GNU AGPL license verze 3",
|
||||||
|
"description":"Popis",
|
||||||
|
"newWallet":"Přidat novou peněženku",
|
||||||
|
"walletExists":"Peněženka s tímto názvem již existuje!"
|
||||||
|
|
||||||
|
}
|
|
@ -88,5 +88,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"addingFromOcr": "Add from OCR",
|
"addingFromOcr": "Add from OCR",
|
||||||
"license":"©️ 2023 Matyáš Caras\nReleased under the GNU AGPL license version 3"
|
"license":"©️ 2023 Matyáš Caras\nReleased under the GNU AGPL license version 3",
|
||||||
|
"description":"Description",
|
||||||
|
"newWallet":"Add new wallet",
|
||||||
|
"walletExists":"A wallet with this name already exists!"
|
||||||
}
|
}
|
|
@ -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';
|
||||||
|
@ -29,6 +31,7 @@ class HomeView extends StatefulWidget {
|
||||||
|
|
||||||
class _HomeViewState extends State<HomeView> {
|
class _HomeViewState extends State<HomeView> {
|
||||||
Wallet? selectedWallet;
|
Wallet? selectedWallet;
|
||||||
|
List<Wallet> wallets = [];
|
||||||
DateTime? prevDate;
|
DateTime? prevDate;
|
||||||
late String locale;
|
late String locale;
|
||||||
@override
|
@override
|
||||||
|
@ -45,13 +48,13 @@ class _HomeViewState extends State<HomeView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadWallet() async {
|
void loadWallet() async {
|
||||||
var wallets = await WalletManager.listWallets();
|
wallets = await WalletManager.listWallets();
|
||||||
if (wallets.isEmpty && mounted) {
|
if (wallets.isEmpty && mounted) {
|
||||||
Navigator.of(context).pushReplacement(
|
Navigator.of(context).pushReplacement(
|
||||||
MaterialPageRoute(builder: (c) => const SetupView()));
|
MaterialPageRoute(builder: (c) => const SetupView()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectedWallet = await WalletManager.loadWallet(wallets.first);
|
selectedWallet = wallets.first;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +99,42 @@ class _HomeViewState extends State<HomeView> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(AppLocalizations.of(context)!.home),
|
title: DropdownButton<int>(
|
||||||
|
value:
|
||||||
|
(selectedWallet == null) ? -1 : wallets.indexOf(selectedWallet!),
|
||||||
|
items: [
|
||||||
|
...wallets.map(
|
||||||
|
(e) => DropdownMenuItem(
|
||||||
|
value: wallets.indexOf(
|
||||||
|
e,
|
||||||
|
),
|
||||||
|
child: Text(e.name),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: -1,
|
||||||
|
child: Text(AppLocalizations.of(context)!.newWallet),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
onChanged: (v) async {
|
||||||
|
if (v == null || v == -1) {
|
||||||
|
await Navigator.of(context).push(
|
||||||
|
platformRoute(
|
||||||
|
(c) => const SetupView(
|
||||||
|
newWallet: true,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
wallets = await WalletManager.listWallets();
|
||||||
|
logger.i(wallets.length);
|
||||||
|
selectedWallet = wallets.last;
|
||||||
|
setState(() {});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
selectedWallet = wallets[v];
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
actions: [
|
actions: [
|
||||||
PopupMenuButton(
|
PopupMenuButton(
|
||||||
itemBuilder: (context) => [
|
itemBuilder: (context) => [
|
||||||
|
@ -204,7 +242,7 @@ class _HomeViewState extends State<HomeView> {
|
||||||
AppLocalizations.of(context)!.deleteSure),
|
AppLocalizations.of(context)!.deleteSure),
|
||||||
actions: [
|
actions: [
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
text: "Yes",
|
text: AppLocalizations.of(context)!.yes,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
selectedWallet?.entries.removeWhere(
|
selectedWallet?.entries.removeWhere(
|
||||||
(e) => e.id == element.id);
|
(e) => e.id == element.id);
|
||||||
|
@ -215,7 +253,7 @@ class _HomeViewState extends State<HomeView> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
PlatformButton(
|
PlatformButton(
|
||||||
text: "No",
|
text: AppLocalizations.of(context)!.no,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(cx).pop();
|
Navigator.of(cx).pop();
|
||||||
},
|
},
|
||||||
|
@ -282,60 +320,87 @@ class _HomeViewState extends State<HomeView> {
|
||||||
builder: (ctx, setState) => PlatformDialog(
|
builder: (ctx, setState) => PlatformDialog(
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final ImagePicker picker = ImagePicker();
|
final ImagePicker picker = ImagePicker();
|
||||||
final XFile? media = await picker.pickImage(source: imgSrc);
|
final XFile? media = await picker.pickImage(source: imgSrc);
|
||||||
if (media == null) {
|
if (media == null) {
|
||||||
if (mounted) Navigator.of(context).pop();
|
if (mounted) Navigator.of(context).pop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// get selected languages
|
// get selected languages
|
||||||
var selected = availableLanguages
|
var selected = availableLanguages
|
||||||
.where((element) => selectedLanguages[
|
.where((element) =>
|
||||||
availableLanguages.indexOf(element)])
|
selectedLanguages[availableLanguages.indexOf(element)])
|
||||||
.join("+")
|
.join("+")
|
||||||
.replaceAll(".traineddata", "");
|
.replaceAll(".traineddata", "");
|
||||||
logger.i(selected);
|
logger.i(selected);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (c) => PlatformDialog(
|
builder: (c) => PlatformDialog(
|
||||||
title: AppLocalizations.of(context)!.ocrLoading),
|
title: AppLocalizations.of(context)!.ocrLoading),
|
||||||
barrierDismissible: false);
|
barrierDismissible: false);
|
||||||
var string = await FlutterTesseractOcr.extractText(media.path,
|
var string = await FlutterTesseractOcr.extractText(media.path,
|
||||||
language: selected,
|
language: selected,
|
||||||
args: {
|
args: {
|
||||||
"psm": "4",
|
"psm": "4",
|
||||||
"preserve_interword_spaces": "1",
|
"preserve_interword_spaces": "1",
|
||||||
});
|
|
||||||
if (!mounted) return;
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
logger.i(string);
|
|
||||||
if (!mounted) return;
|
|
||||||
var lines = string.split("\n")
|
|
||||||
..removeWhere((element) {
|
|
||||||
element.trim();
|
|
||||||
return element.isEmpty;
|
|
||||||
});
|
});
|
||||||
|
if (!mounted) return;
|
||||||
var data = <EntryData>[];
|
Navigator.of(context).pop();
|
||||||
for (var line in lines) {
|
logger.i(string);
|
||||||
var regex = RegExp(r'\d+(?:\.|,)\d+');
|
if (!mounted) return;
|
||||||
var price = 0.0;
|
var lines = string.split("\n")
|
||||||
for (var match in regex.allMatches(line)) {
|
..removeWhere((element) {
|
||||||
price += double.tryParse(match.group(0).toString()) ?? 0;
|
element.trim();
|
||||||
}
|
return element.isEmpty;
|
||||||
data.add(EntryData(name: "Idk", amount: price));
|
});
|
||||||
|
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)) {
|
||||||
|
price += double.tryParse(match.group(0).toString()) ?? 0;
|
||||||
}
|
}
|
||||||
Navigator.of(context).pop();
|
description += "${line.replaceAll(regex, "")}\n";
|
||||||
// TODO: send to create
|
}
|
||||||
},
|
Navigator.of(ctx).pop();
|
||||||
child: const Text("Ok")),
|
// 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"),
|
||||||
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(c).pop();
|
Navigator.of(c).pop();
|
||||||
},
|
},
|
||||||
child: const Text("Cancel")),
|
child: const Text("Cancel"),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
title: AppLocalizations.of(context)!.ocrSelect,
|
title: AppLocalizations.of(context)!.ocrSelect,
|
||||||
content: Column(
|
content: Column(
|
||||||
|
|
|
@ -12,8 +12,10 @@ import 'package:prasule/views/home.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
class SetupView extends StatefulWidget {
|
class SetupView extends StatefulWidget {
|
||||||
const SetupView({super.key});
|
const SetupView({super.key, this.newWallet = false});
|
||||||
|
|
||||||
|
/// We are only creating a new wallet, no first-time setup
|
||||||
|
final bool newWallet;
|
||||||
@override
|
@override
|
||||||
State<SetupView> createState() => _SetupViewState();
|
State<SetupView> createState() => _SetupViewState();
|
||||||
}
|
}
|
||||||
|
@ -36,36 +38,40 @@ class _SetupViewState extends State<SetupView> {
|
||||||
var name = "";
|
var name = "";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void didChangeDependencies() {
|
||||||
super.initState();
|
super.didChangeDependencies();
|
||||||
categories = [
|
if (categories.isEmpty) {
|
||||||
WalletCategory(
|
categories = [
|
||||||
name: AppLocalizations.of(context)!.categoryHealth,
|
WalletCategory(
|
||||||
type: EntryType.expense,
|
name: AppLocalizations.of(context)!.categoryHealth,
|
||||||
id: 1,
|
type: EntryType.expense,
|
||||||
icon: IconData(Icons.medical_information.codePoint,
|
id: 1,
|
||||||
fontFamily: 'MaterialIcons'),
|
icon: IconData(Icons.medical_information.codePoint,
|
||||||
),
|
fontFamily: 'MaterialIcons'),
|
||||||
WalletCategory(
|
),
|
||||||
name: AppLocalizations.of(context)!.categoryCar,
|
WalletCategory(
|
||||||
type: EntryType.expense,
|
name: AppLocalizations.of(context)!.categoryCar,
|
||||||
id: 2,
|
type: EntryType.expense,
|
||||||
icon: IconData(Icons.car_repair.codePoint, fontFamily: 'MaterialIcons'),
|
id: 2,
|
||||||
),
|
icon:
|
||||||
WalletCategory(
|
IconData(Icons.car_repair.codePoint, fontFamily: 'MaterialIcons'),
|
||||||
name: AppLocalizations.of(context)!.categoryFood,
|
),
|
||||||
type: EntryType.expense,
|
WalletCategory(
|
||||||
id: 3,
|
name: AppLocalizations.of(context)!.categoryFood,
|
||||||
icon: IconData(Icons.restaurant.codePoint, fontFamily: 'MaterialIcons'),
|
type: EntryType.expense,
|
||||||
),
|
id: 3,
|
||||||
WalletCategory(
|
icon:
|
||||||
name: AppLocalizations.of(context)!.categoryTravel,
|
IconData(Icons.restaurant.codePoint, fontFamily: 'MaterialIcons'),
|
||||||
type: EntryType.expense,
|
),
|
||||||
id: 4,
|
WalletCategory(
|
||||||
icon: IconData(Icons.train.codePoint, fontFamily: 'MaterialIcons'),
|
name: AppLocalizations.of(context)!.categoryTravel,
|
||||||
),
|
type: EntryType.expense,
|
||||||
];
|
id: 4,
|
||||||
setState(() {});
|
icon: IconData(Icons.train.codePoint, fontFamily: 'MaterialIcons'),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -99,11 +105,27 @@ class _SetupViewState extends State<SetupView> {
|
||||||
currency: _selectedCurrency,
|
currency: _selectedCurrency,
|
||||||
categories: categories);
|
categories: categories);
|
||||||
WalletManager.saveWallet(wallet).then(
|
WalletManager.saveWallet(wallet).then(
|
||||||
(value) => Navigator.of(context).pushReplacement(
|
(value) {
|
||||||
MaterialPageRoute(
|
if (!value) {
|
||||||
builder: (c) => const HomeView(),
|
ScaffoldMessenger.of(context).clearSnackBars();
|
||||||
),
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
),
|
SnackBar(
|
||||||
|
content:
|
||||||
|
Text(AppLocalizations.of(context)!.walletExists),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (widget.newWallet) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.of(context).pushReplacement(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (c) => const HomeView(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
pages: [
|
pages: [
|
||||||
|
@ -123,13 +145,15 @@ class _SetupViewState extends State<SetupView> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
if (!widget.newWallet)
|
||||||
child: Text(
|
Flexible(
|
||||||
AppLocalizations.of(context)!.welcomeAboutPrasule),
|
child: Text(
|
||||||
),
|
AppLocalizations.of(context)!.welcomeAboutPrasule),
|
||||||
const SizedBox(
|
),
|
||||||
height: 5,
|
if (!widget.newWallet)
|
||||||
),
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
AppLocalizations.of(context)!.welcomeInstruction),
|
AppLocalizations.of(context)!.welcomeInstruction),
|
||||||
|
|
Loading…
Reference in a new issue