Compare commits

..

No commits in common. "79cf29a0d309fa0fc73a6c2a98d916154415630d" and "833aef28c798fc7adacdfb2acfe83b48b7eb3b5d" have entirely different histories.

27 changed files with 708 additions and 1295 deletions

@ -1 +1 @@
Subproject commit c1df7d07ac60336309bae9dd2d48e7cb8844ec98
Subproject commit fed06b31d938f7620ea7417295b8d8d19cf7cf1d

1
.gitignore vendored
View file

@ -42,4 +42,3 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
reports

View file

@ -1,9 +1,3 @@
# 1.0.0-alpha+5
- Add tests
- Add searching through entries to homepage
- Replace `PlatformDialog` with `AlertDialog.adaptive`
- Add import/export of wallets
# 1.0.0-alpha+4
- Fix OCR downloads
# 1.0.0-alpha+3

View file

@ -1,5 +1,5 @@
# prasule
[![Codemagic build status](https://api.codemagic.io/apps/64faee78aae8c48abc70dbc6/64faee78aae8c48abc70dbc5/status_badge.svg)](https://codemagic.io/apps/64faee78aae8c48abc70dbc6/64faee78aae8c48abc70dbc5/latest_build) [![Bug issue count](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgit.mnau.xyz%2Fapi%2Fv1%2Frepos%2Fhernik%2Fprasule%2Fissues%3Flabels%3DKind%2FBug&query=%24.length&logo=forgejo&label=bug%20issues&color=red)](https://git.mnau.xyz/hernik/prasule/issues?q=&type=all&sort=&state=open&labels=144&milestone=0&project=0&assignee=0&poster=0) [![wakatime](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/bf1f40b0-c8c0-4f72-8ad6-c861ecdcc90c.svg)](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/bf1f40b0-c8c0-4f72-8ad6-c861ecdcc90c) [![Translation status](https://hosted.weblate.org/widget/prasule/svg-badge.svg)](https://hosted.weblate.org/engage/prasule/) [![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page)
[![Codemagic build status](https://api.codemagic.io/apps/64faee78aae8c48abc70dbc6/64faee78aae8c48abc70dbc5/status_badge.svg)](https://codemagic.io/apps/64faee78aae8c48abc70dbc6/64faee78aae8c48abc70dbc5/latest_build) [![Bug issue count](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgit.mnau.xyz%2Fapi%2Fv1%2Frepos%2Fhernik%2Fprasule%2Fissues%3Flabels%3DKind%2FBug&query=%24.length&logo=forgejo&label=bug%20issues&color=red)](https://git.mnau.xyz/hernik/prasule/issues?q=&type=all&sort=&state=open&labels=144&milestone=0&project=0&assignee=0&poster=0) [![wakatime](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/bf1f40b0-c8c0-4f72-8ad6-c861ecdcc90c.svg)](https://wakatime.com/badge/user/17178fab-a33c-430f-a764-7b3f26c7b966/project/bf1f40b0-c8c0-4f72-8ad6-c861ecdcc90c) [![Translation status](https://hosted.weblate.org/widget/prasule/svg-badge.svg)](https://hosted.weblate.org/engage/prasule/)
Expense manager

View file

@ -76,6 +76,4 @@ flutter {
source '../..'
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
dependencies {}

View file

@ -4,8 +4,7 @@
<application
android:label="Prašule"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:enableOnBackInvokedCallback="true">
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"

View file

@ -1,3 +1,16 @@
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()

View file

@ -10,17 +10,11 @@ pluginManagement {
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
plugins {
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}
include ":app"
apply from: "${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle/app_plugin_loader.gradle"

View file

@ -1,140 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:logger/logger.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/entry_data.dart';
import 'package:prasule/api/wallet.dart';
import 'package:prasule/api/wallet_entry.dart';
import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/main.dart';
import 'package:prasule/pw/platformfield.dart';
void main() {
final logger = Logger();
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group("Test classes and API", () {
test("Test wallet operations", () async {
expect(
(await WalletManager.listWallets()).length,
equals(0),
); // check that there are no other wallets
await WalletManager.saveWallet(Wallet.empty);
var w = (await WalletManager.listWallets()).firstOrNull;
expect(w, isNotNull); // check that the wallet was successfully saved
expect(w!.categories.length, equals(1));
w.categories.add(
WalletCategory(
name: "Testing",
id: w.nextCategoryId,
icon: Icons.abc,
color: Colors.orange,
),
); // create test category
final testId = w.nextId;
w.entries.add(
WalletSingleEntry(
data: EntryData(amount: 200, name: "Automated"),
type: EntryType.expense,
date: DateTime.now(),
category: w.categories.last,
id: w.nextId,
),
); // create test entry
await WalletManager.saveWallet(w); // save again
w = await WalletManager.loadWallet(w.name); // try loading manually
final e = w.entries.where((element) => element.id == testId).firstOrNull;
expect(
e,
isNotNull,
); // check that the entry was successfully created
expect(
w.categories.where((element) => element.id == e!.category.id).length,
equals(1),
); // check that the category exists too
await WalletManager.deleteWallet(w);
expect(
(await WalletManager.listWallets()).length,
equals(0),
);
});
});
group("Test app functionality:", () {
testWidgets('First-time setup', (WidgetTester tester) async {
// Delete all data
await WalletManager.deleteAllData();
// Build our app and trigger a frame.
await tester.pumpWidget(
const MyApp(
locale: Locale('en', 'US'),
),
);
await tester.pumpAndSettle();
logger.i("Looking for welcome header");
expect(find.text('Welcome!'), findsOneWidget);
// Tap "Next" button
await tester.tap(find.text("Next"));
await tester.pumpAndSettle();
logger.i("Next view, looking for name+balance fields");
final firstFields = find.byType(PlatformField);
expect(firstFields, findsExactly(2));
logger.i("Entering text");
await tester.enterText(find.byType(PlatformField).first, "Debugging");
await tester.pumpAndSettle();
await tester.enterText(find.byType(PlatformField).last, "100");
await tester.pumpAndSettle();
// Tap "Next" button
await tester.tap(find.text("Next"));
await tester.pumpAndSettle();
// Tap "Finish" button
await tester.tap(find.text("Finish"));
await tester.pumpAndSettle();
expect(
find.byWidgetPredicate(
(widget) =>
widget is DropdownButton &&
((widget as DropdownButton<int>).value ?? -1) == 0,
),
findsOne,
);
});
testWidgets('Test rendering of entries', (WidgetTester tester) async {
// Delete all data
await WalletManager.deleteAllData();
expect((await WalletManager.listWallets()).length, equals(0));
// Create test data
final w = Wallet.empty;
await w.createTestEntries();
expect((await WalletManager.listWallets()).length, equals(1));
// Build our app and trigger a frame.
await tester.pumpWidget(
const MyApp(
locale: Locale('en', 'US'),
),
);
await tester.pumpAndSettle();
// TODO: better test
expect(
find.byType(ListTile, skipOffstage: false),
findsAtLeast(10),
);
});
});
}

View file

@ -0,0 +1,24 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:prasule/main.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group("Test Setup screen:", () {
testWidgets('First-time setup', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
expect(find.text('Welcome!'), findsOneWidget);
// // Tap the '+' icon and trigger a frame.
// await tester.tap(find.byIcon(Icons.add));
// await tester.pump();
// // Verify that our counter has incremented.
// expect(find.text('0'), findsNothing);
// expect(find.text('1'), findsOneWidget);
});
});
}

View file

@ -1,11 +1,7 @@
import 'dart:math';
import 'package:currency_picker/currency_picker.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/entry_data.dart';
import 'package:prasule/api/recurring_entry.dart';
import 'package:prasule/api/wallet_entry.dart';
import 'package:prasule/api/wallet_manager.dart';
@ -160,44 +156,9 @@ class Wallet {
await WalletManager.saveWallet(this);
}
/// Returns the current balance
///
/// Basically just takes *starterBalance* and adds all the entries to it
double calculateCurrentBalance() {
var toAdd = 0.0;
for (final e in entries) {
toAdd += (e.type == EntryType.income) ? e.data.amount : -e.data.amount;
}
return starterBalance + toAdd;
}
/// Returns the amount that was made/lost during a month
double calculateMonthStatus(int month, int year) {
var f = 0.0;
for (final e in entries.where(
(element) => element.date.year == year && element.date.month == month,
)) {
f += (e.type == EntryType.income) ? e.data.amount : -e.data.amount;
}
return f;
}
/// Empty wallet used for placeholders
static final Wallet empty = Wallet(
name: "Empty",
entries: [],
recurringEntries: [],
categories: [
WalletCategory(
name: "Default",
id: 0,
icon: IconData(
Icons.payments.codePoint,
fontFamily: 'MaterialIcons',
),
color: Colors.white,
),
],
currency: Currency.from(
json: {
"code": "USD",
@ -214,66 +175,4 @@ class Wallet {
},
),
);
/// Creates test data used for debugging purposes
Future<void> createTestEntries() async {
entries.clear();
recurringEntries.clear();
final random = Random();
for (var i = 0; i < 30; i++) {
entries.add(
WalletSingleEntry(
data: EntryData(
name: "Test Entry #${i + 1}",
amount: random.nextInt(20000).toDouble(),
),
type: (random.nextInt(3) > 0) ? EntryType.expense : EntryType.income,
date: DateTime(
2023,
random.nextInt(12) + 1,
random.nextInt(28) + 1,
),
category: categories[random.nextInt(categories.length)],
id: nextId,
),
);
}
logger.d(
"Created ${entries.length} regular entries",
);
for (var i = 0; i < 3; i++) {
final type = random.nextInt(3);
recurringEntries.add(
RecurringWalletEntry(
data: EntryData(
name: "Recurring Entry #${i + 1}",
amount: random.nextInt(20000).toDouble(),
),
type: (random.nextInt(3) > 0) ? EntryType.expense : EntryType.income,
date: DateTime(
2023,
random.nextInt(12) + 1,
random.nextInt(28) + 1,
),
category: categories[random.nextInt(categories.length)],
id: nextId,
lastRunDate: DateTime.now().subtract(
Duration(
days: (type > 0) ? 3 : 3 * 31,
),
),
recurType: (type > 0) ? RecurType.day : RecurType.month,
),
);
}
logger.d(
"Created ${recurringEntries.length} recurring entries",
);
// save and reload
await WalletManager.saveWallet(this);
}
}

View file

@ -1,10 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'package:archive/archive_io.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
import 'package:intl/intl.dart';
import 'package:path_provider/path_provider.dart';
import 'package:prasule/api/wallet.dart';
import 'package:prasule/main.dart';
@ -28,143 +24,10 @@ class WalletManager {
// TODO: do something with unreadable wallets
}
}
logger.i(wallets.length);
return wallets;
}
/// Deletes all [Wallet]s
static Future<void> deleteAllData() async {
final path =
Directory("${(await getApplicationDocumentsDirectory()).path}/wallets");
if (!path.existsSync()) {
return;
}
for (final entry in path.listSync()) {
logger.d("Deleting ${entry.path}");
entry.deleteSync();
}
}
/// Creates a ZIP archive from all wallets
static Future<void> exportAllWallets() async {
if (kIsWeb) {
// TODO
return;
}
final archive = Archive();
for (final w in Directory(
"${(await getApplicationDocumentsDirectory()).path}/wallets",
).listSync()) {
if (w is! File) continue;
logger.i("Zipping ${w.path.split("/").last}");
final wf = w;
archive.addFile(
ArchiveFile.stream(
wf.path.split("/").last,
wf.lengthSync(),
InputFileStream(wf.path),
),
);
}
if (!await FlutterFileDialog.isPickDirectorySupported()) {
File(
"${(await getApplicationDocumentsDirectory()).path}/export_${DateFormat("dd_MM_yyyy").format(DateTime.now())}.zip",
).writeAsBytesSync(ZipEncoder().encode(archive) ?? []);
return;
}
final dir = await FlutterFileDialog.pickDirectory();
if (dir == null) return;
await FlutterFileDialog.saveFileToDirectory(
directory: dir,
data: Uint8List.fromList(ZipEncoder().encode(archive) ?? []),
fileName: "export_${DateFormat("dd_MM_yyyy").format(DateTime.now())}.zip",
mimeType: "application/zip",
);
}
/// Exports a single [Wallet]
static Future<void> exportWallet({Wallet? wallet, String? name}) async {
if (wallet == null && name == null) {
throw Exception("You need to specify either a wallet or a name");
}
final n = name ?? wallet!.name;
if (!await FlutterFileDialog.isPickDirectorySupported()) {
File("${(await getApplicationDocumentsDirectory()).path}/wallets/$n")
.copySync(
"${await getApplicationDocumentsDirectory()}/export_${n.replaceAll(RegExp('[|\\?*<":>+\[\]/\' ]+'), '_')}_${DateFormat("dd_MM_yyyy").format(DateTime.now())}.json",
);
return;
}
final dir = await FlutterFileDialog.pickDirectory();
if (dir == null) return;
await FlutterFileDialog.saveFileToDirectory(
directory: dir,
data:
File("${(await getApplicationDocumentsDirectory()).path}/wallets/$n")
.readAsBytesSync(),
fileName:
"export_${n.replaceAll(RegExp('[|\\?*<":>+\[\]/\' ]+'), '_')}_${DateFormat("dd_MM_yyyy").format(DateTime.now())}.json",
mimeType: "application/json",
);
}
/// Import a single wallet
static Future<void> importWallet({String? data}) async {
var d = data ?? "";
if (data == null) {
final filePath = await FlutterFileDialog.pickFile(
params: const OpenFileDialogParams(
mimeTypesFilter: ["application/json"],
fileExtensionsFilter: ["json"],
),
);
if (filePath == null) return;
d = File(filePath).readAsStringSync();
}
final w = Wallet.fromJson(jsonDecode(d) as Map<String, dynamic>);
if (await WalletManager.exists(w.name)) {
throw Exception("Wallet already exists!");
}
await WalletManager.saveWallet(
w,
);
}
/// Imports wallets from a ZIP archive
static Future<void> importArchive() async {
final filePath = await FlutterFileDialog.pickFile(
params: const OpenFileDialogParams(
mimeTypesFilter: ["application/zip"],
fileExtensionsFilter: ["zip"],
),
);
if (filePath == null) return;
if (kIsWeb) {
// TODO
return;
}
final temp = Directory("${(await getTemporaryDirectory()).path}/data");
if (temp.existsSync()) {
temp.deleteSync();
}
temp.createSync(recursive: true);
final archive = ZipDecoder().decodeBuffer(InputFileStream(filePath));
for (final file in archive.files) {
if (!file.isFile) {
logger.d(file.name);
continue;
}
file.writeContent(OutputFileStream("${temp.path}/${file.name}"));
}
for (final e in temp.listSync()) {
logger.d(e.path);
if (e is! File) continue;
await importWallet(data: e.readAsStringSync());
}
}
/// Loads and returns a single [Wallet] by name
static Future<Wallet> loadWallet(String name) async {
final path =
@ -200,11 +63,4 @@ class WalletManager {
Directory("${(await getApplicationDocumentsDirectory()).path}/wallets");
File("${path.path}/${w.name}").deleteSync();
}
/// Checks if the wallet exists
static Future<bool> exists(String name) async {
return File(
"${(await getApplicationDocumentsDirectory()).path}/wallets/$name",
).existsSync();
}
}

