Compare commits
13 Commits
44279796c4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
f4294e0e11
|
|||
|
78614bd021
|
|||
|
f1d7d31a3c
|
|||
|
6a9da33283
|
|||
| 35930d188c | |||
| 51cb8868a3 | |||
| fc6f64a271 | |||
| f86c4cd18b | |||
| 979fecb60a | |||
| 2b53d1ab74 | |||
| 2006ebf5cb | |||
| b2175ddafd | |||
| 57ed6f44cd |
25
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "krezus",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "krezus (profile mode)",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "profile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "krezus (release mode)",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"flutterMode": "release"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# Tunas
|
# Krezus (tunas)
|
||||||
|
|
||||||
A very complicated tool that should have been an excel sheet.
|
A very complicated tool that should have been an excel sheet.
|
||||||
@@ -23,7 +23,7 @@ if (flutterVersionName == null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace "com.example.tunas"
|
namespace "sx.glt.krezus"
|
||||||
compileSdkVersion flutter.compileSdkVersion
|
compileSdkVersion flutter.compileSdkVersion
|
||||||
ndkVersion flutter.ndkVersion
|
ndkVersion flutter.ndkVersion
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
applicationId "com.example.tunas"
|
applicationId "sx.glt.krezus"
|
||||||
// You can update the following values to match your application needs.
|
// You can update the following values to match your application needs.
|
||||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||||
minSdkVersion flutter.minSdkVersion
|
minSdkVersion flutter.minSdkVersion
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<application
|
<application
|
||||||
android:label="tunas"
|
android:label="krezus"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/launcher_icon">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.example.tunas
|
package sx.glt.krezus
|
||||||
|
|
||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
|
|
||||||
|
|||||||
BIN
android/app/src/main/res/mipmap-hdpi/launcher_icon.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/launcher_icon.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/launcher_icon.png
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/launcher_icon.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/launcher_icon.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
assets/icon/krezus.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/icon/krezus2.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/icon/tunas.png
Normal file
|
After Width: | Height: | Size: 29 KiB |
@@ -367,7 +367,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas;
|
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
@@ -384,7 +384,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -402,7 +402,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||||
@@ -418,7 +418,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas.RunnerTests;
|
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus.RunnerTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||||
@@ -545,7 +545,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas;
|
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -567,7 +567,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas;
|
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 295 B After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 450 B After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 462 B After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 406 B After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 586 B After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 7.3 KiB |
|
After Width: | Height: | Size: 2.9 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 862 B After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 762 B After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 9.3 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 10 KiB |
@@ -5,7 +5,7 @@
|
|||||||
<key>CFBundleDevelopmentRegion</key>
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
<string>Tunas</string>
|
<string>Krezus</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
<string>6.0</string>
|
<string>6.0</string>
|
||||||
<key>CFBundleName</key>
|
<key>CFBundleName</key>
|
||||||
<string>tunas</string>
|
<string>krezus</string>
|
||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
|
|||||||
73
lib/app.dart
@@ -1,12 +1,12 @@
|
|||||||
|
import 'package:dynamic_color/dynamic_color.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
import 'package:tunas/clients/storage/storage_client.dart';
|
import 'package:krezus/clients/storage/json_storage_client.dart';
|
||||||
import 'package:tunas/pages/home/home_page.dart';
|
import 'package:krezus/pages/home/home_page.dart';
|
||||||
import 'package:tunas/repositories/json/json_repository.dart';
|
import 'package:krezus/repositories/json/json_repository.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
import 'package:tunas/theme.dart';
|
|
||||||
|
|
||||||
class App extends StatefulWidget {
|
class App extends StatefulWidget {
|
||||||
const App({super.key});
|
const App({super.key});
|
||||||
@@ -30,7 +30,7 @@ class AppView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AppViewState extends State<AppView> {
|
class _AppViewState extends State<AppView> {
|
||||||
late final StorageClient _storageClient;
|
late final JsonStorageClient _storageClient;
|
||||||
late final JsonRepository _jsonRepository;
|
late final JsonRepository _jsonRepository;
|
||||||
late final TransactionsRepository _transactionsRepository;
|
late final TransactionsRepository _transactionsRepository;
|
||||||
late final MetadataRepository _metadataRepository;
|
late final MetadataRepository _metadataRepository;
|
||||||
@@ -39,13 +39,15 @@ class _AppViewState extends State<AppView> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_storageClient = StorageClient();
|
_storageClient = JsonStorageClient();
|
||||||
_jsonRepository = JsonRepository(storageClient: _storageClient);
|
_jsonRepository = JsonRepository(storageClient: _storageClient);
|
||||||
_transactionsRepository = TransactionsRepository(jsonRepository: _jsonRepository);
|
_transactionsRepository = TransactionsRepository(jsonRepository: _jsonRepository);
|
||||||
_metadataRepository = MetadataRepository(jsonRepository: _jsonRepository);
|
_metadataRepository = MetadataRepository(jsonRepository: _jsonRepository);
|
||||||
|
|
||||||
_transactionsRepository.loadTransactions();
|
_transactionsRepository.loadTransactions();
|
||||||
_metadataRepository.loadMetadata();
|
_metadataRepository.loadMetadata();
|
||||||
|
|
||||||
|
_metadataRepository.getSettingsStream().listen((event) => setState(() {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -56,23 +58,44 @@ class _AppViewState extends State<AppView> {
|
|||||||
RepositoryProvider.value(value: _transactionsRepository),
|
RepositoryProvider.value(value: _transactionsRepository),
|
||||||
RepositoryProvider.value(value: _metadataRepository),
|
RepositoryProvider.value(value: _metadataRepository),
|
||||||
],
|
],
|
||||||
child: MaterialApp(
|
child: DynamicColorBuilder(
|
||||||
title: 'Tunas',
|
builder: ((lightDynamic, darkDynamic) {
|
||||||
theme: ThemeData(useMaterial3: true, colorScheme: lightColorScheme),
|
ColorScheme lightColorScheme;
|
||||||
darkTheme: ThemeData(useMaterial3: true, colorScheme: darkColorScheme),
|
ColorScheme darkColorScheme;
|
||||||
themeMode: ThemeMode.dark,
|
|
||||||
initialRoute: '/home',
|
if (lightDynamic != null && darkDynamic != null) {
|
||||||
routes: {
|
lightColorScheme = lightDynamic.harmonized();
|
||||||
'/home':(context) => const HomePage(),
|
darkColorScheme = darkDynamic.harmonized();
|
||||||
},
|
} else {
|
||||||
localizationsDelegates: const [
|
lightColorScheme = ColorScheme.fromSeed(
|
||||||
GlobalMaterialLocalizations.delegate,
|
seedColor: const Color.fromARGB(255, 103, 6, 231),
|
||||||
GlobalWidgetsLocalizations.delegate,
|
);
|
||||||
GlobalCupertinoLocalizations.delegate
|
|
||||||
],
|
darkColorScheme = ColorScheme.fromSeed(
|
||||||
supportedLocales: const [
|
seedColor: const Color.fromARGB(255, 103, 6, 231),
|
||||||
Locale('fr')
|
brightness: Brightness.dark,
|
||||||
],
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MaterialApp(
|
||||||
|
title: 'Krezus',
|
||||||
|
theme: ThemeData(colorScheme: lightColorScheme),
|
||||||
|
darkTheme: ThemeData(colorScheme: darkColorScheme),
|
||||||
|
themeMode: _metadataRepository.getSettings().themeMode,
|
||||||
|
initialRoute: '/home',
|
||||||
|
routes: {
|
||||||
|
'/home':(context) => const HomePage(),
|
||||||
|
},
|
||||||
|
localizationsDelegates: const [
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate
|
||||||
|
],
|
||||||
|
supportedLocales: const [
|
||||||
|
Locale('fr')
|
||||||
|
],
|
||||||
|
);
|
||||||
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
class StorageClient {
|
class JsonStorageClient {
|
||||||
|
|
||||||
save(String filename, String data) async {
|
save(String filename, String data) async {
|
||||||
File file = await _getJson(filename);
|
File file = await _getJson(filename);
|
||||||
await file.writeAsString(data);
|
await file.writeAsString(data);
|
||||||
@@ -19,11 +20,17 @@ class StorageClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<File> _getJson(String filename) async {
|
Future<File> _getJson(String filename) async {
|
||||||
final dir = await getApplicationDocumentsDirectory();
|
final rootDirectory = Platform.isAndroid ? await getExternalStorageDirectory() : await getApplicationDocumentsDirectory();
|
||||||
final file = File('${dir.path}/$filename');
|
|
||||||
if (!file.existsSync()) {
|
final appDirectory = Directory('${rootDirectory!.path}/krezus');
|
||||||
file.createSync();
|
if (!appDirectory.existsSync()) {
|
||||||
|
appDirectory.createSync();
|
||||||
}
|
}
|
||||||
return file;
|
|
||||||
|
final targetFile = File('${rootDirectory.path}/krezus/$filename');
|
||||||
|
if (!targetFile.existsSync()) {
|
||||||
|
targetFile.createSync();
|
||||||
|
}
|
||||||
|
return targetFile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,11 +5,11 @@ import 'package:csv/csv.dart';
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
part 'account_event.dart';
|
part 'account_event.dart';
|
||||||
@@ -55,6 +55,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
on<AccountEditLabel>(_onAccountEditLabel);
|
on<AccountEditLabel>(_onAccountEditLabel);
|
||||||
on<AccountEditSaving>(_onAccountEditSaving);
|
on<AccountEditSaving>(_onAccountEditSaving);
|
||||||
on<AccountEditColor>(_onAccountEditColor);
|
on<AccountEditColor>(_onAccountEditColor);
|
||||||
|
on<ClearData>(_onClearData);
|
||||||
|
|
||||||
_metadataRepository
|
_metadataRepository
|
||||||
.getAccountsStream()
|
.getAccountsStream()
|
||||||
@@ -74,7 +75,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onAccountImportCSV(AccountImportCSV event, Emitter<AccountState> emit) async {
|
_onAccountImportCSV(AccountImportCSV event, Emitter<AccountState> emit) async {
|
||||||
int colorIndex = 0;
|
// int colorIndex = 0;
|
||||||
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||||
|
|
||||||
final csvPath = result?.files.first.path;
|
final csvPath = result?.files.first.path;
|
||||||
@@ -123,13 +124,13 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
await _metadataRepository.deleteMetadata();
|
_metadataRepository.deleteMetadata();
|
||||||
await _transactionsRepository.deleteTransactions();
|
_transactionsRepository.deleteTransactions();
|
||||||
|
|
||||||
await _metadataRepository.saveAccounts(accounts.values.toList());
|
_metadataRepository.saveAccounts(accounts.values.toList());
|
||||||
await _metadataRepository.saveBudgets([]);
|
_metadataRepository.saveBudgets([]);
|
||||||
await _metadataRepository.saveCategories(categoriesMap.values.toList());
|
_metadataRepository.saveCategories(categoriesMap.values.toList());
|
||||||
await _transactionsRepository.saveTransactions(transactions);
|
_transactionsRepository.saveTransactions(transactions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +142,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAccountAdd(AccountAdd event, Emitter<AccountState> emit) async {
|
_onAccountAdd(AccountAdd event, Emitter<AccountState> emit) {
|
||||||
String uuid = const Uuid().v8();
|
String uuid = const Uuid().v8();
|
||||||
Account account = Account(
|
Account account = Account(
|
||||||
label: 'Account $uuid',
|
label: 'Account $uuid',
|
||||||
@@ -149,11 +150,11 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
saving: false
|
saving: false
|
||||||
);
|
);
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(await _saveAccount(account))
|
state.copyWith(_saveAccount(account))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAcountRemove(AccountRemove event, Emitter<AccountState> emit) async {
|
_onAcountRemove(AccountRemove event, Emitter<AccountState> emit) {
|
||||||
Account accountToRemove = event.account;
|
Account accountToRemove = event.account;
|
||||||
List<Account> accounts = state.accounts;
|
List<Account> accounts = state.accounts;
|
||||||
List<Transaction> transactions = _transactionsRepository.getTransactions();
|
List<Transaction> transactions = _transactionsRepository.getTransactions();
|
||||||
@@ -165,36 +166,33 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
accounts.removeWhere((account) => account.label == accountToRemove.label);
|
accounts.removeWhere((account) => account.label == accountToRemove.label);
|
||||||
emit(AccountRemoveSucess());
|
emit(AccountRemoveSucess());
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(await _metadataRepository.saveAccounts(accounts))
|
state.copyWith(_metadataRepository.saveAccounts(accounts))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAccountEditLabel(AccountEditLabel event, Emitter<AccountState> emit) async {
|
_onAccountEditLabel(AccountEditLabel event, Emitter<AccountState> emit) {
|
||||||
Account account = event.account;
|
// Account account = event.account;
|
||||||
account.label = event.label;
|
// TODO check for existance, rename every transaction
|
||||||
emit(
|
|
||||||
state.copyWith(await _saveAccount(account))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAccountEditSaving(AccountEditSaving event, Emitter<AccountState> emit) async {
|
_onAccountEditSaving(AccountEditSaving event, Emitter<AccountState> emit) {
|
||||||
Account account = event.account;
|
Account account = event.account;
|
||||||
account.saving = event.saving;
|
account.saving = event.saving;
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(await _saveAccount(account))
|
state.copyWith(_saveAccount(account))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAccountEditColor(AccountEditColor event, Emitter<AccountState> emit) async {
|
_onAccountEditColor(AccountEditColor event, Emitter<AccountState> emit) {
|
||||||
Account account = event.account;
|
Account account = event.account;
|
||||||
account.color = event.color;
|
account.color = event.color;
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(await _saveAccount(account))
|
state.copyWith(_saveAccount(account))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Account>> _saveAccount(Account accountToSave) async {
|
List<Account> _saveAccount(Account accountToSave) {
|
||||||
List<Account> accounts = _metadataRepository.getAccounts();
|
List<Account> accounts = _metadataRepository.getAccounts();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -202,10 +200,19 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
|||||||
accountFound.color = accountToSave.color;
|
accountFound.color = accountToSave.color;
|
||||||
accountFound.saving = accountToSave.saving;
|
accountFound.saving = accountToSave.saving;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
accounts.add(accountToSave);
|
if (accounts.isEmpty) {
|
||||||
|
accounts = [accountToSave];
|
||||||
|
} else {
|
||||||
|
accounts.add(accountToSave);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _metadataRepository.saveAccounts(accounts);
|
_metadataRepository.saveAccounts(accounts);
|
||||||
return accounts;
|
return accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onClearData(ClearData event, Emitter<AccountState> emit) {
|
||||||
|
_metadataRepository.deleteMetadata();
|
||||||
|
_transactionsRepository.deleteTransactions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ sealed class AccountEvent extends Equatable {
|
|||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class ClearData extends AccountEvent {
|
||||||
|
const ClearData();
|
||||||
|
}
|
||||||
|
|
||||||
final class AccountImportCSV extends AccountEvent {
|
final class AccountImportCSV extends AccountEvent {
|
||||||
const AccountImportCSV();
|
const AccountImportCSV();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,241 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
|
|
||||||
part 'budget_event.dart';
|
part 'budget_event.dart';
|
||||||
part 'budget_state.dart';
|
part 'budget_state.dart';
|
||||||
|
|
||||||
class BudgetBloc extends Bloc<BudgetEvent, BudgetState> {
|
class BudgetBloc extends Bloc<BudgetEvent, BudgetState> {
|
||||||
final MetadataRepository _metadataRepository;
|
final MetadataRepository _metadataRepository;
|
||||||
|
final TransactionsRepository _transactionsRepository;
|
||||||
|
Timer? setValueTimer;
|
||||||
|
|
||||||
BudgetBloc({required MetadataRepository metadataRepository}) : _metadataRepository = metadataRepository, super(const BudgetState()) {
|
BudgetBloc({required MetadataRepository metadataRepository, required TransactionsRepository transactionsRepository}) : _metadataRepository = metadataRepository, _transactionsRepository = transactionsRepository, super(const BudgetState()) {
|
||||||
on<BudgetsLoad>(_onBudgetsLoad);
|
on<BudgetsLoad>(_onBudgetsLoad);
|
||||||
|
on<BudgetAdd>(_onBudgetAdd);
|
||||||
|
on<BudgetRemove>(_onBudgetRemove);
|
||||||
|
on<BudgetSetValue>(_onBudgetSetValue);
|
||||||
|
on<BudgetSetLabel>(_onBudgetSetLabel);
|
||||||
|
on<BudgetCompareNext>(_onBudgetCompareNext);
|
||||||
|
on<BudgetComparePrevious>(_onBudgetComparePrevious);
|
||||||
|
on<BudgetSetCompare>(_onBudgetSetCompare);
|
||||||
|
on<BudgetSetInitial>(_onBudgetSetInitial);
|
||||||
|
|
||||||
_metadataRepository
|
_metadataRepository
|
||||||
.getBudgetsStream()
|
.getBudgetsStream()
|
||||||
.listen((budgets) => add(BudgetsLoad(budgets)));
|
.listen((budgets) => add(BudgetsLoad(budgets)));
|
||||||
|
|
||||||
|
_transactionsRepository
|
||||||
|
.getTransactionsStream()
|
||||||
|
.listen((transactions) => add(BudgetSetCompare()));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onBudgetsLoad(
|
_onBudgetsLoad(
|
||||||
BudgetsLoad event, Emitter<BudgetState> emit
|
BudgetsLoad event, Emitter<BudgetState> emit
|
||||||
) {
|
) {
|
||||||
|
emit(_computeState(event.budgets, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onBudgetAdd(BudgetAdd event, Emitter<BudgetState> emit) {
|
||||||
|
Budget budget = Budget(
|
||||||
|
label: event.label,
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Budget> budgets = _computeBudgets(budget);
|
||||||
|
_saveBudget(budgets);
|
||||||
|
emit(_computeState(budgets, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onBudgetRemove(BudgetRemove event, Emitter<BudgetState> emit) {
|
||||||
|
List<Budget> budgets = _metadataRepository.getBudgets();
|
||||||
|
Budget budgetToRemove = event.budget;
|
||||||
|
|
||||||
|
budgets.removeWhere((budget) => budget.label == budgetToRemove.label);
|
||||||
|
emit(_computeState(_metadataRepository.saveBudgets(budgets), null));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onBudgetSetValue(BudgetSetValue event, Emitter<BudgetState> emit) {
|
||||||
|
Budget budgetToUpdate = event.budget;
|
||||||
|
double newValue = event.value;
|
||||||
|
|
||||||
|
if (state.remainingBudget - (event.value - budgetToUpdate.value) < 0) {
|
||||||
|
newValue = event.budget.value + state.remainingBudget;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (state.remainingBudget - event.value < 0 && state.remainingBudget < 10) {
|
||||||
|
// budgetToUpdate.value =
|
||||||
|
// } else {
|
||||||
|
// budgetToUpdate.value = event.value;
|
||||||
|
// }
|
||||||
|
budgetToUpdate.value = newValue;
|
||||||
|
List<Budget> budgets = _computeBudgets(budgetToUpdate);
|
||||||
|
emit(_computeState(budgets, null));
|
||||||
|
|
||||||
|
setValueTimer?.cancel();
|
||||||
|
setValueTimer = Timer(
|
||||||
|
const Duration(milliseconds: 100),
|
||||||
|
() {
|
||||||
|
_saveBudget(budgets);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onBudgetSetLabel(BudgetSetLabel event, Emitter<BudgetState> emit) {
|
||||||
|
Budget budgetToUpdate = event.budget;
|
||||||
|
|
||||||
|
budgetToUpdate.label = event.label;
|
||||||
|
List<Budget> budgets = _computeBudgets(budgetToUpdate);
|
||||||
|
_saveBudget(budgets);
|
||||||
|
emit(_computeState(budgets, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onBudgetCompareNext(BudgetCompareNext event, Emitter<BudgetState> emit) {
|
||||||
|
num compareMonth = state.compareMonth;
|
||||||
|
num compareYear = state.compareYear;
|
||||||
|
if (state.compareMonth == 12) {
|
||||||
|
compareMonth = 1;
|
||||||
|
compareYear++;
|
||||||
|
} else {
|
||||||
|
compareMonth++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.lastDate != null && state.lastDate!.isBefore(DateTime(compareYear.toInt(), compareMonth.toInt()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final compareResult = _computeCompareBudget(state.budgets, compareYear, compareMonth);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
budgets: event.budgets,
|
compareBudgets: compareResult.$1,
|
||||||
|
otherBudgets: compareResult.$2,
|
||||||
|
compareMonth: compareMonth,
|
||||||
|
compareYear: compareYear,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onBudgetComparePrevious(BudgetComparePrevious event, Emitter<BudgetState> emit) {
|
||||||
|
num compareMonth = state.compareMonth;
|
||||||
|
num compareYear = state.compareYear;
|
||||||
|
if (state.compareMonth == 1) {
|
||||||
|
compareMonth = 12;
|
||||||
|
compareYear--;
|
||||||
|
} else {
|
||||||
|
compareMonth--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.firstDate != null && state.firstDate!.isAfter(DateTime(compareYear.toInt(), compareMonth.toInt()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final compareResult = _computeCompareBudget(state.budgets, compareYear, compareMonth);
|
||||||
|
emit(state.copyWith(
|
||||||
|
compareBudgets: compareResult.$1,
|
||||||
|
otherBudgets: compareResult.$2,
|
||||||
|
compareMonth: compareMonth,
|
||||||
|
compareYear: compareYear,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
_onBudgetSetCompare(BudgetSetCompare event, Emitter<BudgetState> emit) {
|
||||||
|
DateTime firstDate = DateTime.now();
|
||||||
|
DateTime lastDate = DateTime.fromMicrosecondsSinceEpoch(0);
|
||||||
|
|
||||||
|
for (var transaction in _transactionsRepository.getTransactions()) {
|
||||||
|
if (firstDate.compareTo(transaction.date) > 0) {
|
||||||
|
firstDate = transaction.date;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastDate.compareTo(transaction.date) < 0) {
|
||||||
|
lastDate = transaction.date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num compareMonth = state.compareMonth;
|
||||||
|
num compareYear = state.compareYear;
|
||||||
|
|
||||||
|
if (compareMonth == 1 && compareYear == 2000) {
|
||||||
|
compareMonth = lastDate.month;
|
||||||
|
compareYear = lastDate.year;
|
||||||
|
}
|
||||||
|
|
||||||
|
final compareResult = _computeCompareBudget(state.budgets, compareYear, compareMonth);
|
||||||
|
emit(state.copyWith(
|
||||||
|
firstDate: firstDate,
|
||||||
|
lastDate: lastDate,
|
||||||
|
compareMonth: compareMonth,
|
||||||
|
compareYear: compareYear,
|
||||||
|
compareBudgets: compareResult.$1,
|
||||||
|
otherBudgets: compareResult.$2,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onBudgetSetInitial(BudgetSetInitial event, Emitter<BudgetState> emit) {
|
||||||
|
emit(_computeState(state.budgets, event.value));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Budget> _computeBudgets(Budget budgetToSave) {
|
||||||
|
List<Budget> budgets = _metadataRepository.getBudgets();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Budget budgetFound = budgets.firstWhere((category) => category.label == budgetToSave.label);
|
||||||
|
budgetFound.value = budgetToSave.value;
|
||||||
|
} catch (e) {
|
||||||
|
if (budgets.isEmpty) {
|
||||||
|
budgets = [budgetToSave];
|
||||||
|
} else {
|
||||||
|
budgets.add(budgetToSave);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return budgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Budget> _saveBudget(List<Budget> budgets) {
|
||||||
|
return _metadataRepository.saveBudgets(budgets);
|
||||||
|
}
|
||||||
|
|
||||||
|
(List<Budget> compareBudgets, List<Budget> otherBudgets) _computeCompareBudget(List<Budget> budgets, num year, num month) {
|
||||||
|
Map<String, Budget> compareBudgetMap = { for (var budget in budgets) budget.label : Budget(label: budget.label)};
|
||||||
|
Budget otherBudget = Budget(label: 'Hors budget');
|
||||||
|
Map<String, Budget> otherBudgetMap = {};
|
||||||
|
List<Budget> compareBudgets = [];
|
||||||
|
_transactionsRepository.getTransactions()
|
||||||
|
.where((transaction) => transaction.value < 0 && transaction.date.year == year && transaction.date.month == month)
|
||||||
|
.forEach((transaction) {
|
||||||
|
Budget? budget = compareBudgetMap[transaction.category];
|
||||||
|
if (budget == null) {
|
||||||
|
otherBudget.value += transaction.value.abs();
|
||||||
|
Budget? otherBudgetFromMap = otherBudgetMap[transaction.category];
|
||||||
|
if (otherBudgetFromMap == null) {
|
||||||
|
otherBudgetMap[transaction.category] = Budget(label: transaction.category, value: transaction.value.abs());
|
||||||
|
} else {
|
||||||
|
otherBudgetFromMap.value += transaction.value.abs();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
budget.value += transaction.value.abs();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
compareBudgets.addAll(compareBudgetMap.values);
|
||||||
|
compareBudgets.add(otherBudget);
|
||||||
|
return (compareBudgets, otherBudgetMap.values.toList()..sort((a, b) => b.value.compareTo(a.value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
BudgetState _computeState(List<Budget> budgets, double? initialBudget) {
|
||||||
|
final compareResult = _computeCompareBudget(state.budgets, state.compareYear, state.compareMonth);
|
||||||
|
|
||||||
|
final budgetValues = budgets.map((budget) => budget.value);
|
||||||
|
final budgetReducedValues = budgetValues.isEmpty ? 0 : budgetValues.reduce((value, element) => value + element);
|
||||||
|
|
||||||
|
return state.copyWith(
|
||||||
|
budgets: budgets,
|
||||||
|
initialBudget: (initialBudget ?? state.initialBudget),
|
||||||
|
remainingBudget: (initialBudget ?? state.initialBudget) - budgetReducedValues,
|
||||||
|
compareBudgets: compareResult.$1,
|
||||||
|
otherBudgets: compareResult.$2,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -14,3 +14,53 @@ final class BudgetsLoad extends BudgetEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [budgets];
|
List<Object> get props => [budgets];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class BudgetAdd extends BudgetEvent {
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const BudgetAdd(this.label);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [label];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class BudgetRemove extends BudgetEvent {
|
||||||
|
final Budget budget;
|
||||||
|
|
||||||
|
const BudgetRemove(this.budget);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [budget];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class BudgetSetValue extends BudgetEvent {
|
||||||
|
final Budget budget;
|
||||||
|
final double value;
|
||||||
|
|
||||||
|
const BudgetSetValue(this.budget, this.value);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [budget, value];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class BudgetSetLabel extends BudgetEvent {
|
||||||
|
final Budget budget;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const BudgetSetLabel(this.budget, this.label);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [budget, label];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class BudgetCompareNext extends BudgetEvent {}
|
||||||
|
final class BudgetComparePrevious extends BudgetEvent {}
|
||||||
|
final class BudgetSetCompare extends BudgetEvent {}
|
||||||
|
final class BudgetSetInitial extends BudgetEvent {
|
||||||
|
final double value;
|
||||||
|
|
||||||
|
const BudgetSetInitial(this.value);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [value];
|
||||||
|
}
|
||||||
@@ -1,20 +1,50 @@
|
|||||||
part of 'budget_bloc.dart';
|
part of 'budget_bloc.dart';
|
||||||
|
|
||||||
final class BudgetState extends Equatable {
|
final class BudgetState {
|
||||||
final List<Budget> budgets;
|
final List<Budget> budgets;
|
||||||
|
final double initialBudget;
|
||||||
|
final double remainingBudget;
|
||||||
|
|
||||||
|
final List<Budget> compareBudgets;
|
||||||
|
final List<Budget> otherBudgets;
|
||||||
|
final num compareYear;
|
||||||
|
final num compareMonth;
|
||||||
|
final DateTime? firstDate;
|
||||||
|
final DateTime? lastDate;
|
||||||
|
|
||||||
const BudgetState({
|
const BudgetState({
|
||||||
this.budgets = const [],
|
this.budgets = const [],
|
||||||
|
this.initialBudget = 2300.0,
|
||||||
|
this.remainingBudget = 2300.0,
|
||||||
|
this.compareBudgets = const [],
|
||||||
|
this.otherBudgets = const [],
|
||||||
|
this.compareYear = 2000,
|
||||||
|
this.compareMonth = 1,
|
||||||
|
this.firstDate,
|
||||||
|
this.lastDate,
|
||||||
});
|
});
|
||||||
|
|
||||||
BudgetState copyWith({
|
BudgetState copyWith({
|
||||||
List<Budget>? budgets,
|
List<Budget>? budgets,
|
||||||
|
double? initialBudget,
|
||||||
|
double? remainingBudget,
|
||||||
|
List<Budget>? compareBudgets,
|
||||||
|
List<Budget>? otherBudgets,
|
||||||
|
num? compareYear,
|
||||||
|
num? compareMonth,
|
||||||
|
DateTime? firstDate,
|
||||||
|
DateTime? lastDate,
|
||||||
}) {
|
}) {
|
||||||
return BudgetState(
|
return BudgetState(
|
||||||
budgets: budgets ?? this.budgets,
|
budgets: budgets ?? this.budgets,
|
||||||
|
initialBudget: initialBudget ?? this.initialBudget,
|
||||||
|
remainingBudget: remainingBudget ?? this.remainingBudget,
|
||||||
|
compareBudgets: compareBudgets ?? this.compareBudgets,
|
||||||
|
otherBudgets: otherBudgets ?? this.otherBudgets,
|
||||||
|
compareYear: compareYear ?? this.compareYear,
|
||||||
|
compareMonth: compareMonth ?? this.compareMonth,
|
||||||
|
firstDate: firstDate ?? this.firstDate,
|
||||||
|
lastDate: lastDate ?? this.lastDate,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [budgets];
|
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,35 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
part 'category_event.dart';
|
part 'category_event.dart';
|
||||||
part 'category_state.dart';
|
part 'category_state.dart';
|
||||||
|
|
||||||
class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||||
final MetadataRepository _metadataRepository;
|
final MetadataRepository _metadataRepository;
|
||||||
|
final TransactionsRepository _transactionsRepository;
|
||||||
|
|
||||||
CategoryBloc({required MetadataRepository metadataRepository}) : _metadataRepository = metadataRepository, super(const CategoryState()) {
|
CategoryBloc({
|
||||||
|
required MetadataRepository metadataRepository,
|
||||||
|
required TransactionsRepository transactionsRepository,
|
||||||
|
})
|
||||||
|
: _metadataRepository = metadataRepository,
|
||||||
|
_transactionsRepository = transactionsRepository,
|
||||||
|
super(const CategoryState()) {
|
||||||
on<CategoriesLoad>(_onCategoriesLoad);
|
on<CategoriesLoad>(_onCategoriesLoad);
|
||||||
|
on<CategoryEditColor>(_onCategoryEditColor);
|
||||||
|
on<CategoryEditTransfert>(_onCategoryEditTransfert);
|
||||||
|
on<CategoryEditEssential>(_onCategoryEditEssential);
|
||||||
|
on<CategoryEditLabel>(_onCategoryEditLabel);
|
||||||
|
on<CategoryRemove>(_onCategoryRemove);
|
||||||
|
on<CategoryAdd>(_onCategoryAdd);
|
||||||
|
|
||||||
_metadataRepository
|
_metadataRepository
|
||||||
.getCategoriesStream()
|
.getCategoriesStream()
|
||||||
@@ -22,9 +39,81 @@ class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
|||||||
_onCategoriesLoad(
|
_onCategoriesLoad(
|
||||||
CategoriesLoad event, Emitter<CategoryState> emit
|
CategoriesLoad event, Emitter<CategoryState> emit
|
||||||
) {
|
) {
|
||||||
emit(state.copyWith(
|
emit(_computeState(event.categories));
|
||||||
categories: event.categories,
|
}
|
||||||
categoriesColors: { for (var category in event.categories) category.label : category.rgbToColor() }
|
|
||||||
));
|
FutureOr<void> _onCategoryEditColor(CategoryEditColor event, Emitter<CategoryState> emit) {
|
||||||
|
Category category = event.category;
|
||||||
|
category.color = event.color;
|
||||||
|
emit(_computeState(_saveCategory(category)));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onCategoryEditTransfert(CategoryEditTransfert event, Emitter<CategoryState> emit) {
|
||||||
|
Category category = event.category;
|
||||||
|
category.transfert = event.transfert;
|
||||||
|
emit(_computeState(_saveCategory(category)));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onCategoryEditEssential(CategoryEditEssential event, Emitter<CategoryState> emit) {
|
||||||
|
Category category = event.category;
|
||||||
|
category.essential = event.essential;
|
||||||
|
emit(_computeState(_saveCategory(category)));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onCategoryEditLabel(CategoryEditLabel event, Emitter<CategoryState> emit) {
|
||||||
|
// TODO check for existance, rename every transaction
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onCategoryRemove(CategoryRemove event, Emitter<CategoryState> emit) {
|
||||||
|
CategoryState originalCategoryState = state.copyWith();
|
||||||
|
Category categoryToRemove = event.category;
|
||||||
|
List<Category> categories = state.categories;
|
||||||
|
List<Transaction> transactions = _transactionsRepository.getTransactions();
|
||||||
|
|
||||||
|
if (transactions.any((transaction) => transaction.category == categoryToRemove.label)) {
|
||||||
|
emit(CategoryRemoveFail());
|
||||||
|
emit(originalCategoryState);
|
||||||
|
} else {
|
||||||
|
categories.removeWhere((category) => category.label == categoryToRemove.label);
|
||||||
|
emit(CategoryRemoveSucess());
|
||||||
|
emit(_computeState(_metadataRepository.saveCategories(categories)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onCategoryAdd(CategoryAdd event, Emitter<CategoryState> emit) {
|
||||||
|
String uuid = const Uuid().v8();
|
||||||
|
Category category = Category(
|
||||||
|
label: 'Category $uuid',
|
||||||
|
color: 'FF74feff',
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(_computeState(_saveCategory(category)));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Category> _saveCategory(Category categoryToSave) {
|
||||||
|
List<Category> categories = _metadataRepository.getCategories();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Category categoryFound = categories.firstWhere((category) => category.label == categoryToSave.label);
|
||||||
|
categoryFound.color = categoryToSave.color;
|
||||||
|
categoryFound.essential = categoryToSave.essential;
|
||||||
|
categoryFound.transfert = categoryToSave.transfert;
|
||||||
|
} catch (e) {
|
||||||
|
if (categories.isEmpty) {
|
||||||
|
categories = [categoryToSave];
|
||||||
|
} else {
|
||||||
|
categories.add(categoryToSave);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_metadataRepository.saveCategories(categories);
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
CategoryState _computeState(List<Category> categories) {
|
||||||
|
return state.copyWith(
|
||||||
|
categories: categories,
|
||||||
|
categoriesColors: { for (var category in categories) category.label : category.rgbToColor() }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,3 +14,54 @@ final class CategoriesLoad extends CategoryEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [categories];
|
List<Object> get props => [categories];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class CategoryEditColor extends CategoryEvent {
|
||||||
|
final Category category;
|
||||||
|
final String color;
|
||||||
|
|
||||||
|
const CategoryEditColor(this.category, this.color);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [category, color];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CategoryEditTransfert extends CategoryEvent {
|
||||||
|
final Category category;
|
||||||
|
final bool transfert;
|
||||||
|
|
||||||
|
const CategoryEditTransfert(this.category, this.transfert);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [category, transfert];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CategoryEditEssential extends CategoryEvent {
|
||||||
|
final Category category;
|
||||||
|
final bool essential;
|
||||||
|
|
||||||
|
const CategoryEditEssential(this.category, this.essential);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [category, essential];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CategoryEditLabel extends CategoryEvent {
|
||||||
|
final Category category;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const CategoryEditLabel(this.category, this.label);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [category, label];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CategoryRemove extends CategoryEvent {
|
||||||
|
final Category category;
|
||||||
|
|
||||||
|
const CategoryRemove(this.category);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [category];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CategoryAdd extends CategoryEvent {}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
part of 'category_bloc.dart';
|
part of 'category_bloc.dart';
|
||||||
|
|
||||||
final class CategoryState extends Equatable {
|
final class CategoryState {
|
||||||
final List<Category> categories;
|
final List<Category> categories;
|
||||||
final Map<String, Color> categoriesColors;
|
final Map<String, Color> categoriesColors;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ final class CategoryState extends Equatable {
|
|||||||
categoriesColors: categoriesColors ?? this.categoriesColors,
|
categoriesColors: categoriesColors ?? this.categoriesColors,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [categories, categoriesColors];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class CategoryRemoveFail extends CategoryState {}
|
||||||
|
final class CategoryRemoveSucess extends CategoryState {}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:fl_chart/fl_chart.dart';
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/charts/models/month_totals.dart';
|
import 'package:krezus/domains/charts/models/month_totals.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_line.dart';
|
import 'package:krezus/domains/transaction/models/transaction_line.dart';
|
||||||
import 'package:tunas/domains/charts/models/chart_item.dart';
|
import 'package:krezus/domains/charts/models/chart_item.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
|
|
||||||
part 'chart_event.dart';
|
part 'chart_event.dart';
|
||||||
part 'chart_state.dart';
|
part 'chart_state.dart';
|
||||||
@@ -95,6 +95,8 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
|||||||
categoriesTotals[transaction.category] = categoryTotal;
|
categoriesTotals[transaction.category] = categoryTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accountsTotals.removeWhere((key, value) => value.round() == 0);
|
||||||
|
|
||||||
return _computeStateScopedStats(state.copyWith(
|
return _computeStateScopedStats(state.copyWith(
|
||||||
transactionsLines: transactionsLines,
|
transactionsLines: transactionsLines,
|
||||||
globalTotal: globalTotal,
|
globalTotal: globalTotal,
|
||||||
@@ -113,7 +115,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
|||||||
double scoppedTotal = 0;
|
double scoppedTotal = 0;
|
||||||
List<ChartItem> scopedCategoriesPositiveTotals = [];
|
List<ChartItem> scopedCategoriesPositiveTotals = [];
|
||||||
List<ChartItem> scopedCategoriesNegativeTotals = [];
|
List<ChartItem> scopedCategoriesNegativeTotals = [];
|
||||||
Map<int, FlSpot> scopedMonthlyTotals = {};
|
Map<int, FlSpot> scopedMonthlyTotalsMap = {};
|
||||||
Map<int, MonthTotals> scopedCategoriesMonthlyTotals = {};
|
Map<int, MonthTotals> scopedCategoriesMonthlyTotals = {};
|
||||||
|
|
||||||
Map<int, double> scopedMonthlyPostitiveTotals = {};
|
Map<int, double> scopedMonthlyPostitiveTotals = {};
|
||||||
@@ -134,7 +136,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
|||||||
DateTime transactionDate = transactionLine.transaction.date;
|
DateTime transactionDate = transactionLine.transaction.date;
|
||||||
int transactionDateDay = transactionDate.difference(DateTime(transactionDate.year,1,1)).inDays + 1;
|
int transactionDateDay = transactionDate.difference(DateTime(transactionDate.year,1,1)).inDays + 1;
|
||||||
|
|
||||||
scopedMonthlyTotals[transactionDateDay] = FlSpot(transactionDateDay.toDouble(), transactionLine.subTotal);
|
scopedMonthlyTotalsMap[transactionDateDay] = FlSpot(transactionDateDay.toDouble(), transactionLine.subTotal);
|
||||||
|
|
||||||
final category = state.categories[transaction.category];
|
final category = state.categories[transaction.category];
|
||||||
if (category == null || category.transfert) {
|
if (category == null || category.transfert) {
|
||||||
@@ -229,6 +231,9 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
|||||||
_sortMapByValues(monthTotals.negatives);
|
_sortMapByValues(monthTotals.negatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<FlSpot> scopedMonthlyTotals = scopedMonthlyTotalsMap.values.toList();
|
||||||
|
scopedMonthlyTotals.sort((a, b) => a.x.compareTo(b.x));
|
||||||
|
|
||||||
return state.copyWith(
|
return state.copyWith(
|
||||||
scoppedProfit: scoppedTotal,
|
scoppedProfit: scoppedTotal,
|
||||||
scopedCategoriesPositiveTotals: scopedCategoriesPositiveTotals,
|
scopedCategoriesPositiveTotals: scopedCategoriesPositiveTotals,
|
||||||
@@ -239,7 +244,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
|||||||
scopedSimplifiedCategoriesPositiveTotalsPercents: scopedSimplifiedCategoriesPositiveTotalsPercents,
|
scopedSimplifiedCategoriesPositiveTotalsPercents: scopedSimplifiedCategoriesPositiveTotalsPercents,
|
||||||
scopedSimplifiedCategoriesNegativeTotals: scopedSimplifiedCategoriesNegativeTotals,
|
scopedSimplifiedCategoriesNegativeTotals: scopedSimplifiedCategoriesNegativeTotals,
|
||||||
scopedSimplifiedCategoriesNegativeTotalsPercents: scopedSimplifiedCategoriesNegativeTotalsPercents,
|
scopedSimplifiedCategoriesNegativeTotalsPercents: scopedSimplifiedCategoriesNegativeTotalsPercents,
|
||||||
scopedMonthlyTotals: scopedMonthlyTotals.values.toList(),
|
scopedMonthlyTotals: scopedMonthlyTotals,
|
||||||
scopedCategoriesMonthlyTotals: scopedCategoriesMonthlyTotals,
|
scopedCategoriesMonthlyTotals: scopedCategoriesMonthlyTotals,
|
||||||
scopedMonthlyPostitiveTotals: scopedMonthlyPostitiveTotals,
|
scopedMonthlyPostitiveTotals: scopedMonthlyPostitiveTotals,
|
||||||
scopedMonthlyNegativeTotals: scopedMonthlyNegativeTotals,
|
scopedMonthlyNegativeTotals: scopedMonthlyNegativeTotals,
|
||||||
|
|||||||
36
lib/domains/settings/settings_bloc.dart
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/settings.dart';
|
||||||
|
|
||||||
|
part 'settings_event.dart';
|
||||||
|
part 'settings_state.dart';
|
||||||
|
|
||||||
|
class SettingsBloc extends Bloc<SettingsEvent, SettingsState> {
|
||||||
|
final MetadataRepository _metadataRepository;
|
||||||
|
|
||||||
|
SettingsBloc({required MetadataRepository metadataRepository}) : _metadataRepository = metadataRepository, super(const SettingsState()) {
|
||||||
|
on<SettingsLoad>(_onSettingsLoad);
|
||||||
|
on<SetThemeMode>(_onSetThemeMode);
|
||||||
|
|
||||||
|
_metadataRepository
|
||||||
|
.getSettingsStream()
|
||||||
|
.listen((settings) => add(SettingsLoad(settings)));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onSettingsLoad(SettingsLoad event, Emitter<SettingsState> emit) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
themeMode: event.settings.themeMode,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onSetThemeMode(SetThemeMode event, Emitter<SettingsState> emit) {
|
||||||
|
_metadataRepository.saveSettings(Settings(themeMode: event.themeMode));
|
||||||
|
emit(state.copyWith(
|
||||||
|
themeMode: event.themeMode,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
20
lib/domains/settings/settings_event.dart
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
part of 'settings_bloc.dart';
|
||||||
|
|
||||||
|
sealed class SettingsEvent extends Equatable {
|
||||||
|
const SettingsEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class SettingsLoad extends SettingsEvent {
|
||||||
|
final Settings settings;
|
||||||
|
|
||||||
|
const SettingsLoad(this.settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
final class SetThemeMode extends SettingsEvent {
|
||||||
|
final ThemeMode themeMode;
|
||||||
|
|
||||||
|
const SetThemeMode(this.themeMode);
|
||||||
|
}
|
||||||
17
lib/domains/settings/settings_state.dart
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
part of 'settings_bloc.dart';
|
||||||
|
|
||||||
|
class SettingsState {
|
||||||
|
final ThemeMode themeMode;
|
||||||
|
|
||||||
|
const SettingsState({
|
||||||
|
this.themeMode = ThemeMode.system,
|
||||||
|
});
|
||||||
|
|
||||||
|
SettingsState copyWith({
|
||||||
|
ThemeMode? themeMode,
|
||||||
|
}) {
|
||||||
|
return SettingsState(
|
||||||
|
themeMode: themeMode ?? this.themeMode,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
|
||||||
class TransactionLine {
|
class TransactionLine extends Equatable{
|
||||||
Transaction transaction;
|
final Transaction transaction;
|
||||||
double subTotal;
|
final double subTotal;
|
||||||
|
|
||||||
TransactionLine({
|
const TransactionLine({
|
||||||
required this.transaction,
|
required this.transaction,
|
||||||
required this.subTotal,
|
required this.subTotal,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [transaction, subTotal];
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,18 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:formz/formz.dart';
|
import 'package:formz/formz.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_account.dart';
|
import 'package:krezus/domains/transaction/models/transaction_account.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_category.dart';
|
import 'package:krezus/domains/transaction/models/transaction_category.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_date.dart';
|
import 'package:krezus/domains/transaction/models/transaction_date.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_description.dart';
|
import 'package:krezus/domains/transaction/models/transaction_description.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_line.dart';
|
import 'package:krezus/domains/transaction/models/transaction_line.dart';
|
||||||
import 'package:tunas/domains/transaction/models/transaction_value.dart';
|
import 'package:krezus/domains/transaction/models/transaction_value.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
part 'transaction_event.dart';
|
part 'transaction_event.dart';
|
||||||
@@ -33,18 +36,20 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
||||||
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
||||||
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
||||||
|
on<TransactionFilterAccount>(_onTransactionFilterAccount);
|
||||||
|
on<TransactionResetSnackBar>(_onTransactionResetSnackBar);
|
||||||
|
|
||||||
_transactionsRepository
|
_transactionsRepository
|
||||||
.getTransactionsStream()
|
.getTransactionsStream()
|
||||||
.listen((transactions) => add(TransactionsLoad(transactions)));
|
.listen((transactions) => add(TransactionsLoad(transactions)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onAccountLoad(TransactionsLoad event, Emitter<TransactionState> emit) {
|
FutureOr<void> _onAccountLoad(TransactionsLoad event, Emitter<TransactionState> emit) {
|
||||||
var computeResult = _computeTransactionLine(event.transactions);
|
var computeResult = _computeTransactionLine(event.transactions);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
transactions: event.transactions,
|
transactions: event.transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
));
|
));
|
||||||
@@ -73,7 +78,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
return (list: output, globalTotal: globalTotal, accountsTotals: accountsTotals, categories: categories.toList());
|
return (list: output, globalTotal: globalTotal, accountsTotals: accountsTotals, categories: categories.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionDateChange(
|
FutureOr<void> _onTransactionDateChange(
|
||||||
TransactionDateChange event, Emitter<TransactionState> emit
|
TransactionDateChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionDate = TransactionDate.dirty(event.date);
|
final transactionDate = TransactionDate.dirty(event.date);
|
||||||
@@ -83,7 +88,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionCategoryChange(
|
FutureOr<void> _onTransactionCategoryChange(
|
||||||
TransactionCategoryChange event, Emitter<TransactionState> emit
|
TransactionCategoryChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionCategory = TransactionCategory.dirty(event.category);
|
final transactionCategory = TransactionCategory.dirty(event.category);
|
||||||
@@ -93,7 +98,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionDescriptionChange(
|
FutureOr<void> _onTransactionDescriptionChange(
|
||||||
TransactionDescriptionChange event, Emitter<TransactionState> emit
|
TransactionDescriptionChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionDescription = TransactionDescription.dirty(event.description);
|
final transactionDescription = TransactionDescription.dirty(event.description);
|
||||||
@@ -103,7 +108,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionAccountChange(
|
FutureOr<void> _onTransactionAccountChange(
|
||||||
TransactionAccountChange event, Emitter<TransactionState> emit
|
TransactionAccountChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
final transactionAccount = TransactionAccount.dirty(event.account);
|
final transactionAccount = TransactionAccount.dirty(event.account);
|
||||||
@@ -113,7 +118,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionValueChange(
|
FutureOr<void> _onTransactionValueChange(
|
||||||
TransactionValueChange event, Emitter<TransactionState> emit
|
TransactionValueChange event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
@@ -131,21 +136,21 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionOpenAddDialog(
|
FutureOr<void> _onTransactionOpenAddDialog(
|
||||||
TransactionOpenAddDialog event, Emitter<TransactionState> emit
|
TransactionOpenAddDialog event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
emit(state.copyWith(showAddDialog: true));
|
emit(state.copyWith(showAddDialog: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionHideAddDialog(
|
FutureOr<void> _onTransactionHideAddDialog(
|
||||||
TransactionHideAddDialog event, Emitter<TransactionState> emit
|
TransactionHideAddDialog event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
emit(state.copyWith(showAddDialog: false));
|
emit(state.copyWith(showAddDialog: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionAddDialog(
|
FutureOr<void> _onTransactionAddDialog(
|
||||||
TransactionAdd event, Emitter<TransactionState> emit
|
TransactionAdd event, Emitter<TransactionState> emit
|
||||||
) async {
|
) {
|
||||||
if (state.isValid) {
|
if (state.isValid) {
|
||||||
List<Transaction> transactions = state.transactions;
|
List<Transaction> transactions = state.transactions;
|
||||||
Transaction? currentTransaction = state.currentTransaction;
|
Transaction? currentTransaction = state.currentTransaction;
|
||||||
@@ -163,25 +168,28 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
));
|
));
|
||||||
final computeResult = _computeTransactionLine(transactions);
|
final computeResult = _computeTransactionLine(transactions);
|
||||||
|
|
||||||
await _transactionsRepository.saveTransactions(transactions);
|
_transactionsRepository.saveTransactions(transactions);
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
currentTransaction: null,
|
currentTransaction: null,
|
||||||
transactionDate: const TransactionDate.pure(),
|
// transactionDate: const TransactionDate.pure(),
|
||||||
transactionCategory: const TransactionCategory.pure(),
|
// transactionCategory: const TransactionCategory.pure(),
|
||||||
transactionDescription: const TransactionDescription.pure(),
|
// transactionDescription: const TransactionDescription.pure(),
|
||||||
transactionAccount: const TransactionAccount.pure(),
|
// transactionAccount: const TransactionAccount.pure(),
|
||||||
transactionValue: const TransactionValue.pure(),
|
// transactionValue: const TransactionValue.pure(),
|
||||||
transactions: transactions,
|
transactions: transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
|
showSnackBar: true,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: 'Transaction ${currentTransaction == null ? 'added' : 'updated'} !',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionSetCurrent(
|
FutureOr<void> _onTransactionSetCurrent(
|
||||||
TransactionSetCurrent event, Emitter<TransactionState> emit
|
TransactionSetCurrent event, Emitter<TransactionState> emit
|
||||||
) {
|
) {
|
||||||
Transaction? transaction = event.transaction;
|
Transaction? transaction = event.transaction;
|
||||||
@@ -206,15 +214,15 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransactionDeleteCurrent(
|
FutureOr<void> _onTransactionDeleteCurrent(
|
||||||
TransactionDeleteCurrent event, Emitter<TransactionState> emit
|
TransactionDeleteCurrent event, Emitter<TransactionState> emit
|
||||||
) async {
|
) {
|
||||||
Transaction? currentTransaction = state.currentTransaction;
|
Transaction? currentTransaction = state.currentTransaction;
|
||||||
if (currentTransaction != null) {
|
if (currentTransaction != null) {
|
||||||
List<Transaction> transactions = state.transactions;
|
List<Transaction> transactions = state.transactions;
|
||||||
transactions.removeWhere((transaction) => transaction.uuid == currentTransaction.uuid);
|
transactions.removeWhere((transaction) => transaction.uuid == currentTransaction.uuid);
|
||||||
final computeResult = _computeTransactionLine(transactions);
|
final computeResult = _computeTransactionLine(transactions);
|
||||||
await _transactionsRepository.saveTransactions(transactions);
|
_transactionsRepository.saveTransactions(transactions);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
currentTransaction: null,
|
currentTransaction: null,
|
||||||
transactionDate: const TransactionDate.pure(),
|
transactionDate: const TransactionDate.pure(),
|
||||||
@@ -224,33 +232,83 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
|||||||
transactionValue: const TransactionValue.pure(),
|
transactionValue: const TransactionValue.pure(),
|
||||||
transactions: transactions,
|
transactions: transactions,
|
||||||
transactionsLines: computeResult.list,
|
transactionsLines: computeResult.list,
|
||||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||||
globalTotal: computeResult.globalTotal,
|
globalTotal: computeResult.globalTotal,
|
||||||
accountsTotals: computeResult.accountsTotals,
|
accountsTotals: computeResult.accountsTotals,
|
||||||
|
showSnackBar: true,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: 'Transaction removed !',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onTransactionFilterCategory(TransactionFilterCategory event, Emitter<TransactionState> emit) {
|
||||||
_onTransactionFilterCategory(TransactionFilterCategory event, Emitter<TransactionState> emit) {
|
emit(TransactionState(
|
||||||
List<TransactionLine> transactionsLinesFiltered = state.transactionsLines;
|
globalTotal: state.globalTotal,
|
||||||
String? categoryLabel = event.category?.label;
|
accountsTotals: state.accountsTotals,
|
||||||
if (categoryLabel != null) {
|
transactions: state.transactions,
|
||||||
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
transactionsLines: state.transactionsLines,
|
||||||
}
|
transactionsLinesFiltered: state.transactionsLinesFiltered,
|
||||||
|
transactionDate: state.transactionDate,
|
||||||
|
transactionCategory: state.transactionCategory,
|
||||||
|
transactionDescription: state.transactionDescription,
|
||||||
|
transactionAccount: state.transactionAccount,
|
||||||
|
transactionValue: state.transactionValue,
|
||||||
|
isValid: state.isValid,
|
||||||
|
showAddDialog: state.showAddDialog,
|
||||||
|
currentTransaction: state.currentTransaction,
|
||||||
|
categoryFilter: event.category,
|
||||||
|
accountFilter: state.accountFilter,
|
||||||
|
));
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
transactionsLinesFiltered: transactionsLinesFiltered,
|
transactionsLinesFiltered: _applyFilters(state.transactionsLines),
|
||||||
categoryFilter: event.category,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TransactionLine> _applyCategoryFilter(List<TransactionLine> transactionsLines) {
|
FutureOr<void> _onTransactionFilterAccount(TransactionFilterAccount event, Emitter<TransactionState> emit) {
|
||||||
|
emit(TransactionState(
|
||||||
|
globalTotal: state.globalTotal,
|
||||||
|
accountsTotals: state.accountsTotals,
|
||||||
|
transactions: state.transactions,
|
||||||
|
transactionsLines: state.transactionsLines,
|
||||||
|
transactionsLinesFiltered: state.transactionsLinesFiltered,
|
||||||
|
transactionDate: state.transactionDate,
|
||||||
|
transactionCategory: state.transactionCategory,
|
||||||
|
transactionDescription: state.transactionDescription,
|
||||||
|
transactionAccount: state.transactionAccount,
|
||||||
|
transactionValue: state.transactionValue,
|
||||||
|
isValid: state.isValid,
|
||||||
|
showAddDialog: state.showAddDialog,
|
||||||
|
currentTransaction: state.currentTransaction,
|
||||||
|
categoryFilter: state.categoryFilter,
|
||||||
|
accountFilter: event.account,
|
||||||
|
));
|
||||||
|
emit(state.copyWith(
|
||||||
|
transactionsLinesFiltered: _applyFilters(state.transactionsLines),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TransactionLine> _applyFilters(List<TransactionLine> transactionsLines) {
|
||||||
List<TransactionLine> transactionsLinesFiltered = transactionsLines;
|
List<TransactionLine> transactionsLinesFiltered = transactionsLines;
|
||||||
String? categoryLabel = state.categoryFilter?.label;
|
String? categoryLabel = state.categoryFilter?.label;
|
||||||
if (categoryLabel != null) {
|
if (categoryLabel != null) {
|
||||||
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
transactionsLinesFiltered = transactionsLinesFiltered.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? accountLabel = state.accountFilter?.label;
|
||||||
|
if (accountLabel != null) {
|
||||||
|
transactionsLinesFiltered = transactionsLinesFiltered.where((transaction) => transaction.transaction.account == accountLabel).toList();
|
||||||
|
}
|
||||||
|
|
||||||
return transactionsLinesFiltered;
|
return transactionsLinesFiltered;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onTransactionResetSnackBar(TransactionResetSnackBar event, Emitter<TransactionState> emit) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
showSnackBar: false,
|
||||||
|
snackBarIsError: false,
|
||||||
|
snackBarMessage: '',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -78,3 +78,13 @@ final class TransactionFilterCategory extends TransactionEvent {
|
|||||||
|
|
||||||
const TransactionFilterCategory(this.category);
|
const TransactionFilterCategory(this.category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final class TransactionFilterAccount extends TransactionEvent {
|
||||||
|
final Account? account;
|
||||||
|
|
||||||
|
const TransactionFilterAccount(this.account);
|
||||||
|
}
|
||||||
|
|
||||||
|
final class TransactionResetSnackBar extends TransactionEvent {
|
||||||
|
const TransactionResetSnackBar();
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ final class TransactionState extends Equatable {
|
|||||||
final List<TransactionLine> transactionsLines;
|
final List<TransactionLine> transactionsLines;
|
||||||
final List<TransactionLine> transactionsLinesFiltered;
|
final List<TransactionLine> transactionsLinesFiltered;
|
||||||
final Category? categoryFilter;
|
final Category? categoryFilter;
|
||||||
|
final Account? accountFilter;
|
||||||
|
|
||||||
final TransactionDate transactionDate;
|
final TransactionDate transactionDate;
|
||||||
final TransactionCategory transactionCategory;
|
final TransactionCategory transactionCategory;
|
||||||
@@ -19,6 +20,10 @@ final class TransactionState extends Equatable {
|
|||||||
|
|
||||||
final Transaction? currentTransaction;
|
final Transaction? currentTransaction;
|
||||||
|
|
||||||
|
final bool showSnackBar;
|
||||||
|
final String snackBarMessage;
|
||||||
|
final bool snackBarIsError;
|
||||||
|
|
||||||
const TransactionState({
|
const TransactionState({
|
||||||
this.globalTotal = 0,
|
this.globalTotal = 0,
|
||||||
this.accountsTotals = const <String, double>{},
|
this.accountsTotals = const <String, double>{},
|
||||||
@@ -34,6 +39,10 @@ final class TransactionState extends Equatable {
|
|||||||
this.showAddDialog = false,
|
this.showAddDialog = false,
|
||||||
this.currentTransaction,
|
this.currentTransaction,
|
||||||
this.categoryFilter,
|
this.categoryFilter,
|
||||||
|
this.accountFilter,
|
||||||
|
this.showSnackBar = false,
|
||||||
|
this.snackBarMessage = '',
|
||||||
|
this.snackBarIsError = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
TransactionState copyWith({
|
TransactionState copyWith({
|
||||||
@@ -51,6 +60,10 @@ final class TransactionState extends Equatable {
|
|||||||
bool? showAddDialog,
|
bool? showAddDialog,
|
||||||
Transaction? currentTransaction,
|
Transaction? currentTransaction,
|
||||||
Category? categoryFilter,
|
Category? categoryFilter,
|
||||||
|
Account? accountFilter,
|
||||||
|
bool? showSnackBar,
|
||||||
|
String? snackBarMessage,
|
||||||
|
bool? snackBarIsError,
|
||||||
}) {
|
}) {
|
||||||
return TransactionState(
|
return TransactionState(
|
||||||
globalTotal: globalTotal ?? this.globalTotal,
|
globalTotal: globalTotal ?? this.globalTotal,
|
||||||
@@ -66,12 +79,19 @@ final class TransactionState extends Equatable {
|
|||||||
isValid: isValid ?? this.isValid,
|
isValid: isValid ?? this.isValid,
|
||||||
showAddDialog: showAddDialog ?? this.showAddDialog,
|
showAddDialog: showAddDialog ?? this.showAddDialog,
|
||||||
currentTransaction: currentTransaction ?? this.currentTransaction,
|
currentTransaction: currentTransaction ?? this.currentTransaction,
|
||||||
categoryFilter: categoryFilter,
|
categoryFilter: categoryFilter ?? this.categoryFilter,
|
||||||
|
accountFilter: accountFilter ?? this.accountFilter,
|
||||||
|
showSnackBar: showSnackBar ?? this.showSnackBar,
|
||||||
|
snackBarMessage: snackBarMessage ?? this.snackBarMessage,
|
||||||
|
snackBarIsError: snackBarIsError ?? this.snackBarIsError,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
|
transactions,
|
||||||
|
transactionsLines,
|
||||||
|
transactionsLinesFiltered,
|
||||||
transactionDate,
|
transactionDate,
|
||||||
transactionCategory,
|
transactionCategory,
|
||||||
transactionDescription,
|
transactionDescription,
|
||||||
@@ -81,6 +101,10 @@ final class TransactionState extends Equatable {
|
|||||||
showAddDialog,
|
showAddDialog,
|
||||||
currentTransaction,
|
currentTransaction,
|
||||||
categoryFilter,
|
categoryFilter,
|
||||||
|
accountFilter,
|
||||||
|
showSnackBar,
|
||||||
|
snackBarMessage,
|
||||||
|
snackBarIsError,
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/date_symbol_data_local.dart';
|
import 'package:intl/date_symbol_data_local.dart';
|
||||||
import 'package:tunas/app.dart';
|
import 'package:krezus/app.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
initializeDateFormatting('fr_FR', null);
|
initializeDateFormatting('fr_FR', null);
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tunas/pages/budgets/widgets/budgets_actions.dart';
|
import 'package:krezus/pages/budgets/widgets/budgets_actions.dart';
|
||||||
import 'package:tunas/pages/budgets/widgets/month_distribution.dart';
|
import 'package:krezus/pages/budgets/widgets/month_distribution.dart';
|
||||||
|
|
||||||
class BudgetsPage extends StatelessWidget {
|
class BudgetsPage extends StatelessWidget {
|
||||||
const BudgetsPage({super.key});
|
const BudgetsPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||||
return Center(
|
return Center(
|
||||||
child: ConstrainedBox(
|
child: Container(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
maxWidth: 1000
|
maxWidth: 1000,
|
||||||
),
|
),
|
||||||
child: const Column(
|
child: ListView(
|
||||||
children: [
|
padding: mediaQuery.padding.copyWith(left: 10.0, right: 10.0, bottom: 100.0),
|
||||||
|
children: const [
|
||||||
BudgetsActions(),
|
BudgetsActions(),
|
||||||
MonthDistribution()
|
MonthDistribution()
|
||||||
],
|
]
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
124
lib/pages/budgets/widgets/budget_cards.dart
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
|
|
||||||
|
class BudgetCards extends StatelessWidget {
|
||||||
|
const BudgetCards({super.key});
|
||||||
|
|
||||||
|
List<Widget> _computeBudgetsCompare(BuildContext context, List<Budget> targetBudgets, List<Budget> realBudgets) {
|
||||||
|
List<Widget> list = [
|
||||||
|
const Text('Budget'),
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.only(bottom: 10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
width: 2,
|
||||||
|
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
list.addAll(targetBudgets.map((budget) => Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Container(width: 5),
|
||||||
|
Text(budget.label),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'${NumberFormat("#00").format(budget.value.abs())}/${NumberFormat("#00 €").format(realBudgets.firstWhere((rbudget) => rbudget.label == budget.label).value.abs())}',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: 'NovaMono',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _computeOtherBudgets(BuildContext context, List<Budget> otherBudgets) {
|
||||||
|
List<Widget> list = [
|
||||||
|
const Text('Hors budget'),
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.only(bottom: 10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
width: 2,
|
||||||
|
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
list.addAll(otherBudgets.map((budget) => Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Container(width: 5),
|
||||||
|
Text(budget.label),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
NumberFormat("#00 €").format(budget.value.abs()),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: 'NovaMono',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => Column(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: smallVerticalScreen ? null : 300,
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
color: Theme.of(context).colorScheme.secondaryContainer
|
||||||
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.vertical,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: _computeBudgetsCompare(context, state.budgets, state.compareBudgets),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: smallVerticalScreen ? null : 300,
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
color: Theme.of(context).colorScheme.secondaryContainer
|
||||||
|
),
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.vertical,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: _computeOtherBudgets(context, state.otherBudgets),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
lib/pages/budgets/widgets/budget_comparator.dart
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/pages/budgets/widgets/budget_cards.dart';
|
||||||
|
import 'package:krezus/pages/budgets/widgets/budget_compare_selector.dart';
|
||||||
|
import 'package:krezus/pages/budgets/widgets/budget_radar.dart';
|
||||||
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
|
||||||
|
class BudgetComparator extends StatelessWidget {
|
||||||
|
const BudgetComparator({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => TitledContainer(
|
||||||
|
title: 'Compare',
|
||||||
|
child: smallVerticalScreen
|
||||||
|
? const Column(
|
||||||
|
children: [
|
||||||
|
BudgetCompareSelector(),
|
||||||
|
SizedBox(
|
||||||
|
height: 500,
|
||||||
|
child: BudgetRadar(),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 500,
|
||||||
|
child: BudgetCards(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: const Column(
|
||||||
|
children: [
|
||||||
|
BudgetCompareSelector(),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
BudgetCards(),
|
||||||
|
BudgetRadar(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
28
lib/pages/budgets/widgets/budget_compare_selector.dart
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
|
||||||
|
class BudgetCompareSelector extends StatelessWidget {
|
||||||
|
const BudgetCompareSelector({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetComparePrevious()),
|
||||||
|
icon: const Icon(Icons.skip_previous)
|
||||||
|
),
|
||||||
|
Text('${NumberFormat('00', 'fr_FR').format(state.compareMonth)} - ${state.compareYear}'),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetCompareNext()),
|
||||||
|
icon: const Icon(Icons.skip_next)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
124
lib/pages/budgets/widgets/budget_line.dart
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
|
|
||||||
|
class BudgetLine extends StatelessWidget {
|
||||||
|
final Budget budget;
|
||||||
|
|
||||||
|
const BudgetLine({super.key, required this.budget});
|
||||||
|
|
||||||
|
Widget _largeScreenLine(BuildContext context, List<Category> categories, double initialBudget, double remainingBudget) {
|
||||||
|
return Row (
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: DropdownButtonFormField<String>(
|
||||||
|
value: budget.label,
|
||||||
|
onChanged: (value) => context.read<BudgetBloc>().add(BudgetSetLabel(budget, value!)),
|
||||||
|
items: categories.map((e) => DropdownMenuItem(value: e.label, child: Text(e.label))).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 30),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetSetValue(budget, budget.value.round().toDouble() - 1)),
|
||||||
|
icon: const Icon(Icons.remove_circle)
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
NumberFormat('####000 €', 'fr_FR').format(budget.value),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: 'NovaMono',
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 15,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetSetValue(budget, budget.value.round().toDouble() + 1)),
|
||||||
|
icon: const Icon(Icons.add_circle)
|
||||||
|
),
|
||||||
|
const SizedBox(width: 5),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Slider(
|
||||||
|
min: 0,
|
||||||
|
max: initialBudget,
|
||||||
|
label: budget.value.round().toString(),
|
||||||
|
value: budget.value,
|
||||||
|
secondaryTrackValue: remainingBudget + budget.value,
|
||||||
|
onChanged: (value) => context.read<BudgetBloc>().add(BudgetSetValue(budget, value.round().toDouble())),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetRemove(budget)),
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _smallScreenLine(BuildContext context, List<Category> categories, double initialBudget, double remainingBudget) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: DropdownButtonFormField<String>(
|
||||||
|
value: budget.label,
|
||||||
|
onChanged: (value) => context.read<BudgetBloc>().add(BudgetSetLabel(budget, value!)),
|
||||||
|
items: categories.map((e) => DropdownMenuItem(value: e.label, child: Text(e.label))).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 30),
|
||||||
|
Text(
|
||||||
|
NumberFormat('####000 €', 'fr_FR').format(budget.value),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: 'NovaMono',
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 15,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetSetValue(budget, budget.value.round().toDouble() - 1)),
|
||||||
|
icon: const Icon(Icons.remove_circle)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetSetValue(budget, budget.value.round().toDouble() + 1)),
|
||||||
|
icon: const Icon(Icons.add_circle)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetRemove(budget)),
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Slider(
|
||||||
|
min: 0,
|
||||||
|
max: initialBudget,
|
||||||
|
label: budget.value.round().toString(),
|
||||||
|
value: budget.value,
|
||||||
|
secondaryTrackValue: remainingBudget + budget.value,
|
||||||
|
onChanged: (value) => context.read<BudgetBloc>().add(BudgetSetValue(budget, value.round().toDouble())),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final categoryState = context.watch<CategoryBloc>().state;
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => smallVerticalScreen
|
||||||
|
? _smallScreenLine(context, categoryState.categories, state.initialBudget, state.remainingBudget)
|
||||||
|
: _largeScreenLine(context, categoryState.categories, state.initialBudget, state.remainingBudget),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
91
lib/pages/budgets/widgets/budget_maker.dart
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
|
import 'package:krezus/pages/budgets/widgets/budget_line.dart';
|
||||||
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
|
|
||||||
|
class BudgetMaker extends StatelessWidget {
|
||||||
|
const BudgetMaker({super.key});
|
||||||
|
|
||||||
|
List<Widget> _computeBudgetLines(BuildContext context, List<Budget> budgets, double initialBudget, double remainingBudget) {
|
||||||
|
List<Widget> list = [];
|
||||||
|
|
||||||
|
list.add(
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.only(top: 5, bottom: 5),
|
||||||
|
padding: const EdgeInsets.only(bottom: 10),
|
||||||
|
child: Flex(
|
||||||
|
direction: Axis.horizontal,
|
||||||
|
children: [Expanded(
|
||||||
|
child:
|
||||||
|
TextFormField(
|
||||||
|
keyboardType: const TextInputType.numberWithOptions(decimal: false),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
icon: const Icon(Icons.euro),
|
||||||
|
label: const Text('Revenu par mois'),
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
initialValue: initialBudget.toString(),
|
||||||
|
onChanged: (value) => context.read<BudgetBloc>().add(BudgetSetInitial(double.parse(value)))
|
||||||
|
)
|
||||||
|
|
||||||
|
)]
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
list.addAll(budgets.map((budget) => BudgetLine(budget: budget)).toList());
|
||||||
|
|
||||||
|
list.add(
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.only(top: 25, bottom: 5),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
width: 2,
|
||||||
|
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
list.add(
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${NumberFormat('#####00 €', 'fr_FR').format(remainingBudget)} remaining ',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontFamily: 'NovaMono',
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 15,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final categoryState = context.watch<CategoryBloc>().state;
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => TitledContainer(
|
||||||
|
title: 'Prepare',
|
||||||
|
action: IconButton(
|
||||||
|
onPressed: () => context.read<BudgetBloc>().add(BudgetAdd(categoryState.categories.first.label)),
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: _computeBudgetLines(context, state.budgets, state.initialBudget, state.remainingBudget),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
lib/pages/budgets/widgets/budget_projection.dart
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
|
||||||
|
class BudgetProjection extends StatelessWidget {
|
||||||
|
const BudgetProjection({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => TitledContainer(
|
||||||
|
title: 'Projection',
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
|
||||||
|
],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
lib/pages/budgets/widgets/budget_radar.dart
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import 'package:fl_chart/fl_chart.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
|
|
||||||
|
class BudgetRadar extends StatelessWidget {
|
||||||
|
const BudgetRadar({super.key});
|
||||||
|
|
||||||
|
List<RadarDataSet> _computeDataSet(BuildContext context, List<Budget> targetBudgets, List<Budget> realBudgets) {
|
||||||
|
if (realBudgets.isEmpty || targetBudgets.isEmpty) {
|
||||||
|
return [RadarDataSet(dataEntries: [const RadarEntry(value: 1), const RadarEntry(value: 2), const RadarEntry(value: 3)])];
|
||||||
|
}
|
||||||
|
|
||||||
|
RadarDataSet targetDataSet = RadarDataSet(
|
||||||
|
fillColor: Theme.of(context).colorScheme.primary.withAlpha(100),
|
||||||
|
borderColor: Theme.of(context).colorScheme.primary,
|
||||||
|
entryRadius: 5,
|
||||||
|
dataEntries: targetBudgets.map((budget) => RadarEntry(value: budget.value)).toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (realBudgets.isNotEmpty) {
|
||||||
|
targetDataSet.dataEntries.add(const RadarEntry(value: 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
RadarDataSet realDataSet = RadarDataSet(
|
||||||
|
fillColor: Theme.of(context).colorScheme.onPrimary.withAlpha(100),
|
||||||
|
borderColor: Theme.of(context).colorScheme.onPrimary,
|
||||||
|
entryRadius: 8,
|
||||||
|
dataEntries: realBudgets.map((budget) => RadarEntry(value: budget.value)).toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
return [realDataSet, targetDataSet];
|
||||||
|
}
|
||||||
|
|
||||||
|
RadarChartTitle _computeDataSetTitle(int index, List<Budget> realBudgets) {
|
||||||
|
return RadarChartTitle(text: realBudgets[index].label);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool canShowData(List<Budget> targetBudgets, List<Budget> realBudgets) {
|
||||||
|
return realBudgets.length >= 3 && targetBudgets.length >= 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
|
builder: (context, state) => canShowData(state.budgets, state.compareBudgets) ? Expanded(
|
||||||
|
child: AspectRatio(
|
||||||
|
aspectRatio: 1.3,
|
||||||
|
child: RadarChart(
|
||||||
|
RadarChartData(
|
||||||
|
titlePositionPercentageOffset: 0.15,
|
||||||
|
tickBorderData: BorderSide(color: Theme.of(context).colorScheme.secondary, width: 1),
|
||||||
|
gridBorderData: BorderSide(color: Theme.of(context).colorScheme.secondary, width: 2),
|
||||||
|
radarBorderData: BorderSide(color: Theme.of(context).colorScheme.secondary, width: 3),
|
||||||
|
radarBackgroundColor: Theme.of(context).colorScheme.secondaryContainer.withAlpha(100),
|
||||||
|
radarShape: RadarShape.circle,
|
||||||
|
dataSets: _computeDataSet(context, state.budgets, state.compareBudgets),
|
||||||
|
getTitle: (index, angle) => _computeDataSetTitle(index, state.compareBudgets),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: const Text('No data to show'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
|
|
||||||
class BudgetsActions extends StatelessWidget {
|
class BudgetsActions extends StatelessWidget {
|
||||||
const BudgetsActions({super.key});
|
const BudgetsActions({super.key});
|
||||||
@@ -9,24 +9,18 @@ class BudgetsActions extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<AccountBloc, AccountState>(
|
return BlocBuilder<AccountBloc, AccountState>(
|
||||||
builder: (context, state) => Container(
|
builder: (context, state) => Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 0),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 0),
|
||||||
child: Row(
|
child: const Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
Text(
|
||||||
'Budgets',
|
'Budgets',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w900,
|
fontWeight: FontWeight.w900,
|
||||||
fontSize: 35,
|
fontSize: 35,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
|
||||||
onPressed: () => null,
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.add
|
|
||||||
)
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,73 +1,22 @@
|
|||||||
import 'package:fl_chart/fl_chart.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tunas/pages/common/titled_container.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
|
import 'package:krezus/pages/budgets/widgets/budget_comparator.dart';
|
||||||
|
import 'package:krezus/pages/budgets/widgets/budget_maker.dart';
|
||||||
|
|
||||||
class MonthDistribution extends StatelessWidget {
|
class MonthDistribution extends StatelessWidget {
|
||||||
const MonthDistribution({super.key});
|
const MonthDistribution({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
|
||||||
children: [
|
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||||
TitledContainer(
|
builder: (context, state) => const Column(
|
||||||
title: 'Prepare',
|
children: [
|
||||||
child: Column(
|
BudgetMaker(),
|
||||||
children: [
|
BudgetComparator(),
|
||||||
Text('Money to spare: 2300 €'),
|
],
|
||||||
Text('Loyer'),
|
)
|
||||||
Slider(
|
|
||||||
min: 0,
|
|
||||||
max: 2300,
|
|
||||||
value: 200,
|
|
||||||
onChanged: (value) => {},
|
|
||||||
),
|
|
||||||
Text('Loyer'),
|
|
||||||
Slider(
|
|
||||||
min: 0,
|
|
||||||
max: 2300,
|
|
||||||
value: 200,
|
|
||||||
onChanged: (value) => {},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
TitledContainer(
|
|
||||||
title: 'Compare',
|
|
||||||
height: 500,
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text('Budget'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
IconButton(
|
|
||||||
onPressed: () => {},
|
|
||||||
icon: const Icon(Icons.skip_previous)
|
|
||||||
),
|
|
||||||
Text('Fev 2024'),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () => {},
|
|
||||||
icon: const Icon(Icons.skip_next)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
100
lib/pages/common/editable_color.dart
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class EditableColor extends StatelessWidget {
|
||||||
|
final Color color;
|
||||||
|
final ValueChanged<Color>? onChanged;
|
||||||
|
|
||||||
|
const EditableColor({super.key, required this.color, this.onChanged});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return IconButton(
|
||||||
|
onPressed: () => EditableColorDialog.show(context, color, onChanged),
|
||||||
|
icon: const Icon(Icons.palette),
|
||||||
|
color: color,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditableColorDialog extends StatefulWidget {
|
||||||
|
final Color initialColor;
|
||||||
|
final ValueChanged<Color>? onChanged;
|
||||||
|
|
||||||
|
const EditableColorDialog({super.key, required this.initialColor, this.onChanged});
|
||||||
|
|
||||||
|
static void show(BuildContext context, Color color, ValueChanged<Color>? onChanged) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
useRootNavigator: false,
|
||||||
|
builder: (context) => EditableColorDialog(initialColor: color, onChanged: onChanged)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hide(BuildContext context) => Navigator.pop(context);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<EditableColorDialog> createState() => _EditableColorDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EditableColorDialogState extends State<EditableColorDialog> {
|
||||||
|
Color? color;
|
||||||
|
|
||||||
|
List<Widget> _buildColorList() {
|
||||||
|
return colors.map((color) => IconButton(
|
||||||
|
onPressed: () => setState(() => this.color = color),
|
||||||
|
icon: Icon(
|
||||||
|
color.value == this.color?.value ? Icons.radio_button_checked : Icons.radio_button_off,
|
||||||
|
color: color,
|
||||||
|
)
|
||||||
|
)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
color ??= widget.initialColor;
|
||||||
|
return AlertDialog(
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => EditableColorDialog.hide(context),
|
||||||
|
icon: const Icon(Icons.close)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
EditableColorDialog.hide(context);
|
||||||
|
if (color != null && widget.onChanged != null) {
|
||||||
|
widget.onChanged!(color!);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.save)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
title: const Text('Edit color'),
|
||||||
|
content: Row(
|
||||||
|
children: _buildColorList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const List<Color> colors = [
|
||||||
|
Colors.black,
|
||||||
|
Colors.white,
|
||||||
|
Colors.red,
|
||||||
|
Colors.pink,
|
||||||
|
Colors.purple,
|
||||||
|
Colors.indigo,
|
||||||
|
Colors.blue,
|
||||||
|
Colors.lightBlue,
|
||||||
|
Colors.cyan,
|
||||||
|
Colors.teal,
|
||||||
|
Colors.green,
|
||||||
|
Colors.lime,
|
||||||
|
Colors.yellow,
|
||||||
|
Colors.amber,
|
||||||
|
Colors.orange,
|
||||||
|
Colors.deepOrange,
|
||||||
|
Colors.brown,
|
||||||
|
Colors.grey,
|
||||||
|
Colors.blueGrey,
|
||||||
|
];
|
||||||
74
lib/pages/common/editable_label.dart
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class EditableLabel extends StatefulWidget {
|
||||||
|
final String initialValue;
|
||||||
|
final String? hintText;
|
||||||
|
final ValueChanged<String>? onChanged;
|
||||||
|
final TextInputType? keyboardType;
|
||||||
|
|
||||||
|
const EditableLabel({super.key, required this.initialValue, this.onChanged, this.hintText, this.keyboardType});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<EditableLabel> createState() => _EditableLabelState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EditableLabelState extends State<EditableLabel> {
|
||||||
|
bool editMode = false;
|
||||||
|
String? value;
|
||||||
|
|
||||||
|
Widget _editMode() {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
child: TextFormField(
|
||||||
|
keyboardType: widget.keyboardType,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: widget.hintText,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
initialValue: widget.initialValue,
|
||||||
|
onChanged: (value) => this.value = value,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => setState(() {
|
||||||
|
editMode = !editMode;
|
||||||
|
}),
|
||||||
|
icon: const Icon(Icons.close),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => setState(() {
|
||||||
|
editMode = !editMode;
|
||||||
|
if (value != null && widget.onChanged != null) {
|
||||||
|
widget.onChanged!(value!);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
icon: const Icon(Icons.save),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _readMode() {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Text(widget.initialValue),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => setState(() {
|
||||||
|
editMode = !editMode;
|
||||||
|
}),
|
||||||
|
icon: const Icon(Icons.edit),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return editMode ? _editMode() : _readMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,15 +35,6 @@ class TitledContainer extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Theme.of(context).colorScheme.shadow,
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(2, 2),
|
|
||||||
spreadRadius: 0.1,
|
|
||||||
blurStyle: BlurStyle.normal,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 0),
|
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 0),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -56,7 +47,12 @@ class TitledContainer extends StatelessWidget {
|
|||||||
Container(
|
Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
|
borderRadius: const BorderRadius.only(topLeft: Radius.circular(14), topRight: Radius.circular(15)),
|
||||||
|
border: Border(
|
||||||
|
bottom: BorderSide(
|
||||||
|
color: Theme.of(context).colorScheme.onSecondaryContainer,
|
||||||
|
)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 15),
|
||||||
child: _computeTitleRow()
|
child: _computeTitleRow()
|
||||||
|
|||||||
@@ -1,41 +1,37 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tunas/pages/data/widgets/account_settings.dart';
|
import 'package:krezus/pages/data/widgets/account_settings.dart';
|
||||||
import 'package:tunas/pages/data/widgets/categories_settings.dart';
|
import 'package:krezus/pages/data/widgets/categories_settings.dart';
|
||||||
import 'package:tunas/pages/data/widgets/import_settings.dart';
|
import 'package:krezus/pages/data/widgets/import_settings.dart';
|
||||||
|
import 'package:krezus/pages/data/widgets/settings_settings.dart';
|
||||||
|
|
||||||
class DataPage extends StatelessWidget {
|
class DataPage extends StatelessWidget {
|
||||||
const DataPage({super.key});
|
const DataPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||||
return Center(
|
return Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 11, horizontal: 0),
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
maxWidth: 1000
|
maxWidth: 1000
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
child: ListView(
|
||||||
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
padding: mediaQuery.padding.copyWith(left: 10.0, right: 10.0, bottom: 100.0),
|
||||||
child: Column(
|
children: const [
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Text(
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'Settings',
|
'Settings',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w900,
|
fontWeight: FontWeight.w900,
|
||||||
fontSize: 35,
|
fontSize: 35,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
SettingsSettings(),
|
||||||
child: ListView(
|
ImportSettings(),
|
||||||
children: const [
|
AccountSettings(),
|
||||||
ImportSettings(),
|
CategoriesSettings(),
|
||||||
CategoriesSettings(),
|
|
||||||
AccountSettings(),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
import 'package:tunas/pages/common/titled_container.dart';
|
import 'package:krezus/pages/common/editable_color.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
import 'package:krezus/pages/common/editable_label.dart';
|
||||||
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
|
|
||||||
class AccountSettings extends StatelessWidget {
|
class AccountSettings extends StatelessWidget {
|
||||||
const AccountSettings({super.key});
|
const AccountSettings({super.key});
|
||||||
@@ -10,10 +12,9 @@ class AccountSettings extends StatelessWidget {
|
|||||||
List<Widget> _computeCategoryList(BuildContext context, List<Account> accounts) {
|
List<Widget> _computeCategoryList(BuildContext context, List<Account> accounts) {
|
||||||
return accounts.map((account) => Row(
|
return accounts.map((account) => Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
EditableColor(
|
||||||
onPressed: () {},
|
|
||||||
icon: const Icon(Icons.palette),
|
|
||||||
color: account.rgbToColor(),
|
color: account.rgbToColor(),
|
||||||
|
onChanged: (color) => context.read<AccountBloc>().add(AccountEditColor(account, color.value.toRadixString(16).toUpperCase().padLeft(8, '0'))),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => context.read<AccountBloc>().add(AccountEditSaving(account, !account.saving)),
|
onPressed: () => context.read<AccountBloc>().add(AccountEditSaving(account, !account.saving)),
|
||||||
@@ -22,11 +23,12 @@ class AccountSettings extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Container(width: 5),
|
Container(width: 5),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(account.label)
|
child: EditableLabel(
|
||||||
),
|
initialValue: account.label,
|
||||||
IconButton(
|
onChanged: (value) => context.read<AccountBloc>().add(AccountEditLabel(account, value)),
|
||||||
onPressed: () {},
|
hintText: 'Acount name',
|
||||||
icon: const Icon(Icons.edit),
|
keyboardType: TextInputType.text,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => context.read<AccountBloc>().add(AccountRemove(account)),
|
onPressed: () => context.read<AccountBloc>().add(AccountRemove(account)),
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/pages/common/titled_container.dart';
|
import 'package:krezus/pages/common/editable_color.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/pages/common/editable_label.dart';
|
||||||
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
|
|
||||||
class CategoriesSettings extends StatelessWidget {
|
class CategoriesSettings extends StatelessWidget {
|
||||||
const CategoriesSettings({super.key});
|
const CategoriesSettings({super.key});
|
||||||
@@ -10,31 +12,31 @@ class CategoriesSettings extends StatelessWidget {
|
|||||||
List<Widget> _computeCategoryList(BuildContext context, List<Category> categories) {
|
List<Widget> _computeCategoryList(BuildContext context, List<Category> categories) {
|
||||||
return categories.map((category) => Row(
|
return categories.map((category) => Row(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
EditableColor(
|
||||||
onPressed: () {},
|
|
||||||
icon: const Icon(Icons.palette),
|
|
||||||
color: category.rgbToColor(),
|
color: category.rgbToColor(),
|
||||||
|
onChanged: (color) => context.read<CategoryBloc>().add(CategoryEditColor(category, color.value.toRadixString(16).toUpperCase().padLeft(8, '0'))),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {},
|
onPressed: () => context.read<CategoryBloc>().add(CategoryEditTransfert(category, !category.transfert)),
|
||||||
icon: const Icon(Icons.swap_horiz),
|
icon: const Icon(Icons.swap_horiz),
|
||||||
color: category.transfert ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
color: category.transfert ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {},
|
onPressed: () => context.read<CategoryBloc>().add(CategoryEditEssential(category, !category.essential)),
|
||||||
icon: const Icon(Icons.foundation),
|
icon: const Icon(Icons.foundation),
|
||||||
color: category.essential ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
color: category.essential ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||||
),
|
),
|
||||||
Container(width: 5),
|
Container(width: 5),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(category.label)
|
child: EditableLabel(
|
||||||
|
initialValue: category.label,
|
||||||
|
onChanged: (value) => context.read<CategoryBloc>().add(CategoryEditLabel(category, value)),
|
||||||
|
hintText: 'Acount name',
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {},
|
onPressed: () => context.read<CategoryBloc>().add(CategoryRemove(category)),
|
||||||
icon: const Icon(Icons.edit),
|
|
||||||
),
|
|
||||||
IconButton(
|
|
||||||
onPressed: () {},
|
|
||||||
icon: const Icon(Icons.delete),
|
icon: const Icon(Icons.delete),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -43,9 +45,30 @@ class CategoriesSettings extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<CategoryBloc, CategoryState>(
|
return BlocConsumer<CategoryBloc, CategoryState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state is CategoryRemoveSucess) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
content: Text('Category succesfuly removed !'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (state is CategoryRemoveFail) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
content: Text('Cannot remove category. Still present on some transactions.'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
builder: (context, state) => TitledContainer(
|
builder: (context, state) => TitledContainer(
|
||||||
title: "Categories",
|
title: "Categories",
|
||||||
|
action: IconButton(
|
||||||
|
onPressed: () => context.read<CategoryBloc>().add(CategoryAdd()),
|
||||||
|
icon: const Icon(Icons.add),
|
||||||
|
),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
scrollDirection: Axis.vertical,
|
scrollDirection: Axis.vertical,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
import 'package:tunas/pages/common/titled_container.dart';
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
|
||||||
class ImportSettings extends StatelessWidget {
|
class ImportSettings extends StatelessWidget {
|
||||||
const ImportSettings({super.key});
|
const ImportSettings({super.key});
|
||||||
@@ -12,25 +12,36 @@ class ImportSettings extends StatelessWidget {
|
|||||||
builder: (context, state) => TitledContainer(
|
builder: (context, state) => TitledContainer(
|
||||||
title: "Import",
|
title: "Import",
|
||||||
child: Column(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
FilledButton(
|
FilledButton.icon(
|
||||||
|
onPressed: () => context.read<AccountBloc>().add(const ClearData()),
|
||||||
|
label: const Text('Clear all data'),
|
||||||
|
icon: const Icon(Icons.delete_forever),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
FilledButton.tonalIcon(
|
||||||
onPressed: () => context.read<AccountBloc>().add(const AccountImportCSV()),
|
onPressed: () => context.read<AccountBloc>().add(const AccountImportCSV()),
|
||||||
child: const Text('Import CSV')
|
label: const Text('Import CSV'),
|
||||||
|
icon: const Icon(Icons.upload_file),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
FilledButton(
|
FilledButton.tonalIcon(
|
||||||
onPressed: () => context.read<AccountBloc>().add(const AccountImportJSON()),
|
onPressed: () => context.read<AccountBloc>().add(const AccountImportJSON()),
|
||||||
child: const Text('Import JSON')
|
label: const Text('Import JSON'),
|
||||||
|
icon: const Icon(Icons.upload_file),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
FilledButton(
|
FilledButton.tonalIcon(
|
||||||
onPressed: () => context.read<AccountBloc>().add(const AccountExportCSV()),
|
onPressed: () => context.read<AccountBloc>().add(const AccountExportCSV()),
|
||||||
child: const Text('Export CSV')
|
label: const Text('Export CSV'),
|
||||||
|
icon: const Icon(Icons.download),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
FilledButton(
|
FilledButton.tonalIcon(
|
||||||
onPressed: () => context.read<AccountBloc>().add(const AccountExportJSON()),
|
onPressed: () => context.read<AccountBloc>().add(const AccountExportJSON()),
|
||||||
child: const Text('Export JSON')
|
label: const Text('Export JSON'),
|
||||||
|
icon: const Icon(Icons.download),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
39
lib/pages/data/widgets/settings_settings.dart
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/settings/settings_bloc.dart';
|
||||||
|
import 'package:krezus/pages/common/titled_container.dart';
|
||||||
|
|
||||||
|
class SettingsSettings extends StatelessWidget {
|
||||||
|
const SettingsSettings({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<SettingsBloc, SettingsState>(
|
||||||
|
builder: (context, state) => TitledContainer(
|
||||||
|
title: "Theme",
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
SegmentedButton<ThemeMode>(
|
||||||
|
segments: const [
|
||||||
|
ButtonSegment(
|
||||||
|
value: ThemeMode.system,
|
||||||
|
icon: Icon(Icons.settings)
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: ThemeMode.light,
|
||||||
|
icon: Icon(Icons.light_mode)
|
||||||
|
),
|
||||||
|
ButtonSegment(
|
||||||
|
value: ThemeMode.dark,
|
||||||
|
icon: Icon(Icons.dark_mode)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
selected: {state.themeMode},
|
||||||
|
onSelectionChanged: (themeMode) => context.read<SettingsBloc>().add(SetThemeMode(themeMode.first)),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,27 +1,102 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
import 'package:tunas/domains/budget/budget_bloc.dart';
|
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/charts/chart_bloc.dart';
|
||||||
import 'package:tunas/pages/budgets/budgets_page.dart';
|
import 'package:krezus/domains/settings/settings_bloc.dart';
|
||||||
import 'package:tunas/pages/data/data_page.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:tunas/pages/stats/stats_page.dart';
|
import 'package:krezus/pages/budgets/budgets_page.dart';
|
||||||
import 'package:tunas/pages/transactions/transactions_page.dart';
|
import 'package:krezus/pages/data/data_page.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
import 'package:krezus/pages/stats/stats_page.dart';
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
import 'package:krezus/pages/transactions/transactions_page.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||||
|
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
class HomePage extends StatelessWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
|
||||||
|
Widget _tabBar() {
|
||||||
|
return TabBar(
|
||||||
|
tabAlignment: TabAlignment.center,
|
||||||
|
splashBorderRadius: BorderRadius.circular(25),
|
||||||
|
tabs: const [
|
||||||
|
Tab(icon: Icon(Icons.insights)),
|
||||||
|
Tab(icon: Icon(Icons.receipt_long)),
|
||||||
|
Tab(icon: Icon(Icons.pie_chart)),
|
||||||
|
Tab(icon: Icon(Icons.settings)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _largeScreenTotalsCharts(BuildContext context) {
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.all(10),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
child: TabBar(
|
||||||
|
tabAlignment: TabAlignment.center,
|
||||||
|
splashBorderRadius: BorderRadius.circular(25),
|
||||||
|
tabs: const [
|
||||||
|
Tab(icon: Icon(Icons.insights)),
|
||||||
|
Tab(icon: Icon(Icons.receipt_long)),
|
||||||
|
Tab(icon: Icon(Icons.pie_chart)),
|
||||||
|
Tab(icon: Icon(Icons.settings)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _smallScreenTotalsCharts(BuildContext context) {
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.bottomCenter,
|
||||||
|
child: Container(
|
||||||
|
height: 40,
|
||||||
|
width: MediaQuery.sizeOf(context).width,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Theme.of(context).colorScheme.shadow,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: const Offset(0, -2),
|
||||||
|
spreadRadius: 0.1,
|
||||||
|
blurStyle: BlurStyle.normal,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child:TabBar(
|
||||||
|
tabAlignment: TabAlignment.center,
|
||||||
|
splashBorderRadius: BorderRadius.circular(25),
|
||||||
|
tabs: const [
|
||||||
|
Tab(icon: Icon(Icons.insights)),
|
||||||
|
Tab(icon: Icon(Icons.receipt_long)),
|
||||||
|
Tab(icon: Icon(Icons.pie_chart)),
|
||||||
|
Tab(icon: Icon(Icons.settings)),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 1500;
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(create: (context) => AccountBloc(transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context), metadataRepository: RepositoryProvider.of<MetadataRepository>(context))),
|
BlocProvider(create: (context) => AccountBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context), transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context))),
|
||||||
BlocProvider(create: (context) => TransactionBloc(transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context))),
|
BlocProvider(create: (context) => TransactionBloc(transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context))),
|
||||||
BlocProvider(create: (context) => CategoryBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context))),
|
BlocProvider(create: (context) => CategoryBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context), transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context))),
|
||||||
BlocProvider(create: (context) => BudgetBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context))),
|
BlocProvider(create: (context) => BudgetBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context), transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context))),
|
||||||
|
BlocProvider(create: (context) => ChartBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context), transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context))),
|
||||||
|
BlocProvider(create: (context) => SettingsBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context))),
|
||||||
],
|
],
|
||||||
child: DefaultTabController(
|
child: DefaultTabController(
|
||||||
length: 4,
|
length: 4,
|
||||||
@@ -36,26 +111,7 @@ class HomePage extends StatelessWidget {
|
|||||||
DataPage()
|
DataPage()
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Align(
|
smallVerticalScreen ? _smallScreenTotalsCharts(context) : _largeScreenTotalsCharts(context),
|
||||||
alignment: Alignment.bottomCenter,
|
|
||||||
child: Container(
|
|
||||||
margin: const EdgeInsets.all(15),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color.fromARGB(255, 41, 49, 56),
|
|
||||||
borderRadius: BorderRadius.circular(25)
|
|
||||||
),
|
|
||||||
child: TabBar(
|
|
||||||
tabAlignment: TabAlignment.center,
|
|
||||||
splashBorderRadius: BorderRadius.circular(25),
|
|
||||||
tabs: const [
|
|
||||||
Tab(icon: Icon(Icons.insights)),
|
|
||||||
Tab(icon: Icon(Icons.receipt_long)),
|
|
||||||
Tab(icon: Icon(Icons.pie_chart)),
|
|
||||||
Tab(icon: Icon(Icons.settings)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,86 +1,133 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/charts/chart_bloc.dart';
|
import 'package:krezus/domains/charts/chart_bloc.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/account_counters.dart';
|
import 'package:krezus/pages/stats/widgets/account_counters.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/categories_totals_chart.dart';
|
import 'package:krezus/pages/stats/widgets/categories_totals_chart.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/global_counter.dart';
|
import 'package:krezus/pages/stats/widgets/global_counter.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/monthly_categories_total_chart.dart';
|
import 'package:krezus/pages/stats/widgets/monthly_categories_total_chart.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/global_total_chart.dart';
|
import 'package:krezus/pages/stats/widgets/global_total_chart.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/profit_indicator.dart';
|
import 'package:krezus/pages/stats/widgets/profit_indicator.dart';
|
||||||
import 'package:tunas/pages/stats/widgets/year_selector.dart';
|
import 'package:krezus/pages/stats/widgets/year_selector.dart';
|
||||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
|
||||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
|
||||||
|
|
||||||
class StatsPage extends StatelessWidget {
|
class StatsPage extends StatelessWidget {
|
||||||
const StatsPage({super.key});
|
const StatsPage({super.key});
|
||||||
|
|
||||||
@override
|
Widget _largeScreenHeader(ChartState state) {
|
||||||
Widget build(BuildContext context) {
|
return Center (
|
||||||
return BlocProvider(
|
child: Container(
|
||||||
create: (context) => ChartBloc(
|
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||||
metadataRepository: RepositoryProvider.of<MetadataRepository>(context),
|
constraints: const BoxConstraints(
|
||||||
transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context),
|
maxWidth: 1000
|
||||||
),
|
),
|
||||||
child: BlocBuilder<ChartBloc, ChartState>(
|
child: Column(
|
||||||
builder: (context, state) => ListView(
|
|
||||||
children: [
|
children: [
|
||||||
Center (
|
Row(
|
||||||
child: ConstrainedBox(
|
children: [
|
||||||
constraints: const BoxConstraints(
|
Expanded(
|
||||||
maxWidth: 1000
|
flex: 2,
|
||||||
|
child: GlobalCounter(value: state.globalTotal)
|
||||||
),
|
),
|
||||||
child: Column(
|
const SizedBox(width: 10),
|
||||||
children: [
|
Expanded(
|
||||||
Row(
|
flex: 1,
|
||||||
children: [
|
child: AccountCounter(accountsTotals: state.accountsTotals)
|
||||||
Expanded(
|
|
||||||
flex: 2,
|
|
||||||
child: GlobalCounter(value: state.globalTotal)
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
flex: 1,
|
|
||||||
child: AccountCounter(accountsTotals: state.accountsTotals)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
const YearSelector(),
|
|
||||||
ProfitIndicator(profit: state.scoppedProfit)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: GlobalTotalChart(monthlyTotals: state.scopedMonthlyTotals)
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 500,
|
|
||||||
child: MonthlyCategoriesTotalChart(categoriesMonthlyTotals: state.scopedCategoriesMonthlyTotals)
|
|
||||||
),
|
|
||||||
Center (
|
|
||||||
child: ConstrainedBox(
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
maxWidth: 1500
|
|
||||||
),
|
),
|
||||||
child: SizedBox(
|
],
|
||||||
height: 450,
|
|
||||||
child: OverflowBar(
|
|
||||||
children: [
|
|
||||||
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesPositiveTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesPositiveTotalsPercents),
|
|
||||||
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesNegativeTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesNegativeTotalsPercents),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const YearSelector(),
|
||||||
|
ProfitIndicator(profit: state.scoppedProfit)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _smallScreenHeader(ChartState state) {
|
||||||
|
return Center (
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxWidth: 1000
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
GlobalCounter(value: state.globalTotal),
|
||||||
|
AccountCounter(accountsTotals: state.accountsTotals),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
ProfitIndicator(profit: state.scoppedProfit),
|
||||||
|
const YearSelector(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _largeScreenTotalsCharts(ChartState state) {
|
||||||
|
return Center (
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxWidth: 1500
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
|
height: 450,
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesPositiveTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesPositiveTotalsPercents),
|
||||||
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesNegativeTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesNegativeTotalsPercents),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _smallScreenTotalsCharts(ChartState state) {
|
||||||
|
return Center (
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxWidth: 1500
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesPositiveTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesPositiveTotalsPercents),
|
||||||
|
CategoriesTotalsChart(categoriesTotals: state.scopedCategoriesNegativeTotals, categoriesTotalsPercents: state.scopedSimplifiedCategoriesNegativeTotalsPercents),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
|
return BlocBuilder<ChartBloc, ChartState>(
|
||||||
|
builder: (context, state) => ListView(
|
||||||
|
padding: mediaQuery.padding.copyWith(bottom: 100.0),
|
||||||
|
children: [
|
||||||
|
smallVerticalScreen ? _smallScreenHeader(state) : _largeScreenHeader(state),
|
||||||
|
SizedBox(
|
||||||
|
height: smallVerticalScreen ? 100 : 200,
|
||||||
|
child: GlobalTotalChart(monthlyTotals: state.scopedMonthlyTotals)
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: smallVerticalScreen ? 200 : 500,
|
||||||
|
child: MonthlyCategoriesTotalChart(categoriesMonthlyTotals: state.scopedCategoriesMonthlyTotals)
|
||||||
|
),
|
||||||
|
smallVerticalScreen ? _smallScreenTotalsCharts(state) : _largeScreenTotalsCharts(state),
|
||||||
|
],
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,19 +31,10 @@ class AccountCounter extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
margin: const EdgeInsets.all(20),
|
margin: const EdgeInsets.only(bottom: 10),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Theme.of(context).colorScheme.shadow,
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(2, 2),
|
|
||||||
spreadRadius: 0.1,
|
|
||||||
blurStyle: BlurStyle.normal,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import 'package:fl_chart/fl_chart.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/domains/charts/models/chart_item.dart';
|
import 'package:krezus/domains/charts/models/chart_item.dart';
|
||||||
|
|
||||||
class CategoriesTotalsChart extends StatelessWidget {
|
class CategoriesTotalsChart extends StatelessWidget {
|
||||||
final List<ChartItem> categoriesTotals;
|
final List<ChartItem> categoriesTotals;
|
||||||
@@ -11,7 +11,7 @@ class CategoriesTotalsChart extends StatelessWidget {
|
|||||||
|
|
||||||
const CategoriesTotalsChart({super.key, required this.categoriesTotals, required this.categoriesTotalsPercents});
|
const CategoriesTotalsChart({super.key, required this.categoriesTotals, required this.categoriesTotalsPercents});
|
||||||
|
|
||||||
List<PieChartSectionData> _convertDataForChart(Map<String, Color> categoriesColors) {
|
List<PieChartSectionData> _convertDataForChart(Map<String, Color> categoriesColors, bool smallVerticalScreen) {
|
||||||
return categoriesTotalsPercents
|
return categoriesTotalsPercents
|
||||||
.map((item) =>
|
.map((item) =>
|
||||||
PieChartSectionData(
|
PieChartSectionData(
|
||||||
@@ -21,9 +21,10 @@ class CategoriesTotalsChart extends StatelessWidget {
|
|||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.w300
|
fontWeight: FontWeight.w300
|
||||||
),
|
),
|
||||||
|
showTitle: !smallVerticalScreen,
|
||||||
titlePositionPercentageOffset: 0.5,
|
titlePositionPercentageOffset: 0.5,
|
||||||
borderSide: const BorderSide(width: 0),
|
borderSide: const BorderSide(width: 0),
|
||||||
radius: 40,
|
radius: smallVerticalScreen ? 30 : 40,
|
||||||
color: categoriesColors[item.label]
|
color: categoriesColors[item.label]
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
@@ -60,35 +61,27 @@ class CategoriesTotalsChart extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
return BlocBuilder<CategoryBloc, CategoryState>(
|
return BlocBuilder<CategoryBloc, CategoryState>(
|
||||||
builder: (context, state) => Container(
|
builder: (context, state) => Container(
|
||||||
height: 320,
|
height: 320,
|
||||||
width: 500,
|
width: smallVerticalScreen ? null : 500,
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
margin: const EdgeInsets.all(20),
|
margin: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Theme.of(context).colorScheme.shadow,
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(2, 2),
|
|
||||||
spreadRadius: 0.1,
|
|
||||||
blurStyle: BlurStyle.normal,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PieChart(
|
child: PieChart(
|
||||||
PieChartData(
|
PieChartData(
|
||||||
sections: _convertDataForChart(state.categoriesColors),
|
sections: _convertDataForChart(state.categoriesColors, smallVerticalScreen),
|
||||||
borderData: FlBorderData(
|
borderData: FlBorderData(
|
||||||
show: false
|
show: false
|
||||||
),
|
),
|
||||||
centerSpaceRadius: 50,
|
centerSpaceRadius: smallVerticalScreen ? 30 :50,
|
||||||
sectionsSpace: 4
|
sectionsSpace: 4
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -10,19 +10,10 @@ class GlobalCounter extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(10),
|
padding: const EdgeInsets.all(10),
|
||||||
margin: const EdgeInsets.all(20),
|
margin: const EdgeInsets.only(bottom: 10),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(15),
|
borderRadius: BorderRadius.circular(15),
|
||||||
color: Theme.of(context).colorScheme.primaryContainer,
|
color: Theme.of(context).colorScheme.primaryContainer,
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Theme.of(context).colorScheme.shadow,
|
|
||||||
blurRadius: 10,
|
|
||||||
offset: const Offset(2, 2),
|
|
||||||
spreadRadius: 0.1,
|
|
||||||
blurStyle: BlurStyle.normal,
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
),
|
||||||
alignment: Alignment.centerRight,
|
alignment: Alignment.centerRight,
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class GlobalTotalChart extends StatelessWidget {
|
|||||||
lineTouchData: LineTouchData(
|
lineTouchData: LineTouchData(
|
||||||
touchTooltipData: LineTouchTooltipData(
|
touchTooltipData: LineTouchTooltipData(
|
||||||
maxContentWidth: 100,
|
maxContentWidth: 100,
|
||||||
tooltipBgColor: Theme.of(context).colorScheme.primaryContainer,
|
getTooltipColor: (LineBarSpot _) => Theme.of(context).colorScheme.primaryContainer,
|
||||||
getTooltipItems: (touchedSpots) {
|
getTooltipItems: (touchedSpots) {
|
||||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||||
final textStyle = TextStyle(
|
final textStyle = TextStyle(
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import 'package:fl_chart/fl_chart.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/domains/charts/models/month_totals.dart';
|
import 'package:krezus/domains/charts/models/month_totals.dart';
|
||||||
|
|
||||||
class MonthlyCategoriesTotalChart extends StatelessWidget {
|
class MonthlyCategoriesTotalChart extends StatelessWidget {
|
||||||
final Map<int, MonthTotals> categoriesMonthlyTotals;
|
final Map<int, MonthTotals> categoriesMonthlyTotals;
|
||||||
@@ -26,7 +26,7 @@ class MonthlyCategoriesTotalChart extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BarChartGroupData> _computeBarGroups(double barsSpace, double barsWidth, Map<String, Color> categoriesColors) {
|
List<BarChartGroupData> _computeBarGroups(double barsSpace, double barsWidth, Map<String, Color> categoriesColors, bool smallVerticalScreen) {
|
||||||
var a = categoriesMonthlyTotals.entries
|
var a = categoriesMonthlyTotals.entries
|
||||||
.map((entry) {
|
.map((entry) {
|
||||||
return BarChartGroupData(
|
return BarChartGroupData(
|
||||||
@@ -36,7 +36,7 @@ class MonthlyCategoriesTotalChart extends StatelessWidget {
|
|||||||
_computeStack(barsWidth, entry.value.positives, categoriesColors),
|
_computeStack(barsWidth, entry.value.positives, categoriesColors),
|
||||||
_computeStack(barsWidth, entry.value.negatives, categoriesColors),
|
_computeStack(barsWidth, entry.value.negatives, categoriesColors),
|
||||||
],
|
],
|
||||||
showingTooltipIndicators: [0, 1]
|
showingTooltipIndicators: smallVerticalScreen ? [] : [0, 1]
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
@@ -66,6 +66,7 @@ class MonthlyCategoriesTotalChart extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
return BlocBuilder<CategoryBloc, CategoryState>(
|
return BlocBuilder<CategoryBloc, CategoryState>(
|
||||||
builder: (context, state) => AspectRatio(
|
builder: (context, state) => AspectRatio(
|
||||||
aspectRatio: 1.66,
|
aspectRatio: 1.66,
|
||||||
@@ -77,7 +78,7 @@ class MonthlyCategoriesTotalChart extends StatelessWidget {
|
|||||||
return BarChart(
|
return BarChart(
|
||||||
BarChartData(
|
BarChartData(
|
||||||
maxY: _computeMaxValue(),
|
maxY: _computeMaxValue(),
|
||||||
barGroups: _computeBarGroups(barsSpace, barsWidth, state.categoriesColors),
|
barGroups: _computeBarGroups(barsSpace, barsWidth, state.categoriesColors, smallVerticalScreen),
|
||||||
titlesData: FlTitlesData(
|
titlesData: FlTitlesData(
|
||||||
topTitles: const AxisTitles(
|
topTitles: const AxisTitles(
|
||||||
sideTitles: SideTitles(showTitles: false)
|
sideTitles: SideTitles(showTitles: false)
|
||||||
@@ -93,7 +94,8 @@ class MonthlyCategoriesTotalChart extends StatelessWidget {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
handleBuiltInTouches: false,
|
handleBuiltInTouches: false,
|
||||||
touchTooltipData: BarTouchTooltipData(
|
touchTooltipData: BarTouchTooltipData(
|
||||||
tooltipBgColor: Colors.transparent,
|
// tooltipBgColor: Colors.transparent,
|
||||||
|
getTooltipColor: (BarChartGroupData _) => Colors.transparent,
|
||||||
tooltipMargin: 0,
|
tooltipMargin: 0,
|
||||||
getTooltipItem:(group, groupIndex, rod, rodIndex) {
|
getTooltipItem:(group, groupIndex, rod, rodIndex) {
|
||||||
String value = NumberFormat("#00").format(rod.toY);
|
String value = NumberFormat("#00").format(rod.toY);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/charts/chart_bloc.dart';
|
import 'package:krezus/domains/charts/chart_bloc.dart';
|
||||||
|
|
||||||
class YearSelector extends StatelessWidget {
|
class YearSelector extends StatelessWidget {
|
||||||
const YearSelector({super.key});
|
const YearSelector({super.key});
|
||||||
|
|||||||
@@ -1,26 +1,44 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transactions_actions.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transactions_header.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transactions_list.dart';
|
import 'package:krezus/pages/transactions/widgets/transactions_actions.dart';
|
||||||
|
import 'package:krezus/pages/transactions/widgets/transactions_header.dart';
|
||||||
|
import 'package:krezus/pages/transactions/widgets/transactions_list.dart';
|
||||||
|
|
||||||
class TransactionsPage extends StatelessWidget {
|
class TransactionsPage extends StatelessWidget {
|
||||||
const TransactionsPage({super.key});
|
const TransactionsPage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Center(
|
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||||
child: ConstrainedBox(
|
return BlocListener<TransactionBloc, TransactionState>(
|
||||||
constraints: const BoxConstraints(
|
listenWhen: (previous, current) => previous.showSnackBar != current.showSnackBar,
|
||||||
maxWidth: 1000
|
listener: (context, state) {
|
||||||
|
if (state.showSnackBar) {
|
||||||
|
ScaffoldMessenger
|
||||||
|
.of(context)
|
||||||
|
.showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
backgroundColor: state.snackBarIsError ? Colors.red : Colors.green,
|
||||||
|
content: Text(state.snackBarMessage),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
context.read<TransactionBloc>().add(const TransactionResetSnackBar());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: Container(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 1000),
|
||||||
|
padding: mediaQuery.padding,
|
||||||
|
child: const Column(
|
||||||
|
children: [
|
||||||
|
TransactionsActions(),
|
||||||
|
TransactionsHeader(),
|
||||||
|
TransactionsList(),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: const Column(
|
),
|
||||||
children: [
|
|
||||||
TransactionsActions(),
|
|
||||||
TransactionsHeader(),
|
|
||||||
TransactionsList(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
36
lib/pages/transactions/widgets/account_filter.dart
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
|
|
||||||
|
class AccountFilter extends StatelessWidget {
|
||||||
|
const AccountFilter({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final accountState = context.watch<AccountBloc>().state;
|
||||||
|
|
||||||
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
|
buildWhen: (previous, current) => previous.accountFilter != current.accountFilter,
|
||||||
|
builder: (context, state) => SizedBox(
|
||||||
|
width: 300,
|
||||||
|
child: DropdownButtonFormField<Account>(
|
||||||
|
value: state.accountFilter,
|
||||||
|
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterAccount(value!)),
|
||||||
|
items: accountState.accounts.map((e) => DropdownMenuItem(value: e, child: Text(e.label))).toList(),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixIcon: IconButton(
|
||||||
|
icon: const Icon(Icons.filter_alt_off),
|
||||||
|
onPressed: () => context.read<TransactionBloc>().add(const TransactionFilterAccount(null)),
|
||||||
|
),
|
||||||
|
hintText: 'Account',
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart' as tunas_category;
|
import 'package:krezus/repositories/metadata/models/category.dart' as krezus_category;
|
||||||
|
|
||||||
class CategoryFilter extends StatelessWidget {
|
class CategoryFilter extends StatelessWidget {
|
||||||
const CategoryFilter({super.key});
|
const CategoryFilter({super.key});
|
||||||
@@ -10,11 +10,12 @@ class CategoryFilter extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final categoryState = context.watch<CategoryBloc>().state;
|
final categoryState = context.watch<CategoryBloc>().state;
|
||||||
|
|
||||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
||||||
builder: (context, state) => SizedBox(
|
builder: (context, state) => SizedBox(
|
||||||
width: 500,
|
width: 300,
|
||||||
child: DropdownButtonFormField<tunas_category.Category>(
|
child: DropdownButtonFormField<krezus_category.Category>(
|
||||||
value: state.categoryFilter,
|
value: state.categoryFilter,
|
||||||
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
||||||
items: categoryState.categories.map((e) => DropdownMenuItem(value: e, child: Text(e.label))).toList(),
|
items: categoryState.categories.map((e) => DropdownMenuItem(value: e, child: Text(e.label))).toList(),
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transaction_form.dart';
|
import 'package:krezus/pages/transactions/widgets/transaction_form.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
|
||||||
class TransactionAddDialog extends StatelessWidget {
|
class TransactionAddDialog extends StatelessWidget {
|
||||||
const TransactionAddDialog({super.key});
|
const TransactionAddDialog({super.key});
|
||||||
@@ -21,8 +21,8 @@ class TransactionAddDialog extends StatelessWidget {
|
|||||||
BlocProvider.value(value: BlocProvider.of<CategoryBloc>(context)),
|
BlocProvider.value(value: BlocProvider.of<CategoryBloc>(context)),
|
||||||
BlocProvider.value(value: BlocProvider.of<AccountBloc>(context)),
|
BlocProvider.value(value: BlocProvider.of<AccountBloc>(context)),
|
||||||
],
|
],
|
||||||
child: const TransactionAddDialog()
|
child: const TransactionAddDialog(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,18 +32,18 @@ class TransactionAddDialog extends StatelessWidget {
|
|||||||
final actions = [
|
final actions = [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => TransactionAddDialog.hide(context),
|
onPressed: () => TransactionAddDialog.hide(context),
|
||||||
icon: const Icon(Icons.close)
|
icon: const Icon(Icons.close),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => context.read<TransactionBloc>().add(const TransactionAdd()),
|
onPressed: () => context.read<TransactionBloc>().add(const TransactionAdd()),
|
||||||
icon: const Icon(Icons.save)
|
icon: const Icon(Icons.save),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (currentTransaction != null) {
|
if (currentTransaction != null) {
|
||||||
actions.add(IconButton(
|
actions.add(IconButton(
|
||||||
onPressed: () => context.read<TransactionBloc>().add(const TransactionDeleteCurrent()),
|
onPressed: () => context.read<TransactionBloc>().add(const TransactionDeleteCurrent()),
|
||||||
icon: const Icon(Icons.delete)
|
icon: const Icon(Icons.delete),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ class TransactionAddDialog extends StatelessWidget {
|
|||||||
builder: (context, state) => AlertDialog(
|
builder: (context, state) => AlertDialog(
|
||||||
title: Text(state.currentTransaction == null ? 'Add Transaction' : 'Edit Transaction'),
|
title: Text(state.currentTransaction == null ? 'Add Transaction' : 'Edit Transaction'),
|
||||||
actions: _computeActions(context, state.currentTransaction),
|
actions: _computeActions(context, state.currentTransaction),
|
||||||
content: const TransactionForm()
|
content: const TransactionForm(),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:tunas/domains/account/account_bloc.dart';
|
import 'package:krezus/domains/account/account_bloc.dart';
|
||||||
import 'package:tunas/domains/category/category_bloc.dart';
|
import 'package:krezus/domains/category/category_bloc.dart';
|
||||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
|
|
||||||
class TransactionForm extends StatelessWidget {
|
class TransactionForm extends StatelessWidget {
|
||||||
|
|
||||||
@@ -15,13 +15,13 @@ class TransactionForm extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
_TransactionDateInput(),
|
_TransactionDateInput(),
|
||||||
const SizedBox(height: 10,),
|
const SizedBox(height: 35,),
|
||||||
_TransactionCategoryInput(),
|
_TransactionCategoryInput(),
|
||||||
const SizedBox(height: 10,),
|
const SizedBox(height: 35,),
|
||||||
_TransactionDescriptionInput(),
|
_TransactionDescriptionInput(),
|
||||||
const SizedBox(height: 10,),
|
const SizedBox(height: 35,),
|
||||||
_TransactionAccountInput(),
|
_TransactionAccountInput(),
|
||||||
const SizedBox(height: 10,),
|
const SizedBox(height: 35,),
|
||||||
_TransactionValueInput()
|
_TransactionValueInput()
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@@ -37,8 +37,11 @@ class _TransactionDateInput extends StatelessWidget {
|
|||||||
builder: (context, state) => SizedBox(
|
builder: (context, state) => SizedBox(
|
||||||
width: 500,
|
width: 500,
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
initialValue: DateFormat('dd-MM-yyyy', 'fr_FR').format(state.transactionDate.value ?? DateTime.now()),
|
|
||||||
keyboardType: TextInputType.datetime,
|
keyboardType: TextInputType.datetime,
|
||||||
|
readOnly: true,
|
||||||
|
controller: TextEditingController(
|
||||||
|
text: DateFormat('dd-MM-yyyy', 'fr_FR').format(state.transactionDate.value ?? DateTime.now()),
|
||||||
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
FocusScope.of(context).requestFocus(FocusNode());
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
showDatePicker(
|
showDatePicker(
|
||||||
@@ -53,7 +56,7 @@ class _TransactionDateInput extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.calendar_month),
|
icon: const Icon(Icons.calendar_month),
|
||||||
hintText: 'Date',
|
label: const Text('Date'),
|
||||||
errorText: state.transactionDate.isNotValid ? state.transactionDate.error?.message : null,
|
errorText: state.transactionDate.isNotValid ? state.transactionDate.error?.message : null,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
@@ -79,7 +82,7 @@ class _TransactionCategoryInput extends StatelessWidget {
|
|||||||
items: categoryState.categories.map((e) => DropdownMenuItem(value: e.label, child: Text(e.label))).toList(),
|
items: categoryState.categories.map((e) => DropdownMenuItem(value: e.label, child: Text(e.label))).toList(),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.category),
|
icon: const Icon(Icons.category),
|
||||||
hintText: 'Category',
|
label: const Text('Category'),
|
||||||
errorText: state.transactionCategory.isNotValid ? state.transactionCategory.error?.message : null,
|
errorText: state.transactionCategory.isNotValid ? state.transactionCategory.error?.message : null,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
@@ -101,7 +104,7 @@ class _TransactionDescriptionInput extends StatelessWidget {
|
|||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.description),
|
icon: const Icon(Icons.description),
|
||||||
hintText: 'Description',
|
label: const Text('Description'),
|
||||||
errorText: state.transactionDescription.isNotValid ? state.transactionDescription.error?.message : null,
|
errorText: state.transactionDescription.isNotValid ? state.transactionDescription.error?.message : null,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
@@ -129,7 +132,7 @@ class _TransactionAccountInput extends StatelessWidget {
|
|||||||
items: accountState.accounts.map((e) => DropdownMenuItem(value: e.label, child: Text(e.label))).toList(),
|
items: accountState.accounts.map((e) => DropdownMenuItem(value: e.label, child: Text(e.label))).toList(),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.account_box),
|
icon: const Icon(Icons.account_box),
|
||||||
hintText: 'Account',
|
label: const Text('Account'),
|
||||||
errorText: state.transactionAccount.isNotValid ? state.transactionAccount.error?.message : null,
|
errorText: state.transactionAccount.isNotValid ? state.transactionAccount.error?.message : null,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
@@ -152,7 +155,7 @@ class _TransactionValueInput extends StatelessWidget {
|
|||||||
keyboardType: TextInputType.number,
|
keyboardType: TextInputType.number,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
icon: const Icon(Icons.euro),
|
icon: const Icon(Icons.euro),
|
||||||
hintText: '\$\$\$',
|
label: const Text('\$\$\$'),
|
||||||
errorText: state.transactionValue.isNotValid ? state.transactionValue.error?.message : null,
|
errorText: state.transactionValue.isNotValid ? state.transactionValue.error?.message : null,
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
import 'package:krezus/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
|
||||||
class TransactionLine extends StatelessWidget {
|
class TransactionLine extends StatelessWidget {
|
||||||
final Transaction transaction;
|
final Transaction transaction;
|
||||||
@@ -9,8 +9,121 @@ class TransactionLine extends StatelessWidget {
|
|||||||
|
|
||||||
const TransactionLine({super.key, required this.transaction, required this.subTotal});
|
const TransactionLine({super.key, required this.transaction, required this.subTotal});
|
||||||
|
|
||||||
|
List<Widget> _largeScreenLayout(BuildContext context) {
|
||||||
|
return [
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: Text(
|
||||||
|
DateFormat('dd/MM/yyyy', 'fr_FR').format(transaction.date),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
fontSize: 15
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
transaction.category,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
transaction.description,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.w300, fontSize: 15)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: Text(transaction.account),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 120,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
NumberFormat(transaction.value > 0 ? '+#######.00 €' : '#######.00 €', 'fr_FR').format(transaction.value),
|
||||||
|
style: TextStyle(
|
||||||
|
color: transaction.value > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
NumberFormat('#######.00 €', 'fr_FR').format(subTotal),
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
fontSize: 15,
|
||||||
|
color: subTotal > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _smallScreenLayout(BuildContext context) {
|
||||||
|
return [
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: Text(
|
||||||
|
DateFormat('dd/MM/yyyy', 'fr_FR').format(transaction.date),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
fontSize: 15
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
transaction.category,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
transaction.description,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.w300, fontSize: 15)
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
transaction.account,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.w300, fontSize: 15)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 120,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
NumberFormat(transaction.value > 0 ? '+#######.00 €' : '#######.00 €', 'fr_FR').format(transaction.value),
|
||||||
|
style: TextStyle(
|
||||||
|
color: transaction.value > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
NumberFormat('#######.00 €', 'fr_FR').format(subTotal),
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.w300,
|
||||||
|
fontSize: 15,
|
||||||
|
color: subTotal > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => TransactionAddDialog.show(context, transaction),
|
onTap: () => TransactionAddDialog.show(context, transaction),
|
||||||
child: MergeSemantics(
|
child: MergeSemantics(
|
||||||
@@ -19,48 +132,7 @@ class TransactionLine extends StatelessWidget {
|
|||||||
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: smallVerticalScreen ? _smallScreenLayout(context) : _largeScreenLayout(context),
|
||||||
SizedBox(
|
|
||||||
width: 100,
|
|
||||||
child: Text(DateFormat('dd-MM-yyyy', 'fr_FR').format(transaction.date))
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
transaction.category,
|
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)
|
|
||||||
),
|
|
||||||
Text(transaction.description),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 100,
|
|
||||||
child: Text(transaction.account),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 120,
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
NumberFormat(transaction.value > 0 ? '+#######.00 €' : '#######.00 €', 'fr_FR').format(transaction.value),
|
|
||||||
style: TextStyle(
|
|
||||||
color: transaction.value > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
|
|
||||||
)
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
NumberFormat('#######.00 €', 'fr_FR').format(subTotal),
|
|
||||||
style: TextStyle(
|
|
||||||
color: subTotal > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error
|
|
||||||
)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,37 +1,73 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/category_filter.dart';
|
import 'package:krezus/pages/transactions/widgets/account_filter.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
import 'package:krezus/pages/transactions/widgets/category_filter.dart';
|
||||||
|
import 'package:krezus/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||||
|
|
||||||
class TransactionsActions extends StatelessWidget {
|
class TransactionsActions extends StatelessWidget {
|
||||||
const TransactionsActions({super.key});
|
const TransactionsActions({super.key});
|
||||||
|
|
||||||
@override
|
Widget _smallScreenLayout(BuildContext context) {
|
||||||
Widget build(BuildContext context) {
|
return Column(
|
||||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
builder: (context, state) => Container(
|
children: [
|
||||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
Row(
|
||||||
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
const Text (
|
||||||
'Transactions',
|
'Transactions',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontWeight: FontWeight.w900,
|
fontWeight: FontWeight.w900,
|
||||||
fontSize: 35,
|
fontSize: 35,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
CategoryFilter(),
|
FilledButton.icon(
|
||||||
IconButton(
|
|
||||||
onPressed: () => TransactionAddDialog.show(context, null),
|
onPressed: () => TransactionAddDialog.show(context, null),
|
||||||
|
label: const Text('Add'),
|
||||||
icon: const Icon(
|
icon: const Icon(
|
||||||
Icons.add
|
Icons.add
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
|
const CategoryFilter(),
|
||||||
|
const AccountFilter(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _largeScreenLayout(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
'Transactions',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
|
fontSize: 35,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const CategoryFilter(),
|
||||||
|
const AccountFilter(),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => TransactionAddDialog.show(context, null),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.add
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
|
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||||
|
builder: (context, state) => Container(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
||||||
|
child: smallVerticalScreen ? _smallScreenLayout(context) : _largeScreenLayout(context),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,39 +3,71 @@ import 'package:flutter/material.dart';
|
|||||||
class TransactionsHeader extends StatelessWidget {
|
class TransactionsHeader extends StatelessWidget {
|
||||||
const TransactionsHeader({super.key});
|
const TransactionsHeader({super.key});
|
||||||
|
|
||||||
|
List<Widget> _largeScreenLayout() {
|
||||||
|
return const [
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: Text('Date')
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Text('Description')
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: Text('Account'),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 120,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text('Amount'),
|
||||||
|
Text('SubTotal'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _smallScreenLayout() {
|
||||||
|
return const [
|
||||||
|
SizedBox(
|
||||||
|
width: 100,
|
||||||
|
child: Text('Date')
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Text('Description')
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 120,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Text('Amount'),
|
||||||
|
Text('SubTotal'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
||||||
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
||||||
decoration: const BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border(bottom: BorderSide(color: Colors.black))
|
border: Border(
|
||||||
),
|
bottom: BorderSide(
|
||||||
child: const Row(
|
width: 2,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: 100,
|
|
||||||
child: Text('Date')
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: Text('Description')
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 100,
|
|
||||||
child: Text('Account'),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 120,
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
Text('Amount'),
|
|
||||||
Text('SubTotal'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
],
|
)
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: smallVerticalScreen ? _smallScreenLayout() : _largeScreenLayout(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||||
import 'package:tunas/pages/transactions/widgets/transaction_line.dart';
|
import 'package:krezus/pages/transactions/widgets/transaction_line.dart';
|
||||||
|
|
||||||
class TransactionsList extends StatelessWidget {
|
class TransactionsList extends StatelessWidget {
|
||||||
const TransactionsList({super.key});
|
const TransactionsList({super.key});
|
||||||
@@ -15,10 +15,10 @@ class TransactionsList extends StatelessWidget {
|
|||||||
itemCount: state.transactionsLinesFiltered.length,
|
itemCount: state.transactionsLinesFiltered.length,
|
||||||
itemBuilder: (context, index) => TransactionLine(
|
itemBuilder: (context, index) => TransactionLine(
|
||||||
transaction: state.transactionsLinesFiltered[index].transaction,
|
transaction: state.transactionsLinesFiltered[index].transaction,
|
||||||
subTotal: state.transactionsLinesFiltered[index].subTotal
|
subTotal: state.transactionsLinesFiltered[index].subTotal,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,31 @@
|
|||||||
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:tunas/clients/storage/storage_client.dart';
|
import 'package:krezus/clients/storage/json_storage_client.dart';
|
||||||
import 'package:tunas/repositories/json/models/json.dart';
|
import 'package:krezus/repositories/json/models/json.dart';
|
||||||
|
|
||||||
class JsonRepository {
|
class JsonRepository {
|
||||||
String accountFile = 'tunas_main_account.json';
|
String accountFile = 'krezus_main_account.json';
|
||||||
|
|
||||||
final StorageClient _storageClient;
|
final JsonStorageClient _storageClient;
|
||||||
|
|
||||||
|
Map<String, Timer> saveTimerMap = {};
|
||||||
|
|
||||||
JsonRepository({
|
JsonRepository({
|
||||||
required storageClient,
|
required storageClient,
|
||||||
}) : _storageClient = storageClient;
|
}) : _storageClient = storageClient;
|
||||||
|
|
||||||
saveJson(Json json) async {
|
void saveJson(Json json) {
|
||||||
await _storageClient.save(json.getJsonFileName(), jsonEncode(json.toJson()));
|
Timer? saveTimer = saveTimerMap[json.getJsonFileName()];
|
||||||
|
|
||||||
|
if (saveTimer != null) {
|
||||||
|
saveTimer.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
saveTimer = Timer(const Duration(milliseconds: 500), () {
|
||||||
|
saveTimerMap.remove(json.getJsonFileName());
|
||||||
|
_storageClient.save(json.getJsonFileName(), jsonEncode(json.toJson()));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<T> loadJson<T extends Json>(Json json, JsonFactory<T> jsonFactory) async {
|
Future<T> loadJson<T extends Json>(Json json, JsonFactory<T> jsonFactory) async {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import 'package:rxdart/subjects.dart';
|
import 'package:rxdart/subjects.dart';
|
||||||
import 'package:tunas/repositories/json/json_repository.dart';
|
import 'package:krezus/repositories/json/json_repository.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/metadata.dart';
|
import 'package:krezus/repositories/metadata/models/metadata.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/settings.dart';
|
||||||
|
|
||||||
class MetadataRepository {
|
class MetadataRepository {
|
||||||
|
|
||||||
@@ -11,15 +12,24 @@ class MetadataRepository {
|
|||||||
final _categoriesController = BehaviorSubject<List<Category>>.seeded(const []);
|
final _categoriesController = BehaviorSubject<List<Category>>.seeded(const []);
|
||||||
final _budgetController = BehaviorSubject<List<Budget>>.seeded(const []);
|
final _budgetController = BehaviorSubject<List<Budget>>.seeded(const []);
|
||||||
final _accountController = BehaviorSubject<List<Account>>.seeded(const []);
|
final _accountController = BehaviorSubject<List<Account>>.seeded(const []);
|
||||||
|
final _settingsController = BehaviorSubject<Settings>.seeded(const Settings());
|
||||||
|
|
||||||
MetadataRepository({
|
MetadataRepository({
|
||||||
required jsonRepository,
|
required jsonRepository,
|
||||||
}) : _jsonRepository = jsonRepository;
|
}) : _jsonRepository = jsonRepository;
|
||||||
|
|
||||||
|
List<Category> getCategories() {
|
||||||
|
return _categoriesController.value;
|
||||||
|
}
|
||||||
|
|
||||||
Stream<List<Category>> getCategoriesStream() {
|
Stream<List<Category>> getCategoriesStream() {
|
||||||
return _categoriesController.asBroadcastStream();
|
return _categoriesController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Budget> getBudgets() {
|
||||||
|
return _budgetController.value;
|
||||||
|
}
|
||||||
|
|
||||||
Stream<List<Budget>> getBudgetsStream() {
|
Stream<List<Budget>> getBudgetsStream() {
|
||||||
return _budgetController.asBroadcastStream();
|
return _budgetController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
@@ -32,42 +42,62 @@ class MetadataRepository {
|
|||||||
return _accountController.asBroadcastStream();
|
return _accountController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMetadata() async {
|
Settings getSettings() {
|
||||||
|
return _settingsController.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<Settings> getSettingsStream() {
|
||||||
|
return _settingsController.asBroadcastStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadMetadata() async {
|
||||||
Metadata metadata = await _jsonRepository.loadJson(Metadata(), MetadataFactory());
|
Metadata metadata = await _jsonRepository.loadJson(Metadata(), MetadataFactory());
|
||||||
_broadcastMetadata(metadata);
|
_broadcastMetadata(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveCategories(List<Category> categories) async {
|
List<Category> saveCategories(List<Category> categories) {
|
||||||
Metadata metadata = _constructMetadataFromControllers();
|
Metadata metadata = _constructMetadataFromControllers();
|
||||||
metadata.categories = categories;
|
metadata.categories = categories;
|
||||||
await _jsonRepository.saveJson(metadata);
|
_jsonRepository.saveJson(metadata);
|
||||||
_categoriesController.add(categories);
|
_categoriesController.add(categories);
|
||||||
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveBudgets(List<Budget> budgets) async {
|
List<Budget> saveBudgets(List<Budget> budgets) {
|
||||||
Metadata metadata = _constructMetadataFromControllers();
|
Metadata metadata = _constructMetadataFromControllers();
|
||||||
metadata.budgets = budgets;
|
metadata.budgets = budgets;
|
||||||
await _jsonRepository.saveJson(metadata);
|
_jsonRepository.saveJson(metadata);
|
||||||
_budgetController.add(budgets);
|
_budgetController.add(budgets);
|
||||||
|
return budgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveAccounts(List<Account> accounts) async {
|
List<Account> saveAccounts(List<Account> accounts) {
|
||||||
Metadata metadata = _constructMetadataFromControllers();
|
Metadata metadata = _constructMetadataFromControllers();
|
||||||
metadata.accounts = accounts;
|
metadata.accounts = accounts;
|
||||||
await _jsonRepository.saveJson(metadata);
|
_jsonRepository.saveJson(metadata);
|
||||||
_accountController.add(accounts);
|
_accountController.add(accounts);
|
||||||
|
return accounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMetadata() async {
|
Settings saveSettings(Settings settings) {
|
||||||
|
Metadata metadata = _constructMetadataFromControllers();
|
||||||
|
metadata.settings = settings;
|
||||||
|
_jsonRepository.saveJson(metadata);
|
||||||
|
_settingsController.add(settings);
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteMetadata() {
|
||||||
Metadata metadata = Metadata();
|
Metadata metadata = Metadata();
|
||||||
await _jsonRepository.saveJson(metadata);
|
_jsonRepository.saveJson(metadata);
|
||||||
_broadcastMetadata(metadata);
|
_broadcastMetadata(metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
_broadcastMetadata(Metadata metadata) {
|
void _broadcastMetadata(Metadata metadata) {
|
||||||
_categoriesController.add(metadata.categories);
|
_categoriesController.add(metadata.categories);
|
||||||
_budgetController.add(metadata.budgets);
|
_budgetController.add(metadata.budgets);
|
||||||
_accountController.add(metadata.accounts);
|
_accountController.add(metadata.accounts);
|
||||||
|
_settingsController.add(metadata.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
Metadata _constructMetadataFromControllers() {
|
Metadata _constructMetadataFromControllers() {
|
||||||
@@ -75,6 +105,7 @@ class MetadataRepository {
|
|||||||
categories: _categoriesController.value,
|
categories: _categoriesController.value,
|
||||||
budgets: _budgetController.value,
|
budgets: _budgetController.value,
|
||||||
accounts: _accountController.value,
|
accounts: _accountController.value,
|
||||||
|
settings: _settingsController.value,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,13 @@ class Account {
|
|||||||
String label;
|
String label;
|
||||||
String color;
|
String color;
|
||||||
bool saving;
|
bool saving;
|
||||||
|
double interest;
|
||||||
|
|
||||||
Account({
|
Account({
|
||||||
this.label = '',
|
this.label = '',
|
||||||
this.color = '',
|
this.color = '',
|
||||||
this.saving = false,
|
this.saving = false,
|
||||||
|
this.interest = 0.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Account.fromJson(Map<String, dynamic> json) {
|
factory Account.fromJson(Map<String, dynamic> json) {
|
||||||
@@ -16,6 +18,7 @@ class Account {
|
|||||||
label: json['label'],
|
label: json['label'],
|
||||||
color: json['color'],
|
color: json['color'],
|
||||||
saving: bool.parse(json['saving']),
|
saving: bool.parse(json['saving']),
|
||||||
|
interest: double.parse(json['intereset']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +26,7 @@ class Account {
|
|||||||
'label': label,
|
'label': label,
|
||||||
'color': color,
|
'color': color,
|
||||||
'saving': saving.toString(),
|
'saving': saving.toString(),
|
||||||
|
'intereset': interest.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Color rgbToColor() {
|
Color rgbToColor() {
|
||||||
|
|||||||
@@ -1,20 +1,24 @@
|
|||||||
class Budget {
|
class Budget {
|
||||||
|
String label;
|
||||||
bool monthly;
|
bool monthly;
|
||||||
double value;
|
double value;
|
||||||
|
|
||||||
Budget({
|
Budget({
|
||||||
|
this.label = '',
|
||||||
this.monthly = false,
|
this.monthly = false,
|
||||||
this.value = 0.0,
|
this.value = 0.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Budget.fromJson(Map<String, dynamic> json) {
|
factory Budget.fromJson(Map<String, dynamic> json) {
|
||||||
return Budget(
|
return Budget(
|
||||||
monthly: json['monthly'],
|
label: json['label'],
|
||||||
|
monthly: bool.parse(json['monthly']),
|
||||||
value: double.parse(json['value']),
|
value: double.parse(json['value']),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> toJson() => {
|
Map<String, String> toJson() => {
|
||||||
|
'label': label,
|
||||||
'monthly': monthly.toString(),
|
'monthly': monthly.toString(),
|
||||||
'value': value.toString(),
|
'value': value.toString(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||||
import 'package:tunas/repositories/json/models/json.dart';
|
import 'package:krezus/repositories/json/models/json.dart';
|
||||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||||
|
import 'package:krezus/repositories/metadata/models/settings.dart';
|
||||||
|
|
||||||
class Metadata implements Json {
|
class Metadata implements Json {
|
||||||
List<Budget> budgets;
|
List<Budget> budgets;
|
||||||
List<Category> categories;
|
List<Category> categories;
|
||||||
List<Account> accounts;
|
List<Account> accounts;
|
||||||
|
Settings settings;
|
||||||
|
|
||||||
Metadata({
|
Metadata({
|
||||||
this.budgets = const [],
|
this.budgets = const [],
|
||||||
this.categories = const [],
|
this.categories = const [],
|
||||||
this.accounts = const [],
|
this.accounts = const [],
|
||||||
|
this.settings = const Settings(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
19
lib/repositories/metadata/models/settings.dart
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
final ThemeMode themeMode;
|
||||||
|
|
||||||
|
const Settings({
|
||||||
|
this.themeMode = ThemeMode.system,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Settings.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Settings(
|
||||||
|
themeMode: ThemeMode.values.byName(json['themeMode']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> toJson() => {
|
||||||
|
'themeMode': themeMode.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class Transaction {
|
class Transaction extends Equatable {
|
||||||
String uuid;
|
final String uuid;
|
||||||
DateTime date;
|
final DateTime date;
|
||||||
String category;
|
final String category;
|
||||||
String description;
|
final String description;
|
||||||
String account;
|
final String account;
|
||||||
double value;
|
final double value;
|
||||||
|
|
||||||
Transaction({
|
const Transaction({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
required this.date,
|
required this.date,
|
||||||
required this.category,
|
required this.category,
|
||||||
@@ -36,4 +37,7 @@ class Transaction {
|
|||||||
'account': account,
|
'account': account,
|
||||||
'value': value.toString(),
|
'value': value.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, date, category, description, account, value];
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:tunas/repositories/json/models/json.dart';
|
import 'package:krezus/repositories/json/models/json.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
|
|
||||||
class Transactions implements Json {
|
class Transactions implements Json {
|
||||||
List<Transaction> transactions;
|
List<Transaction> transactions;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:rxdart/subjects.dart';
|
import 'package:rxdart/subjects.dart';
|
||||||
import 'package:tunas/repositories/json/json_repository.dart';
|
import 'package:krezus/repositories/json/json_repository.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||||
import 'package:tunas/repositories/transactions/models/transactions.dart';
|
import 'package:krezus/repositories/transactions/models/transactions.dart';
|
||||||
|
|
||||||
class TransactionsRepository {
|
class TransactionsRepository {
|
||||||
|
|
||||||
@@ -20,20 +20,20 @@ class TransactionsRepository {
|
|||||||
return _transactionsController.asBroadcastStream();
|
return _transactionsController.asBroadcastStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadTransactions() async {
|
Future<void> loadTransactions() async {
|
||||||
Transactions transactions = await _jsonRepository.loadJson(Transactions(), TransactionsFactory());
|
Transactions transactions = await _jsonRepository.loadJson(Transactions(), TransactionsFactory());
|
||||||
_transactionsController.add(transactions.transactions);
|
_transactionsController.add(transactions.transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTransactions(List<Transaction> transactionsList) async {
|
void saveTransactions(List<Transaction> transactionsList) {
|
||||||
Transactions transactions = Transactions(transactions: transactionsList);
|
Transactions transactions = Transactions(transactions: transactionsList);
|
||||||
await _jsonRepository.saveJson(transactions);
|
_jsonRepository.saveJson(transactions);
|
||||||
_transactionsController.add(transactionsList);
|
_transactionsController.add(transactionsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteTransactions() async {
|
void deleteTransactions() {
|
||||||
Transactions transactions = Transactions();
|
Transactions transactions = Transactions();
|
||||||
await _jsonRepository.saveJson(transactions);
|
_jsonRepository.saveJson(transactions);
|
||||||
_transactionsController.add([]);
|
_transactionsController.add([]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ project(runner LANGUAGES CXX)
|
|||||||
|
|
||||||
# The name of the executable created for the application. Change this to change
|
# The name of the executable created for the application. Change this to change
|
||||||
# the on-disk name of your application.
|
# the on-disk name of your application.
|
||||||
set(BINARY_NAME "tunas")
|
set(BINARY_NAME "krezus")
|
||||||
# The unique GTK application identifier for this application. See:
|
# The unique GTK application identifier for this application. See:
|
||||||
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
|
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
|
||||||
set(APPLICATION_ID "com.example.tunas")
|
set(APPLICATION_ID "sx.glt.krezus")
|
||||||
|
|
||||||
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
|
||||||
# versions of CMake.
|
# versions of CMake.
|
||||||
|
|||||||