View file

@ -87,22 +87,5 @@
"dayCounter":"{count, plural, =1{den} few{dny} many{dnů} other{dnů} }",
"yearCounter":"{count, plural, =1{rok} few{rok} many{let} other{let} }",
"recurEvery":"{count, plural, =1{Opakovat každý} few{Opakovat každé} many{Opakovat každých} other{Opakovat každých}}",
"startingWithDate": "počínaje datem",
"evenMoney":"Váš stav je stejný jako minulý měsíc.",
"balanceStatusA": "Váš stav je ",
"balanceStatusB": " oproti minulému měsíci.",
"searchLabel":"Prohledat záznamy...",
"exportSingle":"Exportovat peněženku",
"exportSingleDesc":"Uloží vybranou peněženku do složky Stažené",
"exportArchive":"Exportovat archiv",
"exportArchiveDesc":"Exportuje všechny peněženky do archivu do složky Stažené",
"importSingle":"Importovat peněženku",
"importSingleDesc":"Importuje jednu peněženku ze souboru",
"importArchive":"Importovat archiv",
"importArchiveDesc":"Importuje všechny nepoškozené peněženky z archivu",
"settingsData":"Data",
"selectExportWallet":"Zvolte peněženku k exportování",
"exportError":"Při exportování peněženky nastala chyba",
"exportCompleted":"Export dokončen",
"importCompleted":"Import dokončen"
"startingWithDate": "počínaje datem"
}

View file

@ -203,22 +203,5 @@
"startingWithDate": "starting",
"@startingWithDate":{
"description": "Shown after 'Recur every X Y', e.g. 'Recur every 2 month starting 20th June 2023'"
},
"evenMoney":"You're on the same balance as last month.",
"balanceStatusA": "Your balance is ",
"balanceStatusB": " compared to last month.",
"searchLabel":"Search entries...",
"exportSingle":"Export a wallet",
"exportSingleDesc":"Saves a single wallet into your downloads directory",
"exportArchive":"Export archive",
"exportArchiveDesc":"Exports all wallets into an archive to your downloads directory",
"importSingle":"Import a wallet",
"importSingleDesc":"Imports a single wallet from file",
"importArchive":"Import archive",
"importArchiveDesc":"Imports all valid wallets inside an archive",
"settingsData":"Data",
"selectExportWallet":"Select a wallet to export",
"exportError":"An error occured trying to export wallet",
"exportCompleted":"Export completed",
"importCompleted":"Import completed"
}
}

View file

@ -29,15 +29,12 @@ final logger = Logger();
/// The application itself
class MyApp extends StatelessWidget {
/// The application itself
const MyApp({super.key, this.locale});
const MyApp({super.key});
/// If Material You was applied
///
/// Used to check if it is supported
static bool appliedYou = false;
/// Override locale, used for testing
final Locale? locale;
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
@ -53,7 +50,6 @@ class MyApp extends StatelessWidget {
...GlobalCupertinoLocalizations.delegates,
],
supportedLocales: AppLocalizations.supportedLocales,
locale: locale,
title: 'Prašule',
theme: ThemeData(
colorScheme: _materialYou

View file

@ -0,0 +1,31 @@
// ignore_for_file: public_member_api_docs
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:prasule/pw/platformwidget.dart';
/// A [PlatformWidget] implementation of a dialog
class PlatformDialog extends PlatformWidget<AlertDialog, CupertinoAlertDialog> {
const PlatformDialog(
{required this.title, super.key, this.content, this.actions = const [],});
final String title;
final Widget? content;
final List<Widget> actions;
@override
AlertDialog createAndroidWidget(BuildContext context) => AlertDialog(
title: Text(title),
content:
(content != null) ? SingleChildScrollView(child: content) : null,
actions: actions,
);
@override
CupertinoAlertDialog createIosWidget(BuildContext context) =>
CupertinoAlertDialog(
title: Text(title),
content:
(content != null) ? SingleChildScrollView(child: content) : null,
actions: actions,
);
}

View file

@ -21,8 +21,6 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
this.textStyle,
this.textAlign = TextAlign.start,
this.maxLines = 1,
this.focusNode,
this.inputBorder = const OutlineInputBorder(),
});
final TextEditingController? controller;
final bool? enabled;
@ -36,8 +34,6 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
final TextStyle? textStyle;
final TextAlign textAlign;
final int? maxLines;
final InputBorder inputBorder;
final FocusNode? focusNode;
@override
TextField createAndroidWidget(BuildContext context) => TextField(
@ -47,11 +43,10 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
obscureText: obscureText,
decoration: InputDecoration(
labelText: labelText,
border: inputBorder,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(4)),
),
autocorrect: autocorrect,
keyboardType: keyboardType,
focusNode: focusNode,
style: textStyle,
inputFormatters: inputFormatters,
onChanged: onChanged,
@ -71,7 +66,6 @@ class PlatformField extends PlatformWidget<TextField, CupertinoTextField> {
keyboardType: keyboardType,
inputFormatters: inputFormatters,
onChanged: onChanged,
focusNode: focusNode,
maxLines: maxLines,
style: textStyle,
);

View file

@ -150,10 +150,10 @@ class ExpensesLineChart extends StatelessWidget {
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(),
color: ((MediaQuery.of(context).platformBrightness ==
Brightness.dark)
color:
(MediaQuery.of(context).platformBrightness == Brightness.dark)
? Colors.green.shade300
: Colors.green)
: Colors.green
.harmonizeWith(Theme.of(context).colorScheme.primary),
spots: List.generate(
yearly ? 12 : date.lastDay,
@ -167,10 +167,10 @@ class ExpensesLineChart extends StatelessWidget {
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(),
color: ((MediaQuery.of(context).platformBrightness ==
Brightness.dark)
color:
(MediaQuery.of(context).platformBrightness == Brightness.dark)
? Colors.red.shade300
: Colors.red)
: Colors.red
.harmonizeWith(Theme.of(context).colorScheme.primary),
spots: List.generate(
yearly
@ -522,7 +522,7 @@ class Indicator extends StatelessWidget {
/// Text shown next to the indicator circle
final String text;
/// Text style of the indicator
/// Style for the text
final TextStyle textStyle;
@override

View file

@ -1,27 +1,29 @@
// ignore_for_file: inference_failure_on_function_invocation
import 'dart:async';
import 'dart:math';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
import 'package:grouped_list/grouped_list.dart';
import 'package:image_picker/image_picker.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:prasule/api/category.dart';
import 'package:prasule/api/entry_data.dart';
import 'package:prasule/api/recurring_entry.dart';
import 'package:prasule/api/wallet.dart';
import 'package:prasule/api/wallet_entry.dart';
import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/main.dart';
import 'package:prasule/network/tessdata.dart';
import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/drawer.dart';
import 'package:prasule/util/text_color.dart';
@ -44,9 +46,6 @@ class _HomeViewState extends State<HomeView> {
List<Wallet> wallets = [];
DateTime? prevDate;
late String locale;
var _searchActive = false;
var _filter = "";
final searchFocus = FocusNode();
@override
void didChangeDependencies() {
super.didChangeDependencies();
@ -76,16 +75,7 @@ class _HomeViewState extends State<HomeView> {
@override
Widget build(BuildContext context) {
return PopScope(
canPop: !_searchActive, // don't pop when we just want
// to deactivate searchfield
onPopInvoked: (b) {
if (b) return;
_searchActive = false;
_filter = "";
setState(() {});
},
child: Scaffold(
return Scaffold(
drawer: makeDrawer(context, 1),
floatingActionButton: SpeedDial(
icon: Icons.add,
@ -98,7 +88,70 @@ class _HomeViewState extends State<HomeView> {
onTap: () {
// debug option to quickly fill a wallet with data
if (selectedWallet == null) return;
selectedWallet!.createTestEntries().then((_) {
selectedWallet!.entries.clear();
selectedWallet!.recurringEntries.clear();
final random = Random();
for (var i = 0; i < 30; i++) {
selectedWallet!.entries.add(
WalletSingleEntry(
data: EntryData(
name: "Test Entry #${i + 1}",
amount: random.nextInt(20000).toDouble(),
),
type: (random.nextInt(3) > 0)
? EntryType.expense
: EntryType.income,
date: DateTime(
2023,
random.nextInt(12) + 1,
random.nextInt(28) + 1,
),
category: selectedWallet!.categories[
random.nextInt(selectedWallet!.categories.length)],
id: selectedWallet!.nextId,
),
);
}
logger.d(
"Created ${selectedWallet!.entries.length} regular entries",
);
for (var i = 0; i < 3; i++) {
final type = random.nextInt(3);
selectedWallet!.recurringEntries.add(
RecurringWalletEntry(
data: EntryData(
name: "Recurring Entry #${i + 1}",
amount: random.nextInt(20000).toDouble(),
),
type: (random.nextInt(3) > 0)
? EntryType.expense
: EntryType.income,
date: DateTime(
2023,
random.nextInt(12) + 1,
random.nextInt(28) + 1,
),
category: selectedWallet!.categories[
random.nextInt(selectedWallet!.categories.length)],
id: selectedWallet!.nextId,
lastRunDate: DateTime.now().subtract(
Duration(
days: (type > 0) ? 3 : 3 * 31,
),
),
recurType: (type > 0) ? RecurType.day : RecurType.month,
),
);
}
logger.d(
"Created ${selectedWallet!.recurringEntries.length} recurring entries",
);
// save and reload
WalletManager.saveWallet(selectedWallet!).then((value) {
Navigator.of(context).pushReplacement(
platformRoute(
(p0) => const HomeView(),
@ -125,38 +178,25 @@ class _HomeViewState extends State<HomeView> {
SpeedDialChild(
child: const Icon(Icons.camera_alt),
label: AppLocalizations.of(context).addCamera,
onTap: () {
startOcr(SourceType.camera);
onTap: () async {
final picker = ImagePicker();
final media = await picker.pickImage(source: ImageSource.camera);
logger.i(media?.name);
},
),
SpeedDialChild(
child: const Icon(Icons.image),
label: AppLocalizations.of(context).addGallery,
onTap: () {
startOcr(SourceType.photoLibrary);
startOcr(ImageSource.gallery);
},
),
],
),
appBar: AppBar(
title: AnimatedCrossFade(
duration: const Duration(milliseconds: 500),
crossFadeState: _searchActive
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
firstChild: PlatformField(
inputBorder: InputBorder.none,
focusNode: searchFocus,
onChanged: (e) {
_filter = e;
setState(() {});
},
labelText: AppLocalizations.of(context).searchLabel,
),
secondChild: DropdownButton<int>(
value: (selectedWallet == null)
? -1
: wallets.indexOf(selectedWallet!),
title: DropdownButton<int>(
value:
(selectedWallet == null) ? -1 : wallets.indexOf(selectedWallet!),
items: [
...wallets.map(
(e) => DropdownMenuItem(
@ -189,17 +229,7 @@ class _HomeViewState extends State<HomeView> {
setState(() {});
},
),
),
actions: [
if (!_searchActive)
IconButton(
onPressed: () {
_searchActive = true;
setState(() {});
},
icon: const Icon(Icons.search),
),
if (!_searchActive)
PopupMenuButton(
itemBuilder: (context) => [
AppLocalizations.of(context).settings,
@ -214,7 +244,6 @@ class _HomeViewState extends State<HomeView> {
),
)
.then((value) async {
wallets = await WalletManager.listWallets();
selectedWallet =
await WalletManager.loadWallet(selectedWallet!.name);
});
@ -258,141 +287,36 @@ class _HomeViewState extends State<HomeView> {
),
],
)
: Overlay(
initialEntries: [
OverlayEntry(
builder: (context) => Column(
children: [
Text(
NumberFormat.compactCurrency(
locale: locale,
symbol: selectedWallet!.currency.symbol,
).format(
selectedWallet!.calculateCurrentBalance(),
),
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
),
),
const SizedBox(
height: 5,
),
if (selectedWallet!.calculateMonthStatus(
DateTime.now().month,
DateTime.now().year,
) ==
0)
Text(AppLocalizations.of(context).evenMoney)
else
RichText(
text: TextSpan(
children: [
TextSpan(
text: AppLocalizations.of(context)
.balanceStatusA,
),
TextSpan(
style: TextStyle(
color: (selectedWallet!
.calculateMonthStatus(
DateTime.now().month,
DateTime.now().year,
) >
0
? ((MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.green.shade300
: Colors.green)
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)
: ((MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red)
.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
)),
),
text: NumberFormat.compactCurrency(
locale: locale,
symbol:
selectedWallet!.currency.symbol,
).format(
selectedWallet!
.calculateMonthStatus(
DateTime.now().month,
DateTime.now().year,
),
),
),
TextSpan(
text: AppLocalizations.of(context)
.balanceStatusB,
),
],
),
),
const SizedBox(
height: 10,
),
Expanded(
child: GroupedListView(
: GroupedListView(
groupHeaderBuilder: (element) => Text(
DateFormat.yMMMM(locale)
.format(element.date),
DateFormat.yMMMM(locale).format(element.date),
style: TextStyle(
color: Theme.of(context)
.colorScheme
.primary,
color: Theme.of(context).colorScheme.primary,
),
),
elements: selectedWallet!.entries
.where((element) =>
element.data.name.contains(_filter))
.toList(),
itemComparator: (a, b) =>
b.date.compareTo(a.date),
groupBy: (e) =>
DateFormat.yMMMM(locale).format(e.date),
elements: selectedWallet!.entries,
itemComparator: (a, b) => b.date.compareTo(a.date),
groupBy: (e) => DateFormat.yMMMM(locale).format(e.date),
groupComparator: (a, b) {
// TODO: better sorting algorithm lol
final yearA =
RegExp(r'\d+').firstMatch(a);
final yearA = RegExp(r'\d+').firstMatch(a);
if (yearA == null) return 0;
final yearB =
RegExp(r'\d+').firstMatch(b);
final yearB = RegExp(r'\d+').firstMatch(b);
if (yearB == null) return 0;
final compareYears =
int.parse(yearB.group(0)!).compareTo(
int.parse(yearA.group(0)!),
);
if (compareYears != 0) {
return compareYears;
}
final compareYears = int.parse(yearB.group(0)!)
.compareTo(int.parse(yearA.group(0)!));
if (compareYears != 0) return compareYears;
final months = List<String>.generate(
12,
(index) =>
DateFormat.MMMM(locale).format(
(index) => DateFormat.MMMM(locale).format(
DateTime(2023, index + 1),
),
);
final monthA =
RegExp('[^0-9 ]+').firstMatch(a);
final monthA = RegExp('[^0-9 ]+').firstMatch(a);
if (monthA == null) return 0;
final monthB =
RegExp('[^0-9 ]+').firstMatch(b);
final monthB = RegExp('[^0-9 ]+').firstMatch(b);
if (monthB == null) return 0;
return months
.indexOf(monthB.group(0)!)
.compareTo(
return months.indexOf(monthB.group(0)!).compareTo(
months.indexOf(monthA.group(0)!),
);
},
@ -405,8 +329,7 @@ class _HomeViewState extends State<HomeView> {
Navigator.of(context)
.push<WalletSingleEntry>(
MaterialPageRoute(
builder: (c) =>
CreateSingleEntryView(
builder: (c) => CreateSingleEntryView(
w: selectedWallet!,
editEntry: element,
),
@ -414,65 +337,44 @@ class _HomeViewState extends State<HomeView> {
)
.then(
(editedEntry) {
if (editedEntry == null) {
return;
}
selectedWallet!.entries
.remove(element);
selectedWallet!.entries
.add(editedEntry);
WalletManager.saveWallet(
selectedWallet!,
);
if (editedEntry == null) return;
selectedWallet!.entries.remove(element);
selectedWallet!.entries.add(editedEntry);
WalletManager.saveWallet(selectedWallet!);
setState(() {});
},
);
},
backgroundColor: Theme.of(context)
.colorScheme
.secondary,
foregroundColor: Theme.of(context)
.colorScheme
.onSecondary,
backgroundColor:
Theme.of(context).colorScheme.secondary,
foregroundColor:
Theme.of(context).colorScheme.onSecondary,
icon: Icons.edit,
),
SlidableAction(
backgroundColor: Theme.of(context)
.colorScheme
.error,
foregroundColor: Theme.of(context)
.colorScheme
.onError,
backgroundColor:
Theme.of(context).colorScheme.error,
foregroundColor:
Theme.of(context).colorScheme.onError,
icon: Icons.delete,
onPressed: (c) {
showAdaptiveDialog(
showDialog(
context: context,
builder: (cx) =>
AlertDialog.adaptive(
title: Text(
AppLocalizations.of(
context,
).sureDialog,
),
builder: (cx) => PlatformDialog(
title:
AppLocalizations.of(context).sureDialog,
content: Text(
AppLocalizations.of(context)
.deleteSure,
AppLocalizations.of(context).deleteSure,
),
actions: [
PlatformButton(
text: AppLocalizations.of(
context,
).yes,
text: AppLocalizations.of(context).yes,
onPressed: () {
selectedWallet?.entries
.removeWhere(
(e) =>
e.id ==
element.id,
selectedWallet?.entries.removeWhere(
(e) => e.id == element.id,
);
WalletManager
.saveWallet(
WalletManager.saveWallet(
selectedWallet!,
);
Navigator.of(cx).pop();
@ -480,9 +382,7 @@ class _HomeViewState extends State<HomeView> {
},
),
PlatformButton(
text: AppLocalizations.of(
context,
).no,
text: AppLocalizations.of(context).no,
onPressed: () {
Navigator.of(cx).pop();
},
@ -497,16 +397,15 @@ class _HomeViewState extends State<HomeView> {
child: ListTile(
leading: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(16),
borderRadius: BorderRadius.circular(16),
color: element.category.color,
),
child: Padding(
padding: const EdgeInsets.all(8),
child: Icon(
element.category.icon,
color: element.category.color
.calculateTextColor(),
color:
element.category.color.calculateTextColor(),
),
),
),
@ -516,19 +415,15 @@ class _HomeViewState extends State<HomeView> {
children: [
TextSpan(
text: NumberFormat.currency(
symbol: selectedWallet!
.currency.symbol,
symbol: selectedWallet!.currency.symbol,
).format(element.data.amount),
style: TextStyle(
color: (element.type ==
EntryType.income)
color: (element.type == EntryType.income)
? (MediaQuery.of(context)
.platformBrightness ==
Brightness.dark)
? Colors
.green.shade300
: Colors.green
.harmonizeWith(
? Colors.green.shade300
: Colors.green.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
@ -537,8 +432,7 @@ class _HomeViewState extends State<HomeView> {
.platformBrightness ==
Brightness.dark)
? Colors.red.shade300
: Colors.red
.harmonizeWith(
: Colors.red.harmonizeWith(
Theme.of(context)
.colorScheme
.primary,
@ -562,43 +456,18 @@ class _HomeViewState extends State<HomeView> {
),
),
),
],
),
),
OverlayEntry(
builder: (context) => SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: GestureDetector(
onTap: () {
if (!_searchActive) return;
if (!searchFocus.hasFocus) {
_searchActive = false;
_filter = "";
setState(() {});
return;
}
searchFocus.unfocus();
},
),
),
),
],
),
),
),
),
);
}
Future<void> startOcr(SourceType sourceType) async {
Future<void> startOcr(ImageSource imgSrc) async {
final availableLanguages = await TessdataApi.getDownloadedData();
if (availableLanguages.isEmpty) {
if (!mounted) return;
await showAdaptiveDialog(
await showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
title: Text(AppLocalizations.of(context).missingOcr),
builder: (c) => PlatformDialog(
title: AppLocalizations.of(context).missingOcr,
actions: [
PlatformButton(
text: AppLocalizations.of(context).download,
@ -628,18 +497,16 @@ class _HomeViewState extends State<HomeView> {
List<bool>.filled(availableLanguages.length, false);
selectedLanguages[0] = true;
await showAdaptiveDialog(
await showDialog(
context: context,
builder: (c) => StatefulBuilder(
builder: (ctx, setState) => AlertDialog.adaptive(
builder: (ctx, setState) => PlatformDialog(
actions: [
TextButton(
onPressed: () async {
final filePath = await FlutterFileDialog.pickFile(
params: OpenFileDialogParams(
dialogType: OpenFileDialogType.image,
sourceType: sourceType));
if (filePath == null) {
final picker = ImagePicker();
final media = await picker.pickImage(source: imgSrc);
if (media == null) {
if (mounted) Navigator.of(context).pop();
return;
}
@ -654,16 +521,16 @@ class _HomeViewState extends State<HomeView> {
logger.i(selected);
if (!mounted) return;
unawaited(
showAdaptiveDialog(
showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
title: Text(AppLocalizations.of(context).ocrLoading),
builder: (c) => PlatformDialog(
title: AppLocalizations.of(context).ocrLoading,
),
barrierDismissible: false,
),
);
final string = await FlutterTesseractOcr.extractText(
filePath,
media.path,
language: selected,
args: {
"psm": "4",
@ -689,7 +556,6 @@ class _HomeViewState extends State<HomeView> {
}
description.write("${line.replaceAll(regex, "")}\n");
}
if (!ctx.mounted) return;
Navigator.of(ctx).pop();
// show edit
final newEntry =
@ -725,7 +591,7 @@ class _HomeViewState extends State<HomeView> {
child: const Text("Cancel"),
),
],
title: Text(AppLocalizations.of(context).ocrSelect),
title: AppLocalizations.of(context).ocrSelect,
content: Column(
children: [
...List.generate(
@ -758,4 +624,23 @@ class _HomeViewState extends State<HomeView> {
),
);
}
Future<void> getLostData() async {
final picker = ImagePicker();
final response = await picker.retrieveLostData();
if (response.isEmpty) {
return;
}
final files = response.files;
if (files != null) {
logger.i("Found lost files");
_handleLostFiles(files);
} else {
logger.e(response.exception);
}
}
void _handleLostFiles(List<XFile> files) {
// TODO: implement
}
}

View file

@ -11,6 +11,7 @@ import 'package:prasule/api/recurring_entry.dart';
import 'package:prasule/api/wallet.dart';
import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/drawer.dart';
import 'package:prasule/util/text_color.dart';
@ -214,10 +215,9 @@ class _RecurringEntriesViewState extends State<RecurringEntriesView> {
onPressed: (c) {
showDialog(
context: context,
builder: (cx) => AlertDialog.adaptive(
title: Text(
builder: (cx) => PlatformDialog(
title:
AppLocalizations.of(context).sureDialog,
),
content: Text(
AppLocalizations.of(context).deleteSure,
),

View file

@ -12,6 +12,7 @@ import 'package:prasule/api/wallet.dart';
import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/main.dart';
import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/text_color.dart';
@ -145,10 +146,10 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
(await SharedPreferences.getInstance())
.getBool("useMaterialYou") ??
false;
if (!context.mounted) return;
await showAdaptiveDialog(
if (!mounted) return;
await showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
builder: (c) => PlatformDialog(
actions: [
PlatformButton(
text: AppLocalizations.of(context).done,
@ -157,8 +158,8 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
},
),
],
title: Text(
AppLocalizations.of(context).pickColor),
title:
AppLocalizations.of(context).pickColor,
content: Column(
children: [
ColorPicker(
@ -214,9 +215,9 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
final controller = TextEditingController(
text: selectedWallet!.categories[i].name,
);
showAdaptiveDialog(
showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
builder: (c) => PlatformDialog(
actions: [
TextButton(
onPressed: () async {
@ -226,7 +227,7 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
await WalletManager.saveWallet(
selectedWallet!,
);
if (!context.mounted) return;
if (!mounted) return;
Navigator.of(context).pop();
},
child: Text(
@ -242,8 +243,8 @@ class _EditCategoriesViewState extends State<EditCategoriesView> {
),
),
],
title: Text(AppLocalizations.of(context)
.setupCategoriesEditingName),
title: AppLocalizations.of(context)
.setupCategoriesEditingName,
content: SizedBox(
width: 400,
child:

View file

@ -2,6 +2,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/pw/platformdialog.dart';
import 'package:settings_ui/settings_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -49,10 +50,10 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
? AppLocalizations.of(context).barChart
: AppLocalizations.of(context).lineChart,
),
onPressed: (c) => showAdaptiveDialog(
onPressed: (c) => showDialog(
context: c,
builder: (ctx) => AlertDialog.adaptive(
title: Text(AppLocalizations.of(context).selectType),
builder: (ctx) => PlatformDialog(
title: AppLocalizations.of(context).selectType,
content: Column(
children: [
SizedBox(
@ -69,7 +70,7 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
final s = await SharedPreferences.getInstance();
await s.setInt("yearlygraph", 1);
_yearly = 1;
if (!ctx.mounted) return;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
@ -89,7 +90,7 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
final s = await SharedPreferences.getInstance();
await s.setInt("yearlygraph", 2);
_yearly = 2;
if (!ctx.mounted) return;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
@ -109,8 +110,8 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
),
onPressed: (c) => showDialog(
context: c,
builder: (ctx) => AlertDialog.adaptive(
title: Text(AppLocalizations.of(context).selectType),
builder: (ctx) => PlatformDialog(
title: AppLocalizations.of(context).selectType,
content: Column(
children: [
SizedBox(
@ -127,7 +128,7 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
final s = await SharedPreferences.getInstance();
await s.setInt("monthlygraph", 1);
_monthly = 1;
if (!ctx.mounted) return;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},
@ -147,7 +148,7 @@ class _GraphTypeSettingsViewState extends State<GraphTypeSettingsView> {
final s = await SharedPreferences.getInstance();
await s.setInt("monthlygraph", 2);
_monthly = 2;
if (!ctx.mounted) return;
if (!mounted) return;
Navigator.of(ctx).pop();
setState(() {});
},

View file

@ -1,13 +1,9 @@
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/main.dart';
import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/show_message.dart';
import 'package:prasule/views/settings/edit_categories.dart';
import 'package:prasule/views/settings/graph_type.dart';
import 'package:prasule/views/settings/tessdata_list.dart';
@ -107,190 +103,6 @@ class _SettingsViewState extends State<SettingsView> {
),
],
),
SettingsSection(
title: Text(AppLocalizations.of(context).settingsData),
tiles: [
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).exportSingle),
description:
Text(AppLocalizations.of(context).exportSingleDesc),
onPressed: (ctx) async {
final all = await WalletManager.listWallets();
if (!ctx.mounted) return;
final w = await showAdaptiveDialog<String>(
context: ctx,
builder: (ctx) => AlertDialog.adaptive(
title: Text(
AppLocalizations.of(context).selectExportWallet,
),
actions: [
PlatformButton(
text: AppLocalizations.of(context).cancel,
onPressed: () => Navigator.of(ctx).pop(),
),
],
content: SizedBox(
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.3,
child: ListView.builder(
itemBuilder: (con, i) => InkWell(
onTap: () => Navigator.of(ctx).pop(all[i].name),
child: Padding(
padding: const EdgeInsets.all(8),
child: Text(
all[i].name,
textAlign: TextAlign.center,
),
),
),
shrinkWrap: true,
itemCount: all.length,
),
),
),
);
if (w == null) return;
try {
await WalletManager.exportWallet(name: w);
} catch (e) {
if (!context.mounted) return;
unawaited(
showAdaptiveDialog(
context: context,
builder: (ctx) => AlertDialog.adaptive(
title: Text(
AppLocalizations.of(context).exportError,
),
content: SingleChildScrollView(
child: Flexible(
child: Text(e.toString()),
),
),
),
),
);
logger.e(e);
return;
}
if (!ctx.mounted) return;
unawaited(
showMessage(
AppLocalizations.of(ctx).exportCompleted,
ctx,
),
);
},
),
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).exportArchive),
description:
Text(AppLocalizations.of(context).exportArchiveDesc),
onPressed: (ctx) async {
try {
await WalletManager.exportAllWallets();
} catch (e) {
if (!ctx.mounted) return;
unawaited(
showAdaptiveDialog(
context: context,
builder: (ctx) => AlertDialog.adaptive(
title: Text(
AppLocalizations.of(context).exportError,
),
content: SingleChildScrollView(
child: Flexible(
child: Text(e.toString()),
),
),
),
),
);
logger.e(e);
return;
}
if (!ctx.mounted) return;
unawaited(
showMessage(
AppLocalizations.of(ctx).exportCompleted,
context,
),
);
},
),
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).importSingle),
description:
Text(AppLocalizations.of(context).importSingleDesc),
onPressed: (ctx) async {
try {
await WalletManager.importWallet();
} catch (e) {
if (!ctx.mounted) return;
unawaited(
showAdaptiveDialog(
context: context,
builder: (ctx) => AlertDialog.adaptive(
title: Text(
AppLocalizations.of(context).exportError,
),
content: SingleChildScrollView(
child: Flexible(
child: Text(e.toString()),
),
),
),
),
);
logger.e(e);
return;
}
if (!ctx.mounted) return;
unawaited(
showMessage(
AppLocalizations.of(ctx).importCompleted,
context,
),
);
},
),
SettingsTile.navigation(
title: Text(AppLocalizations.of(context).importArchive),
description:
Text(AppLocalizations.of(context).importArchiveDesc),
onPressed: (ctx) async {
try {
await WalletManager.importArchive();
} catch (e) {
if (!ctx.mounted) return;
unawaited(
showAdaptiveDialog(
context: context,
builder: (ctx) => AlertDialog.adaptive(
title: Text(
AppLocalizations.of(context).exportError,
),
content: SingleChildScrollView(
child: Flexible(
child: Text(e.toString()),
),
),
),
),
);
logger.e(e);
return;
}
if (!ctx.mounted) return;
unawaited(
showMessage(
AppLocalizations.of(ctx).importCompleted,
context,
),
);
},
),
],
),
],
),
);

View file

@ -9,6 +9,7 @@ import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
import 'package:prasule/main.dart';
import 'package:prasule/network/tessdata.dart';
import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart';
/// Used to manage downloaded Tessdata for OCR
class TessdataListView extends StatefulWidget {
@ -61,11 +62,10 @@ class _TessdataListViewState extends State<TessdataListView> {
final lang = _tessdata[i].keys.first;
if (_tessdata[i][lang]!) {
// deleting data
await showAdaptiveDialog(
await showDialog(
context: context,
builder: (context) => AlertDialog.adaptive(
title:
Text(AppLocalizations.of(context).sureDialog),
builder: (context) => PlatformDialog(
title: AppLocalizations.of(context).sureDialog,
content: Text(
AppLocalizations.of(context).deleteOcr(lang),
),
@ -75,9 +75,7 @@ class _TessdataListViewState extends State<TessdataListView> {
onPressed: () async {
await TessdataApi.deleteData(lang);
_tessdata[i][lang] = true;
if (context.mounted) {
Navigator.of(context).pop();
}
if (mounted) Navigator.of(context).pop();
},
),
PlatformButton(
@ -98,11 +96,11 @@ class _TessdataListViewState extends State<TessdataListView> {
final progressStream = StreamController<double>();
unawaited(
showAdaptiveDialog(
showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
title: Text(AppLocalizations.of(context)
.langDownloadDialog(lang)),
builder: (c) => PlatformDialog(
title: AppLocalizations.of(context)
.langDownloadDialog(lang),
content: StreamBuilder(
builder: (context, snapshot) {
if (snapshot.connectionState ==

View file

@ -1,7 +1,5 @@
// ignore_for_file: inference_failure_on_function_invocation
import 'dart:async';
import 'package:currency_picker/currency_picker.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flex_color_picker/flex_color_picker.dart';
@ -14,6 +12,7 @@ import 'package:prasule/api/category.dart';
import 'package:prasule/api/wallet.dart';
import 'package:prasule/api/wallet_manager.dart';
import 'package:prasule/pw/platformbutton.dart';
import 'package:prasule/pw/platformdialog.dart';
import 'package:prasule/pw/platformfield.dart';
import 'package:prasule/pw/platformroute.dart';
import 'package:prasule/util/show_message.dart';
@ -119,22 +118,11 @@ class _SetupViewState extends State<SetupView> {
next: Text(AppLocalizations.of(context).next),
back: Text(AppLocalizations.of(context).back),
done: Text(AppLocalizations.of(context).finish),
onDone: () async {
onDone: () {
if (name.isEmpty) {
unawaited(
showMessage(
AppLocalizations.of(context).errorEmptyName,
context,
),
);
return;
}
if (await WalletManager.exists(name) && context.mounted) {
unawaited(
showMessage(
AppLocalizations.of(context).walletExists,
context,
),
);
return;
}
@ -143,19 +131,25 @@ class _SetupViewState extends State<SetupView> {
currency: _selectedCurrency,
categories: categories,
);
await WalletManager.saveWallet(wallet);
if (widget.newWallet && context.mounted) {
WalletManager.saveWallet(wallet).then(
(value) {
if (!value) {
showMessage(
AppLocalizations.of(context).walletExists,
context,
);
return;
}
if (widget.newWallet) {
Navigator.of(context).pop();
return;
}
if (!context.mounted) return;
unawaited(
Navigator.of(context).pushReplacement(
platformRoute(
(c) => const HomeView(),
),
),
);
},
);
},
pages: [
@ -303,10 +297,10 @@ class _SetupViewState extends State<SetupView> {
(await SharedPreferences.getInstance())
.getBool("useMaterialYou") ??
false;
if (!context.mounted) return;
await showAdaptiveDialog(
if (!mounted) return;
await showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
builder: (c) => PlatformDialog(
actions: [
PlatformButton(
text: AppLocalizations.of(context)
@ -316,10 +310,8 @@ class _SetupViewState extends State<SetupView> {
},
),
],
title: Text(
AppLocalizations.of(context)
title: AppLocalizations.of(context)
.pickColor,
),
content: Column(
children: [
ColorPicker(
@ -371,9 +363,9 @@ class _SetupViewState extends State<SetupView> {
final controller = TextEditingController(
text: categories[i].name,
);
showAdaptiveDialog(
showDialog(
context: context,
builder: (c) => AlertDialog.adaptive(
builder: (c) => PlatformDialog(
actions: [
TextButton(
onPressed: () {
@ -398,10 +390,8 @@ class _SetupViewState extends State<SetupView> {
),
),
],
title: Text(
AppLocalizations.of(context)
title: AppLocalizations.of(context)
.setupCategoriesEditingName,
),
content: SizedBox(
width: 400,
child: PlatformField(

View file

@ -18,7 +18,7 @@ packages:
source: hosted
version: "6.3.0"
archive:
dependency: "direct main"
dependency: transitive
description:
name: archive
sha256: "22600aa1e926be775fa5fe7e6894e7fb3df9efda8891c73f70fb3262399a432d"
@ -85,10 +85,10 @@ packages:
dependency: "direct dev"
description:
name: build_runner
sha256: "581bacf68f89ec8792f5e5a0b2c4decd1c948e97ce659dc783688c8a88fbec21"
sha256: "67d591d602906ef9201caf93452495ad1812bea2074f04e25dbd7c133785821b"
url: "https://pub.dev"
source: hosted
version: "2.4.8"
version: "2.4.7"
build_runner_core:
dependency: transitive
description:
@ -149,10 +149,10 @@ packages:
dependency: transitive
description:
name: code_builder
sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37
sha256: feee43a5c05e7b3199bb375a86430b8ada1b04104f2923d0e03cc01ca87b6d84
url: "https://pub.dev"
source: hosted
version: "4.10.0"
version: "4.9.0"
collection:
dependency: transitive
description:
@ -177,6 +177,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.7.2"
cross_file:
dependency: transitive
description:
name: cross_file
sha256: fedaadfa3a6996f75211d835aaeb8fede285dae94262485698afd832371b9a5e
url: "https://pub.dev"
source: hosted
version: "0.3.3+8"
crypto:
dependency: transitive
description:
@ -265,6 +273,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
file_selector_linux:
dependency: transitive
description:
name: file_selector_linux
sha256: "045d372bf19b02aeb69cacf8b4009555fb5f6f0b7ad8016e5f46dd1387ddd492"
url: "https://pub.dev"
source: hosted
version: "0.9.2+1"
file_selector_macos:
dependency: transitive
description:
name: file_selector_macos
sha256: b15c3da8bd4908b9918111fa486903f5808e388b8d1c559949f584725a6594d6
url: "https://pub.dev"
source: hosted
version: "0.9.3+3"
file_selector_platform_interface:
dependency: transitive
description:
name: file_selector_platform_interface
sha256: "0aa47a725c346825a2bd396343ce63ac00bda6eff2fbc43eabe99737dede8262"
url: "https://pub.dev"
source: hosted
version: "2.6.1"
file_selector_windows:
dependency: transitive
description:
name: file_selector_windows
sha256: d3547240c20cabf205c7c7f01a50ecdbc413755814d6677f3cb366f04abcead0
url: "https://pub.dev"
source: hosted
version: "0.9.3+1"
fixnum:
dependency: transitive
description:
@ -285,10 +325,10 @@ packages:
dependency: "direct main"
description:
name: flex_color_picker
sha256: "0871edc170153cfc3de316d30625f40a85daecfa76ce541641f3cc0ec7757cbf"
sha256: f37476ab3e80dcaca94e428e159944d465dd16312fda9ff41e07e86f04bfa51c
url: "https://pub.dev"
source: hosted
version: "3.3.1"
version: "3.3.0"
flex_seed_scheme:
dependency: transitive
description:
@ -307,14 +347,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_file_dialog:
dependency: "direct main"
description:
name: flutter_file_dialog
sha256: "9344b8f07be6a1b6f9854b723fb0cf84a8094ba94761af1d213589d3cb087488"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
flutter_iconpicker:
dependency: "direct main"
description:
@ -392,6 +424,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
sha256: b068ffc46f82a55844acfa4fdbb61fad72fa2aef0905548419d97f0f95c456da
url: "https://pub.dev"
source: hosted
version: "2.0.17"
flutter_slidable:
dependency: "direct main"
description:
@ -479,6 +519,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.1.2"
http:
dependency: transitive
description:
name: http
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139
url: "https://pub.dev"
source: hosted
version: "1.1.2"
http_multi_server:
dependency: transitive
description:
@ -499,10 +547,74 @@ packages:
dependency: transitive
description:
name: image
sha256: "004a2e90ce080f8627b5a04aecb4cdfac87d2c3f3b520aa291260be5a32c033d"
sha256: "028f61960d56f26414eb616b48b04eb37d700cbe477b7fb09bf1d7ce57fd9271"
url: "https://pub.dev"
source: hosted
version: "4.1.4"
version: "4.1.3"
image_picker:
dependency: "direct main"
description:
name: image_picker
sha256: "340efe08645537d6b088a30620ee5752298b1630f23a829181172610b868262b"
url: "https://pub.dev"
source: hosted
version: "1.0.6"
image_picker_android:
dependency: transitive
description:
name: image_picker_android
sha256: "1a27bf4cc0330389cebe465bab08fe6dec97e44015b4899637344bb7297759ec"
url: "https://pub.dev"
source: hosted
version: "0.8.9+2"
image_picker_for_web:
dependency: transitive
description:
name: image_picker_for_web
sha256: e2423c53a68b579a7c37a1eda967b8ae536c3d98518e5db95ca1fe5719a730a3
url: "https://pub.dev"
source: hosted
version: "3.0.2"
image_picker_ios:
dependency: transitive
description:
name: image_picker_ios
sha256: eac0a62104fa12feed213596df0321f57ce5a572562f72a68c4ff81e9e4caacf
url: "https://pub.dev"
source: hosted
version: "0.8.9"
image_picker_linux:
dependency: transitive
description:
name: image_picker_linux
sha256: "4ed1d9bb36f7cd60aa6e6cd479779cc56a4cb4e4de8f49d487b1aaad831300fa"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
image_picker_macos:
dependency: transitive
description:
name: image_picker_macos
sha256: "3f5ad1e8112a9a6111c46d0b57a7be2286a9a07fc6e1976fdf5be2bd31d4ff62"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
sha256: "0e827c156e3a90edd3bbe7f6de048b39247b16e58173b08a835b7eb00aba239e"
url: "https://pub.dev"
source: hosted
version: "2.9.2"
image_picker_windows:
dependency: transitive
description:
name: image_picker_windows
sha256: "6ad07afc4eb1bc25f3a01084d28520496c4a3bb0cb13685435838167c9dcedeb"
url: "https://pub.dev"
source: hosted
version: "0.2.1+1"
integration_test:
dependency: "direct dev"
description: flutter
@ -560,26 +672,18 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
sha256: "04be76c4a4bb50f14904e64749237e541e7c7bcf7ec0b196907322ab5d2fc739"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "9.0.16"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
sha256: b06739349ec2477e943055aea30172c5c7000225f79dad4702e2ec0eda79a6ff
url: "https://pub.dev"
source: hosted
version: "2.0.1"
version: "1.0.5"
lints:
dependency: transitive
description:
@ -608,10 +712,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.16+1"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
@ -664,18 +768,18 @@ packages:
dependency: transitive
description:
name: path
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
version: "1.8.3"
path_provider:
dependency: "direct main"
description:
name: path_provider
sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b
sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
path_provider_android:
dependency: transitive
description:
@ -688,10 +792,10 @@ packages:
dependency: transitive
description:
name: path_provider_foundation
sha256: "5a7999be66e000916500be4f15a3633ebceb8302719b47b9cc49ce924125350f"
sha256: "19314d595120f82aca0ba62787d58dde2cc6b5df7d2f0daf72489e38d1b57f2d"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.1"
path_provider_linux:
dependency: transitive
description:
@ -704,10 +808,10 @@ packages:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
sha256: "94b1e0dd80970c1ce43d5d4e050a9918fce4f4a775e6142424c30a29a363265c"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
version: "2.1.1"
path_provider_windows:
dependency: transitive
description:
@ -728,10 +832,10 @@ packages:
dependency: transitive
description:
name: platform
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
sha256: "0a279f0707af40c890e80b1e9df8bb761694c074ba7e1d4ab1bc4b728e200b59"
url: "https://pub.dev"
source: hosted
version: "3.1.4"
version: "3.1.3"
plugin_platform_interface:
dependency: transitive
description:
@ -744,10 +848,10 @@ packages:
dependency: transitive
description:
name: pointycastle
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
sha256: "7c1e5f0d23c9016c5bbd8b1473d0d3fb3fc851b876046039509e18e0c7485f2c"
url: "https://pub.dev"
source: hosted
version: "3.7.4"
version: "3.7.3"
pool:
dependency: transitive
description:
@ -760,10 +864,10 @@ packages:
dependency: transitive
description:
name: process
sha256: "21e54fd2faf1b5bdd5102afd25012184a6793927648ea81eea80552ac9405b32"
sha256: "266ca5be5820feefc777793d0a583acfc8c40834893c87c00c6c09e2cf58ea42"
url: "https://pub.dev"
source: hosted
version: "5.0.2"
version: "5.0.1"
provider:
dependency: transitive
description:
@ -816,10 +920,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
sha256: "7bf53a9f2d007329ee6f3df7268fd498f8373602f943c975598bbb34649b62a7"
url: "https://pub.dev"
source: hosted
version: "2.3.5"
version: "2.3.4"
shared_preferences_linux:
dependency: transitive
description:
@ -832,10 +936,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b"
sha256: d4ec5fc9ebb2f2e056c617112aa75dcf92fc2e4faaf2ae999caa297473f75d8a
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.3.1"
shared_preferences_web:
dependency: transitive
description:
@ -1053,18 +1157,18 @@ packages:
dependency: transitive
description:
name: web
sha256: "4188706108906f002b3a293509234588823c8c979dc83304e229ff400c996b05"
sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa
url: "https://pub.dev"
source: hosted
version: "0.4.2"
version: "0.4.0"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
sha256: "939ab60734a4f8fa95feacb55804fa278de28bdeef38e616dc08e44a84adea23"
sha256: "045ec2137c27bf1a32e6ffa0e734d532a6677bf9016a0d1a406c54e499ff945b"
url: "https://pub.dev"
source: hosted
version: "2.4.3"
version: "2.4.1"
webdriver:
dependency: transitive
description:

View file

@ -1,7 +1,7 @@
name: prasule
description: Open-source private expense tracker
version: 1.0.0-alpha+5
version: 1.0.0-alpha+4
environment:
sdk: '>=3.1.0-262.2.beta <4.0.0'
@ -13,7 +13,6 @@ environment:
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
archive: ^3.4.10
cupertino_icons: ^1.0.2
currency_picker: ^2.0.16
dio: ^5.3.0
@ -22,7 +21,6 @@ dependencies:
flex_color_picker: ^3.3.0
flutter:
sdk: flutter
flutter_file_dialog: ^3.0.2
flutter_iconpicker: ^3.2.4
flutter_localizations:
sdk: flutter
@ -31,6 +29,7 @@ dependencies:
flutter_tesseract_ocr: ^0.4.23
fluttertoast: ^8.2.4
grouped_list: ^5.1.2
image_picker: ^1.0.1
intl: any
introduction_screen: ^3.1.11
json_annotation: ^4.8.1