Compare commits
10 Commits
2006ebf5cb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
f4294e0e11
|
|||
|
78614bd021
|
|||
|
f1d7d31a3c
|
|||
|
6a9da33283
|
|||
| 35930d188c | |||
| 51cb8868a3 | |||
| fc6f64a271 | |||
| f86c4cd18b | |||
| 979fecb60a | |||
| 2b53d1ab74 |
6
.vscode/launch.json
vendored
@@ -5,18 +5,18 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "tunas",
|
||||
"name": "krezus",
|
||||
"request": "launch",
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
"name": "tunas (profile mode)",
|
||||
"name": "krezus (profile mode)",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "profile"
|
||||
},
|
||||
{
|
||||
"name": "tunas (release mode)",
|
||||
"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.
|
||||
@@ -23,7 +23,7 @@ if (flutterVersionName == null) {
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "com.example.tunas"
|
||||
namespace "sx.glt.krezus"
|
||||
compileSdkVersion flutter.compileSdkVersion
|
||||
ndkVersion flutter.ndkVersion
|
||||
|
||||
@@ -42,7 +42,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
// 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.
|
||||
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
|
||||
minSdkVersion flutter.minSdkVersion
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application
|
||||
android:label="tunas"
|
||||
android:label="krezus"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/launcher_icon">
|
||||
<activity
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.example.tunas
|
||||
package sx.glt.krezus
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 5.6 KiB After Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 11 KiB 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 |
@@ -367,7 +367,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -384,7 +384,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas.RunnerTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
@@ -402,7 +402,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas.RunnerTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||
@@ -418,7 +418,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas.RunnerTests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
|
||||
@@ -545,7 +545,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
@@ -567,7 +567,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.example.tunas;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = sx.glt.krezus;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
||||
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 183 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 9.3 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 10 KiB |
@@ -5,7 +5,7 @@
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Tunas</string>
|
||||
<string>Krezus</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
@@ -13,7 +13,7 @@
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>tunas</string>
|
||||
<string>krezus</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<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_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:tunas/clients/storage/storage_client.dart';
|
||||
import 'package:tunas/pages/home/home_page.dart';
|
||||
import 'package:tunas/repositories/json/json_repository.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:tunas/theme.dart';
|
||||
import 'package:krezus/clients/storage/json_storage_client.dart';
|
||||
import 'package:krezus/pages/home/home_page.dart';
|
||||
import 'package:krezus/repositories/json/json_repository.dart';
|
||||
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||
|
||||
class App extends StatefulWidget {
|
||||
const App({super.key});
|
||||
@@ -30,7 +30,7 @@ class AppView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AppViewState extends State<AppView> {
|
||||
late final StorageClient _storageClient;
|
||||
late final JsonStorageClient _storageClient;
|
||||
late final JsonRepository _jsonRepository;
|
||||
late final TransactionsRepository _transactionsRepository;
|
||||
late final MetadataRepository _metadataRepository;
|
||||
@@ -39,13 +39,15 @@ class _AppViewState extends State<AppView> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_storageClient = StorageClient();
|
||||
_storageClient = JsonStorageClient();
|
||||
_jsonRepository = JsonRepository(storageClient: _storageClient);
|
||||
_transactionsRepository = TransactionsRepository(jsonRepository: _jsonRepository);
|
||||
_metadataRepository = MetadataRepository(jsonRepository: _jsonRepository);
|
||||
|
||||
_transactionsRepository.loadTransactions();
|
||||
_metadataRepository.loadMetadata();
|
||||
|
||||
_metadataRepository.getSettingsStream().listen((event) => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -56,23 +58,44 @@ class _AppViewState extends State<AppView> {
|
||||
RepositoryProvider.value(value: _transactionsRepository),
|
||||
RepositoryProvider.value(value: _metadataRepository),
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Tunas',
|
||||
theme: ThemeData(useMaterial3: true, colorScheme: lightColorScheme),
|
||||
darkTheme: ThemeData(useMaterial3: true, colorScheme: darkColorScheme),
|
||||
themeMode: ThemeMode.dark,
|
||||
initialRoute: '/home',
|
||||
routes: {
|
||||
'/home':(context) => const HomePage(),
|
||||
},
|
||||
localizationsDelegates: const [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate
|
||||
],
|
||||
supportedLocales: const [
|
||||
Locale('fr')
|
||||
],
|
||||
child: DynamicColorBuilder(
|
||||
builder: ((lightDynamic, darkDynamic) {
|
||||
ColorScheme lightColorScheme;
|
||||
ColorScheme darkColorScheme;
|
||||
|
||||
if (lightDynamic != null && darkDynamic != null) {
|
||||
lightColorScheme = lightDynamic.harmonized();
|
||||
darkColorScheme = darkDynamic.harmonized();
|
||||
} else {
|
||||
lightColorScheme = ColorScheme.fromSeed(
|
||||
seedColor: const Color.fromARGB(255, 103, 6, 231),
|
||||
);
|
||||
|
||||
darkColorScheme = ColorScheme.fromSeed(
|
||||
seedColor: const Color.fromARGB(255, 103, 6, 231),
|
||||
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';
|
||||
|
||||
class StorageClient {
|
||||
class JsonStorageClient {
|
||||
|
||||
save(String filename, String data) async {
|
||||
File file = await _getJson(filename);
|
||||
await file.writeAsString(data);
|
||||
@@ -19,11 +20,17 @@ class StorageClient {
|
||||
}
|
||||
|
||||
Future<File> _getJson(String filename) async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final file = File('${dir.path}/$filename');
|
||||
if (!file.existsSync()) {
|
||||
file.createSync();
|
||||
final rootDirectory = Platform.isAndroid ? await getExternalStorageDirectory() : await getApplicationDocumentsDirectory();
|
||||
|
||||
final appDirectory = Directory('${rootDirectory!.path}/krezus');
|
||||
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:file_picker/file_picker.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
part 'account_event.dart';
|
||||
@@ -55,6 +55,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
on<AccountEditLabel>(_onAccountEditLabel);
|
||||
on<AccountEditSaving>(_onAccountEditSaving);
|
||||
on<AccountEditColor>(_onAccountEditColor);
|
||||
on<ClearData>(_onClearData);
|
||||
|
||||
_metadataRepository
|
||||
.getAccountsStream()
|
||||
@@ -74,7 +75,7 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
}
|
||||
|
||||
_onAccountImportCSV(AccountImportCSV event, Emitter<AccountState> emit) async {
|
||||
int colorIndex = 0;
|
||||
// int colorIndex = 0;
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||
|
||||
final csvPath = result?.files.first.path;
|
||||
@@ -123,13 +124,13 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
})
|
||||
.toList();
|
||||
|
||||
await _metadataRepository.deleteMetadata();
|
||||
await _transactionsRepository.deleteTransactions();
|
||||
_metadataRepository.deleteMetadata();
|
||||
_transactionsRepository.deleteTransactions();
|
||||
|
||||
await _metadataRepository.saveAccounts(accounts.values.toList());
|
||||
await _metadataRepository.saveBudgets([]);
|
||||
await _metadataRepository.saveCategories(categoriesMap.values.toList());
|
||||
await _transactionsRepository.saveTransactions(transactions);
|
||||
_metadataRepository.saveAccounts(accounts.values.toList());
|
||||
_metadataRepository.saveBudgets([]);
|
||||
_metadataRepository.saveCategories(categoriesMap.values.toList());
|
||||
_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();
|
||||
Account account = Account(
|
||||
label: 'Account $uuid',
|
||||
@@ -149,11 +150,11 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
saving: false
|
||||
);
|
||||
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;
|
||||
List<Account> accounts = state.accounts;
|
||||
List<Transaction> transactions = _transactionsRepository.getTransactions();
|
||||
@@ -165,36 +166,33 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
accounts.removeWhere((account) => account.label == accountToRemove.label);
|
||||
emit(AccountRemoveSucess());
|
||||
emit(
|
||||
state.copyWith(await _metadataRepository.saveAccounts(accounts))
|
||||
state.copyWith(_metadataRepository.saveAccounts(accounts))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_onAccountEditLabel(AccountEditLabel event, Emitter<AccountState> emit) async {
|
||||
Account account = event.account;
|
||||
account.label = event.label;
|
||||
emit(
|
||||
state.copyWith(await _saveAccount(account))
|
||||
);
|
||||
_onAccountEditLabel(AccountEditLabel event, Emitter<AccountState> emit) {
|
||||
// Account account = event.account;
|
||||
// TODO check for existance, rename every transaction
|
||||
}
|
||||
|
||||
_onAccountEditSaving(AccountEditSaving event, Emitter<AccountState> emit) async {
|
||||
_onAccountEditSaving(AccountEditSaving event, Emitter<AccountState> emit) {
|
||||
Account account = event.account;
|
||||
account.saving = event.saving;
|
||||
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.color = event.color;
|
||||
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();
|
||||
|
||||
try {
|
||||
@@ -209,7 +207,12 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
|
||||
}
|
||||
}
|
||||
|
||||
await _metadataRepository.saveAccounts(accounts);
|
||||
_metadataRepository.saveAccounts(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 => [];
|
||||
}
|
||||
|
||||
final class ClearData extends AccountEvent {
|
||||
const ClearData();
|
||||
}
|
||||
|
||||
final class AccountImportCSV extends AccountEvent {
|
||||
const AccountImportCSV();
|
||||
}
|
||||
|
||||
@@ -1,27 +1,241 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||
import 'package:krezus/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:krezus/repositories/transactions/transactions_repository.dart';
|
||||
|
||||
part 'budget_event.dart';
|
||||
part 'budget_state.dart';
|
||||
|
||||
class BudgetBloc extends Bloc<BudgetEvent, BudgetState> {
|
||||
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<BudgetAdd>(_onBudgetAdd);
|
||||
on<BudgetRemove>(_onBudgetRemove);
|
||||
on<BudgetSetValue>(_onBudgetSetValue);
|
||||
on<BudgetSetLabel>(_onBudgetSetLabel);
|
||||
on<BudgetCompareNext>(_onBudgetCompareNext);
|
||||
on<BudgetComparePrevious>(_onBudgetComparePrevious);
|
||||
on<BudgetSetCompare>(_onBudgetSetCompare);
|
||||
on<BudgetSetInitial>(_onBudgetSetInitial);
|
||||
|
||||
_metadataRepository
|
||||
.getBudgetsStream()
|
||||
.listen((budgets) => add(BudgetsLoad(budgets)));
|
||||
|
||||
_transactionsRepository
|
||||
.getTransactionsStream()
|
||||
.listen((transactions) => add(BudgetSetCompare()));
|
||||
}
|
||||
|
||||
_onBudgetsLoad(
|
||||
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(
|
||||
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
|
||||
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';
|
||||
|
||||
final class BudgetState extends Equatable {
|
||||
final class BudgetState {
|
||||
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({
|
||||
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({
|
||||
List<Budget>? budgets,
|
||||
double? initialBudget,
|
||||
double? remainingBudget,
|
||||
List<Budget>? compareBudgets,
|
||||
List<Budget>? otherBudgets,
|
||||
num? compareYear,
|
||||
num? compareMonth,
|
||||
DateTime? firstDate,
|
||||
DateTime? lastDate,
|
||||
}) {
|
||||
return BudgetState(
|
||||
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 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:krezus/repositories/metadata/metadata_repository.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_state.dart';
|
||||
|
||||
class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
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<CategoryEditColor>(_onCategoryEditColor);
|
||||
on<CategoryEditTransfert>(_onCategoryEditTransfert);
|
||||
on<CategoryEditEssential>(_onCategoryEditEssential);
|
||||
on<CategoryEditLabel>(_onCategoryEditLabel);
|
||||
on<CategoryRemove>(_onCategoryRemove);
|
||||
on<CategoryAdd>(_onCategoryAdd);
|
||||
|
||||
_metadataRepository
|
||||
.getCategoriesStream()
|
||||
@@ -22,9 +39,81 @@ class CategoryBloc extends Bloc<CategoryEvent, CategoryState> {
|
||||
_onCategoriesLoad(
|
||||
CategoriesLoad event, Emitter<CategoryState> emit
|
||||
) {
|
||||
emit(state.copyWith(
|
||||
categories: event.categories,
|
||||
categoriesColors: { for (var category in event.categories) category.label : category.rgbToColor() }
|
||||
));
|
||||
emit(_computeState(event.categories));
|
||||
}
|
||||
|
||||
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
|
||||
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';
|
||||
|
||||
final class CategoryState extends Equatable {
|
||||
final class CategoryState {
|
||||
final List<Category> categories;
|
||||
final Map<String, Color> categoriesColors;
|
||||
|
||||
@@ -18,7 +18,7 @@ final class CategoryState extends Equatable {
|
||||
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:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/charts/models/month_totals.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_line.dart';
|
||||
import 'package:tunas/domains/charts/models/chart_item.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:krezus/domains/charts/models/month_totals.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_line.dart';
|
||||
import 'package:krezus/domains/charts/models/chart_item.dart';
|
||||
import 'package:krezus/repositories/metadata/metadata_repository.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';
|
||||
|
||||
part 'chart_event.dart';
|
||||
part 'chart_state.dart';
|
||||
@@ -95,6 +95,8 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
categoriesTotals[transaction.category] = categoryTotal;
|
||||
}
|
||||
|
||||
accountsTotals.removeWhere((key, value) => value.round() == 0);
|
||||
|
||||
return _computeStateScopedStats(state.copyWith(
|
||||
transactionsLines: transactionsLines,
|
||||
globalTotal: globalTotal,
|
||||
@@ -113,7 +115,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
double scoppedTotal = 0;
|
||||
List<ChartItem> scopedCategoriesPositiveTotals = [];
|
||||
List<ChartItem> scopedCategoriesNegativeTotals = [];
|
||||
Map<int, FlSpot> scopedMonthlyTotals = {};
|
||||
Map<int, FlSpot> scopedMonthlyTotalsMap = {};
|
||||
Map<int, MonthTotals> scopedCategoriesMonthlyTotals = {};
|
||||
|
||||
Map<int, double> scopedMonthlyPostitiveTotals = {};
|
||||
@@ -134,7 +136,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
DateTime transactionDate = transactionLine.transaction.date;
|
||||
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];
|
||||
if (category == null || category.transfert) {
|
||||
@@ -229,6 +231,9 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
_sortMapByValues(monthTotals.negatives);
|
||||
}
|
||||
|
||||
List<FlSpot> scopedMonthlyTotals = scopedMonthlyTotalsMap.values.toList();
|
||||
scopedMonthlyTotals.sort((a, b) => a.x.compareTo(b.x));
|
||||
|
||||
return state.copyWith(
|
||||
scoppedProfit: scoppedTotal,
|
||||
scopedCategoriesPositiveTotals: scopedCategoriesPositiveTotals,
|
||||
@@ -239,7 +244,7 @@ class ChartBloc extends Bloc<ChartEvent, ChartState> {
|
||||
scopedSimplifiedCategoriesPositiveTotalsPercents: scopedSimplifiedCategoriesPositiveTotalsPercents,
|
||||
scopedSimplifiedCategoriesNegativeTotals: scopedSimplifiedCategoriesNegativeTotals,
|
||||
scopedSimplifiedCategoriesNegativeTotalsPercents: scopedSimplifiedCategoriesNegativeTotalsPercents,
|
||||
scopedMonthlyTotals: scopedMonthlyTotals.values.toList(),
|
||||
scopedMonthlyTotals: scopedMonthlyTotals,
|
||||
scopedCategoriesMonthlyTotals: scopedCategoriesMonthlyTotals,
|
||||
scopedMonthlyPostitiveTotals: scopedMonthlyPostitiveTotals,
|
||||
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 {
|
||||
Transaction transaction;
|
||||
double subTotal;
|
||||
class TransactionLine extends Equatable{
|
||||
final Transaction transaction;
|
||||
final double subTotal;
|
||||
|
||||
TransactionLine({
|
||||
const TransactionLine({
|
||||
required this.transaction,
|
||||
required this.subTotal,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [transaction, subTotal];
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:formz/formz.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_account.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_category.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_date.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_description.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_line.dart';
|
||||
import 'package:tunas/domains/transaction/models/transaction_value.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_account.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_category.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_date.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_description.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_line.dart';
|
||||
import 'package:krezus/domains/transaction/models/transaction_value.dart';
|
||||
import 'package:krezus/repositories/metadata/models/account.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 'transaction_event.dart';
|
||||
@@ -33,18 +36,20 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
||||
on<TransactionSetCurrent>(_onTransactionSetCurrent);
|
||||
on<TransactionDeleteCurrent>(_onTransactionDeleteCurrent);
|
||||
on<TransactionFilterCategory>(_onTransactionFilterCategory);
|
||||
on<TransactionFilterAccount>(_onTransactionFilterAccount);
|
||||
on<TransactionResetSnackBar>(_onTransactionResetSnackBar);
|
||||
|
||||
_transactionsRepository
|
||||
.getTransactionsStream()
|
||||
.listen((transactions) => add(TransactionsLoad(transactions)));
|
||||
}
|
||||
|
||||
_onAccountLoad(TransactionsLoad event, Emitter<TransactionState> emit) {
|
||||
FutureOr<void> _onAccountLoad(TransactionsLoad event, Emitter<TransactionState> emit) {
|
||||
var computeResult = _computeTransactionLine(event.transactions);
|
||||
emit(state.copyWith(
|
||||
transactions: event.transactions,
|
||||
transactionsLines: computeResult.list,
|
||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
||||
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||
globalTotal: computeResult.globalTotal,
|
||||
accountsTotals: computeResult.accountsTotals,
|
||||
));
|
||||
@@ -73,7 +78,7 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
||||
return (list: output, globalTotal: globalTotal, accountsTotals: accountsTotals, categories: categories.toList());
|
||||
}
|
||||
|
||||
_onTransactionDateChange(
|
||||
FutureOr<void> _onTransactionDateChange(
|
||||
TransactionDateChange event, Emitter<TransactionState> emit
|
||||
) {
|
||||
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
|
||||
) {
|
||||
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
|
||||
) {
|
||||
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
|
||||
) {
|
||||
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
|
||||
) {
|
||||
try {
|
||||
@@ -131,21 +136,21 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
||||
}
|
||||
}
|
||||
|
||||
_onTransactionOpenAddDialog(
|
||||
FutureOr<void> _onTransactionOpenAddDialog(
|
||||
TransactionOpenAddDialog event, Emitter<TransactionState> emit
|
||||
) {
|
||||
emit(state.copyWith(showAddDialog: true));
|
||||
}
|
||||
|
||||
_onTransactionHideAddDialog(
|
||||
FutureOr<void> _onTransactionHideAddDialog(
|
||||
TransactionHideAddDialog event, Emitter<TransactionState> emit
|
||||
) {
|
||||
emit(state.copyWith(showAddDialog: false));
|
||||
}
|
||||
|
||||
_onTransactionAddDialog(
|
||||
FutureOr<void> _onTransactionAddDialog(
|
||||
TransactionAdd event, Emitter<TransactionState> emit
|
||||
) async {
|
||||
) {
|
||||
if (state.isValid) {
|
||||
List<Transaction> transactions = state.transactions;
|
||||
Transaction? currentTransaction = state.currentTransaction;
|
||||
@@ -163,25 +168,28 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
||||
));
|
||||
final computeResult = _computeTransactionLine(transactions);
|
||||
|
||||
await _transactionsRepository.saveTransactions(transactions);
|
||||
_transactionsRepository.saveTransactions(transactions);
|
||||
|
||||
emit(state.copyWith(
|
||||
currentTransaction: null,
|
||||
transactionDate: const TransactionDate.pure(),
|
||||
transactionCategory: const TransactionCategory.pure(),
|
||||
transactionDescription: const TransactionDescription.pure(),
|
||||
transactionAccount: const TransactionAccount.pure(),
|
||||
transactionValue: const TransactionValue.pure(),
|
||||
// transactionDate: const TransactionDate.pure(),
|
||||
// transactionCategory: const TransactionCategory.pure(),
|
||||
// transactionDescription: const TransactionDescription.pure(),
|
||||
// transactionAccount: const TransactionAccount.pure(),
|
||||
// transactionValue: const TransactionValue.pure(),
|
||||
transactions: transactions,
|
||||
transactionsLines: computeResult.list,
|
||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
||||
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||
globalTotal: computeResult.globalTotal,
|
||||
accountsTotals: computeResult.accountsTotals,
|
||||
showSnackBar: true,
|
||||
snackBarIsError: false,
|
||||
snackBarMessage: 'Transaction ${currentTransaction == null ? 'added' : 'updated'} !',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
_onTransactionSetCurrent(
|
||||
FutureOr<void> _onTransactionSetCurrent(
|
||||
TransactionSetCurrent event, Emitter<TransactionState> emit
|
||||
) {
|
||||
Transaction? transaction = event.transaction;
|
||||
@@ -206,15 +214,15 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
||||
}
|
||||
}
|
||||
|
||||
_onTransactionDeleteCurrent(
|
||||
FutureOr<void> _onTransactionDeleteCurrent(
|
||||
TransactionDeleteCurrent event, Emitter<TransactionState> emit
|
||||
) async {
|
||||
) {
|
||||
Transaction? currentTransaction = state.currentTransaction;
|
||||
if (currentTransaction != null) {
|
||||
List<Transaction> transactions = state.transactions;
|
||||
transactions.removeWhere((transaction) => transaction.uuid == currentTransaction.uuid);
|
||||
final computeResult = _computeTransactionLine(transactions);
|
||||
await _transactionsRepository.saveTransactions(transactions);
|
||||
_transactionsRepository.saveTransactions(transactions);
|
||||
emit(state.copyWith(
|
||||
currentTransaction: null,
|
||||
transactionDate: const TransactionDate.pure(),
|
||||
@@ -224,33 +232,83 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {
|
||||
transactionValue: const TransactionValue.pure(),
|
||||
transactions: transactions,
|
||||
transactionsLines: computeResult.list,
|
||||
transactionsLinesFiltered: _applyCategoryFilter(computeResult.list),
|
||||
transactionsLinesFiltered: _applyFilters(computeResult.list),
|
||||
globalTotal: computeResult.globalTotal,
|
||||
accountsTotals: computeResult.accountsTotals,
|
||||
showSnackBar: true,
|
||||
snackBarIsError: false,
|
||||
snackBarMessage: 'Transaction removed !',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_onTransactionFilterCategory(TransactionFilterCategory event, Emitter<TransactionState> emit) {
|
||||
List<TransactionLine> transactionsLinesFiltered = state.transactionsLines;
|
||||
String? categoryLabel = event.category?.label;
|
||||
if (categoryLabel != null) {
|
||||
transactionsLinesFiltered = state.transactionsLines.where((transaction) => transaction.transaction.category == categoryLabel).toList();
|
||||
}
|
||||
FutureOr<void> _onTransactionFilterCategory(TransactionFilterCategory 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: event.category,
|
||||
accountFilter: state.accountFilter,
|
||||
));
|
||||
|
||||
emit(state.copyWith(
|
||||
transactionsLinesFiltered: transactionsLinesFiltered,
|
||||
categoryFilter: event.category,
|
||||
transactionsLinesFiltered: _applyFilters(state.transactionsLines),
|
||||
));
|
||||
}
|
||||
|
||||
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;
|
||||
String? categoryLabel = state.categoryFilter?.label;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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> transactionsLinesFiltered;
|
||||
final Category? categoryFilter;
|
||||
final Account? accountFilter;
|
||||
|
||||
final TransactionDate transactionDate;
|
||||
final TransactionCategory transactionCategory;
|
||||
@@ -19,6 +20,10 @@ final class TransactionState extends Equatable {
|
||||
|
||||
final Transaction? currentTransaction;
|
||||
|
||||
final bool showSnackBar;
|
||||
final String snackBarMessage;
|
||||
final bool snackBarIsError;
|
||||
|
||||
const TransactionState({
|
||||
this.globalTotal = 0,
|
||||
this.accountsTotals = const <String, double>{},
|
||||
@@ -34,6 +39,10 @@ final class TransactionState extends Equatable {
|
||||
this.showAddDialog = false,
|
||||
this.currentTransaction,
|
||||
this.categoryFilter,
|
||||
this.accountFilter,
|
||||
this.showSnackBar = false,
|
||||
this.snackBarMessage = '',
|
||||
this.snackBarIsError = false,
|
||||
});
|
||||
|
||||
TransactionState copyWith({
|
||||
@@ -51,6 +60,10 @@ final class TransactionState extends Equatable {
|
||||
bool? showAddDialog,
|
||||
Transaction? currentTransaction,
|
||||
Category? categoryFilter,
|
||||
Account? accountFilter,
|
||||
bool? showSnackBar,
|
||||
String? snackBarMessage,
|
||||
bool? snackBarIsError,
|
||||
}) {
|
||||
return TransactionState(
|
||||
globalTotal: globalTotal ?? this.globalTotal,
|
||||
@@ -66,12 +79,19 @@ final class TransactionState extends Equatable {
|
||||
isValid: isValid ?? this.isValid,
|
||||
showAddDialog: showAddDialog ?? this.showAddDialog,
|
||||
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
|
||||
List<Object?> get props => [
|
||||
transactions,
|
||||
transactionsLines,
|
||||
transactionsLinesFiltered,
|
||||
transactionDate,
|
||||
transactionCategory,
|
||||
transactionDescription,
|
||||
@@ -81,6 +101,10 @@ final class TransactionState extends Equatable {
|
||||
showAddDialog,
|
||||
currentTransaction,
|
||||
categoryFilter,
|
||||
accountFilter,
|
||||
showSnackBar,
|
||||
snackBarMessage,
|
||||
snackBarIsError,
|
||||
];
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:tunas/app.dart';
|
||||
import 'package:krezus/app.dart';
|
||||
|
||||
void main() {
|
||||
initializeDateFormatting('fr_FR', null);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/budgets_actions.dart';
|
||||
import 'package:tunas/pages/budgets/widgets/month_distribution.dart';
|
||||
import 'package:krezus/pages/budgets/widgets/budgets_actions.dart';
|
||||
import 'package:krezus/pages/budgets/widgets/month_distribution.dart';
|
||||
|
||||
class BudgetsPage extends StatelessWidget {
|
||||
const BudgetsPage({super.key});
|
||||
@@ -11,7 +11,7 @@ class BudgetsPage extends StatelessWidget {
|
||||
return Center(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 1000
|
||||
maxWidth: 1000,
|
||||
),
|
||||
child: ListView(
|
||||
padding: mediaQuery.padding.copyWith(left: 10.0, right: 10.0, bottom: 100.0),
|
||||
|
||||
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_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:krezus/domains/account/account_bloc.dart';
|
||||
|
||||
class BudgetsActions extends StatelessWidget {
|
||||
const BudgetsActions({super.key});
|
||||
|
||||
@@ -1,73 +1,22 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/foundation.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 {
|
||||
const MonthDistribution({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
TitledContainer(
|
||||
title: 'Prepare',
|
||||
child: Column(
|
||||
children: [
|
||||
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)
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
return BlocBuilder<BudgetBloc, BudgetState>(
|
||||
builder: (context, state) => const Column(
|
||||
children: [
|
||||
BudgetMaker(),
|
||||
BudgetComparator(),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
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(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
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),
|
||||
child: Column(
|
||||
@@ -56,7 +47,12 @@ class TitledContainer extends StatelessWidget {
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
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),
|
||||
child: _computeTitleRow()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tunas/pages/data/widgets/account_settings.dart';
|
||||
import 'package:tunas/pages/data/widgets/categories_settings.dart';
|
||||
import 'package:tunas/pages/data/widgets/import_settings.dart';
|
||||
import 'package:krezus/pages/data/widgets/account_settings.dart';
|
||||
import 'package:krezus/pages/data/widgets/categories_settings.dart';
|
||||
import 'package:krezus/pages/data/widgets/import_settings.dart';
|
||||
import 'package:krezus/pages/data/widgets/settings_settings.dart';
|
||||
|
||||
class DataPage extends StatelessWidget {
|
||||
const DataPage({super.key});
|
||||
@@ -11,6 +12,7 @@ class DataPage extends StatelessWidget {
|
||||
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
return Center(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 11, horizontal: 0),
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 1000
|
||||
),
|
||||
@@ -24,6 +26,7 @@ class DataPage extends StatelessWidget {
|
||||
fontSize: 35,
|
||||
),
|
||||
),
|
||||
SettingsSettings(),
|
||||
ImportSettings(),
|
||||
AccountSettings(),
|
||||
CategoriesSettings(),
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:tunas/pages/common/titled_container.dart';
|
||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
||||
import 'package:krezus/domains/account/account_bloc.dart';
|
||||
import 'package:krezus/pages/common/editable_color.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 {
|
||||
const AccountSettings({super.key});
|
||||
@@ -10,10 +12,9 @@ class AccountSettings extends StatelessWidget {
|
||||
List<Widget> _computeCategoryList(BuildContext context, List<Account> accounts) {
|
||||
return accounts.map((account) => Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.palette),
|
||||
EditableColor(
|
||||
color: account.rgbToColor(),
|
||||
onChanged: (color) => context.read<AccountBloc>().add(AccountEditColor(account, color.value.toRadixString(16).toUpperCase().padLeft(8, '0'))),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => context.read<AccountBloc>().add(AccountEditSaving(account, !account.saving)),
|
||||
@@ -22,11 +23,12 @@ class AccountSettings extends StatelessWidget {
|
||||
),
|
||||
Container(width: 5),
|
||||
Expanded(
|
||||
child: Text(account.label)
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.edit),
|
||||
child: EditableLabel(
|
||||
initialValue: account.label,
|
||||
onChanged: (value) => context.read<AccountBloc>().add(AccountEditLabel(account, value)),
|
||||
hintText: 'Acount name',
|
||||
keyboardType: TextInputType.text,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => context.read<AccountBloc>().add(AccountRemove(account)),
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/pages/common/titled_container.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/pages/common/editable_color.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 {
|
||||
const CategoriesSettings({super.key});
|
||||
@@ -10,31 +12,31 @@ class CategoriesSettings extends StatelessWidget {
|
||||
List<Widget> _computeCategoryList(BuildContext context, List<Category> categories) {
|
||||
return categories.map((category) => Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.palette),
|
||||
EditableColor(
|
||||
color: category.rgbToColor(),
|
||||
onChanged: (color) => context.read<CategoryBloc>().add(CategoryEditColor(category, color.value.toRadixString(16).toUpperCase().padLeft(8, '0'))),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () => context.read<CategoryBloc>().add(CategoryEditTransfert(category, !category.transfert)),
|
||||
icon: const Icon(Icons.swap_horiz),
|
||||
color: category.transfert ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () => context.read<CategoryBloc>().add(CategoryEditEssential(category, !category.essential)),
|
||||
icon: const Icon(Icons.foundation),
|
||||
color: category.essential ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.error,
|
||||
),
|
||||
Container(width: 5),
|
||||
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(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.edit),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () => context.read<CategoryBloc>().add(CategoryRemove(category)),
|
||||
icon: const Icon(Icons.delete),
|
||||
),
|
||||
],
|
||||
@@ -43,9 +45,30 @@ class CategoriesSettings extends StatelessWidget {
|
||||
|
||||
@override
|
||||
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(
|
||||
title: "Categories",
|
||||
action: IconButton(
|
||||
onPressed: () => context.read<CategoryBloc>().add(CategoryAdd()),
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Column(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:tunas/pages/common/titled_container.dart';
|
||||
import 'package:krezus/domains/account/account_bloc.dart';
|
||||
import 'package:krezus/pages/common/titled_container.dart';
|
||||
|
||||
class ImportSettings extends StatelessWidget {
|
||||
const ImportSettings({super.key});
|
||||
@@ -12,25 +12,36 @@ class ImportSettings extends StatelessWidget {
|
||||
builder: (context, state) => TitledContainer(
|
||||
title: "Import",
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
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()),
|
||||
child: const Text('Import CSV')
|
||||
label: const Text('Import CSV'),
|
||||
icon: const Icon(Icons.upload_file),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
FilledButton(
|
||||
FilledButton.tonalIcon(
|
||||
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),
|
||||
FilledButton(
|
||||
FilledButton.tonalIcon(
|
||||
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),
|
||||
FilledButton(
|
||||
FilledButton.tonalIcon(
|
||||
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_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:tunas/domains/budget/budget_bloc.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/pages/budgets/budgets_page.dart';
|
||||
import 'package:tunas/pages/data/data_page.dart';
|
||||
import 'package:tunas/pages/stats/stats_page.dart';
|
||||
import 'package:tunas/pages/transactions/transactions_page.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:krezus/domains/account/account_bloc.dart';
|
||||
import 'package:krezus/domains/budget/budget_bloc.dart';
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/domains/charts/chart_bloc.dart';
|
||||
import 'package:krezus/domains/settings/settings_bloc.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:krezus/pages/budgets/budgets_page.dart';
|
||||
import 'package:krezus/pages/data/data_page.dart';
|
||||
import 'package:krezus/pages/stats/stats_page.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 {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 1500;
|
||||
return MultiBlocProvider(
|
||||
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) => CategoryBloc(metadataRepository: RepositoryProvider.of<MetadataRepository>(context))),
|
||||
BlocProvider(create: (context) => BudgetBloc(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), 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(
|
||||
length: 4,
|
||||
@@ -36,26 +111,7 @@ class HomePage extends StatelessWidget {
|
||||
DataPage()
|
||||
],
|
||||
),
|
||||
Align(
|
||||
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)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
smallVerticalScreen ? _smallScreenTotalsCharts(context) : _largeScreenTotalsCharts(context),
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/charts/chart_bloc.dart';
|
||||
import 'package:tunas/pages/stats/widgets/account_counters.dart';
|
||||
import 'package:tunas/pages/stats/widgets/categories_totals_chart.dart';
|
||||
import 'package:tunas/pages/stats/widgets/global_counter.dart';
|
||||
import 'package:tunas/pages/stats/widgets/monthly_categories_total_chart.dart';
|
||||
import 'package:tunas/pages/stats/widgets/global_total_chart.dart';
|
||||
import 'package:tunas/pages/stats/widgets/profit_indicator.dart';
|
||||
import 'package:tunas/pages/stats/widgets/year_selector.dart';
|
||||
import 'package:tunas/repositories/metadata/metadata_repository.dart';
|
||||
import 'package:tunas/repositories/transactions/transactions_repository.dart';
|
||||
import 'package:krezus/domains/charts/chart_bloc.dart';
|
||||
import 'package:krezus/pages/stats/widgets/account_counters.dart';
|
||||
import 'package:krezus/pages/stats/widgets/categories_totals_chart.dart';
|
||||
import 'package:krezus/pages/stats/widgets/global_counter.dart';
|
||||
import 'package:krezus/pages/stats/widgets/monthly_categories_total_chart.dart';
|
||||
import 'package:krezus/pages/stats/widgets/global_total_chart.dart';
|
||||
import 'package:krezus/pages/stats/widgets/profit_indicator.dart';
|
||||
import 'package:krezus/pages/stats/widgets/year_selector.dart';
|
||||
|
||||
class StatsPage extends StatelessWidget {
|
||||
const StatsPage({super.key});
|
||||
@@ -82,6 +80,8 @@ class StatsPage extends StatelessWidget {
|
||||
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),
|
||||
@@ -112,28 +112,22 @@ class StatsPage extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
bool smallVerticalScreen = MediaQuery.sizeOf(context).width < 800;
|
||||
return BlocProvider(
|
||||
create: (context) => ChartBloc(
|
||||
metadataRepository: RepositoryProvider.of<MetadataRepository>(context),
|
||||
transactionsRepository: RepositoryProvider.of<TransactionsRepository>(context),
|
||||
),
|
||||
child: 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),
|
||||
],
|
||||
)
|
||||
),
|
||||
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),
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -35,15 +35,6 @@ class AccountCounter extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
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,
|
||||
child: Column(
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/charts/models/chart_item.dart';
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/domains/charts/models/chart_item.dart';
|
||||
|
||||
class CategoriesTotalsChart extends StatelessWidget {
|
||||
final List<ChartItem> categoriesTotals;
|
||||
@@ -71,15 +71,6 @@ class CategoriesTotalsChart extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
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(
|
||||
children: [
|
||||
|
||||
@@ -14,15 +14,6 @@ class GlobalCounter extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
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,
|
||||
child: Text(
|
||||
|
||||
@@ -29,7 +29,7 @@ class GlobalTotalChart extends StatelessWidget {
|
||||
lineTouchData: LineTouchData(
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
maxContentWidth: 100,
|
||||
tooltipBgColor: Theme.of(context).colorScheme.primaryContainer,
|
||||
getTooltipColor: (LineBarSpot _) => Theme.of(context).colorScheme.primaryContainer,
|
||||
getTooltipItems: (touchedSpots) {
|
||||
return touchedSpots.map((LineBarSpot touchedSpot) {
|
||||
final textStyle = TextStyle(
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/charts/models/month_totals.dart';
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/domains/charts/models/month_totals.dart';
|
||||
|
||||
class MonthlyCategoriesTotalChart extends StatelessWidget {
|
||||
final Map<int, MonthTotals> categoriesMonthlyTotals;
|
||||
@@ -94,7 +94,8 @@ class MonthlyCategoriesTotalChart extends StatelessWidget {
|
||||
enabled: true,
|
||||
handleBuiltInTouches: false,
|
||||
touchTooltipData: BarTouchTooltipData(
|
||||
tooltipBgColor: Colors.transparent,
|
||||
// tooltipBgColor: Colors.transparent,
|
||||
getTooltipColor: (BarChartGroupData _) => Colors.transparent,
|
||||
tooltipMargin: 0,
|
||||
getTooltipItem:(group, groupIndex, rod, rodIndex) {
|
||||
String value = NumberFormat("#00").format(rod.toY);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.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 {
|
||||
const YearSelector({super.key});
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transactions_actions.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transactions_header.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transactions_list.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.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 {
|
||||
const TransactionsPage({super.key});
|
||||
@@ -9,20 +11,34 @@ class TransactionsPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MediaQueryData mediaQuery = MediaQuery.of(context);
|
||||
return Center(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: 1000
|
||||
return BlocListener<TransactionBloc, TransactionState>(
|
||||
listenWhen: (previous, current) => previous.showSnackBar != current.showSnackBar,
|
||||
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(),
|
||||
],
|
||||
),
|
||||
),
|
||||
padding: mediaQuery.padding,
|
||||
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_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart' as tunas_category;
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:krezus/repositories/metadata/models/category.dart' as krezus_category;
|
||||
|
||||
class CategoryFilter extends StatelessWidget {
|
||||
const CategoryFilter({super.key});
|
||||
@@ -10,11 +10,12 @@ class CategoryFilter extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final categoryState = context.watch<CategoryBloc>().state;
|
||||
|
||||
return BlocBuilder<TransactionBloc, TransactionState>(
|
||||
buildWhen: (previous, current) => previous.categoryFilter != current.categoryFilter,
|
||||
builder: (context, state) => SizedBox(
|
||||
width: 500,
|
||||
child: DropdownButtonFormField<tunas_category.Category>(
|
||||
width: 300,
|
||||
child: DropdownButtonFormField<krezus_category.Category>(
|
||||
value: state.categoryFilter,
|
||||
onChanged: (value) => context.read<TransactionBloc>().add(TransactionFilterCategory(value!)),
|
||||
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_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transaction_form.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:krezus/domains/account/account_bloc.dart';
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:krezus/pages/transactions/widgets/transaction_form.dart';
|
||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||
|
||||
class TransactionAddDialog extends StatelessWidget {
|
||||
const TransactionAddDialog({super.key});
|
||||
@@ -21,8 +21,8 @@ class TransactionAddDialog extends StatelessWidget {
|
||||
BlocProvider.value(value: BlocProvider.of<CategoryBloc>(context)),
|
||||
BlocProvider.value(value: BlocProvider.of<AccountBloc>(context)),
|
||||
],
|
||||
child: const TransactionAddDialog()
|
||||
)
|
||||
child: const TransactionAddDialog(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,18 +32,18 @@ class TransactionAddDialog extends StatelessWidget {
|
||||
final actions = [
|
||||
IconButton(
|
||||
onPressed: () => TransactionAddDialog.hide(context),
|
||||
icon: const Icon(Icons.close)
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => context.read<TransactionBloc>().add(const TransactionAdd()),
|
||||
icon: const Icon(Icons.save)
|
||||
icon: const Icon(Icons.save),
|
||||
),
|
||||
];
|
||||
|
||||
if (currentTransaction != null) {
|
||||
actions.add(IconButton(
|
||||
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(
|
||||
title: Text(state.currentTransaction == null ? 'Add Transaction' : 'Edit Transaction'),
|
||||
actions: _computeActions(context, state.currentTransaction),
|
||||
content: const TransactionForm()
|
||||
)
|
||||
content: const TransactionForm(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tunas/domains/account/account_bloc.dart';
|
||||
import 'package:tunas/domains/category/category_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:krezus/domains/account/account_bloc.dart';
|
||||
import 'package:krezus/domains/category/category_bloc.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||
|
||||
class TransactionForm extends StatelessWidget {
|
||||
|
||||
@@ -15,13 +15,13 @@ class TransactionForm extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_TransactionDateInput(),
|
||||
const SizedBox(height: 10,),
|
||||
const SizedBox(height: 35,),
|
||||
_TransactionCategoryInput(),
|
||||
const SizedBox(height: 10,),
|
||||
const SizedBox(height: 35,),
|
||||
_TransactionDescriptionInput(),
|
||||
const SizedBox(height: 10,),
|
||||
const SizedBox(height: 35,),
|
||||
_TransactionAccountInput(),
|
||||
const SizedBox(height: 10,),
|
||||
const SizedBox(height: 35,),
|
||||
_TransactionValueInput()
|
||||
],
|
||||
);
|
||||
@@ -37,8 +37,11 @@ class _TransactionDateInput extends StatelessWidget {
|
||||
builder: (context, state) => SizedBox(
|
||||
width: 500,
|
||||
child: TextFormField(
|
||||
initialValue: DateFormat('dd-MM-yyyy', 'fr_FR').format(state.transactionDate.value ?? DateTime.now()),
|
||||
keyboardType: TextInputType.datetime,
|
||||
readOnly: true,
|
||||
controller: TextEditingController(
|
||||
text: DateFormat('dd-MM-yyyy', 'fr_FR').format(state.transactionDate.value ?? DateTime.now()),
|
||||
),
|
||||
onTap: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
showDatePicker(
|
||||
@@ -53,7 +56,7 @@ class _TransactionDateInput extends StatelessWidget {
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
icon: const Icon(Icons.calendar_month),
|
||||
hintText: 'Date',
|
||||
label: const Text('Date'),
|
||||
errorText: state.transactionDate.isNotValid ? state.transactionDate.error?.message : null,
|
||||
border: OutlineInputBorder(
|
||||
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(),
|
||||
decoration: InputDecoration(
|
||||
icon: const Icon(Icons.category),
|
||||
hintText: 'Category',
|
||||
label: const Text('Category'),
|
||||
errorText: state.transactionCategory.isNotValid ? state.transactionCategory.error?.message : null,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
@@ -101,7 +104,7 @@ class _TransactionDescriptionInput extends StatelessWidget {
|
||||
child: TextFormField(
|
||||
decoration: InputDecoration(
|
||||
icon: const Icon(Icons.description),
|
||||
hintText: 'Description',
|
||||
label: const Text('Description'),
|
||||
errorText: state.transactionDescription.isNotValid ? state.transactionDescription.error?.message : null,
|
||||
border: OutlineInputBorder(
|
||||
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(),
|
||||
decoration: InputDecoration(
|
||||
icon: const Icon(Icons.account_box),
|
||||
hintText: 'Account',
|
||||
label: const Text('Account'),
|
||||
errorText: state.transactionAccount.isNotValid ? state.transactionAccount.error?.message : null,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
@@ -152,7 +155,7 @@ class _TransactionValueInput extends StatelessWidget {
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
icon: const Icon(Icons.euro),
|
||||
hintText: '\$\$\$',
|
||||
label: const Text('\$\$\$'),
|
||||
errorText: state.transactionValue.isNotValid ? state.transactionValue.error?.message : null,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:krezus/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||
|
||||
class TransactionLine extends StatelessWidget {
|
||||
final Transaction transaction;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/category_filter.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:krezus/pages/transactions/widgets/account_filter.dart';
|
||||
import 'package:krezus/pages/transactions/widgets/category_filter.dart';
|
||||
import 'package:krezus/pages/transactions/widgets/transaction_add_dialog.dart';
|
||||
|
||||
class TransactionsActions extends StatelessWidget {
|
||||
const TransactionsActions({super.key});
|
||||
@@ -31,6 +32,7 @@ class TransactionsActions extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const CategoryFilter(),
|
||||
const AccountFilter(),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -47,6 +49,7 @@ class TransactionsActions extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const CategoryFilter(),
|
||||
const AccountFilter(),
|
||||
IconButton(
|
||||
onPressed: () => TransactionAddDialog.show(context, null),
|
||||
icon: const Icon(
|
||||
|
||||
@@ -57,8 +57,13 @@ class TransactionsHeader extends StatelessWidget {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 9, horizontal: 10),
|
||||
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 10),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.black))
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
width: 2,
|
||||
color: Theme.of(context).colorScheme.onPrimaryContainer
|
||||
)
|
||||
)
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:tunas/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:tunas/pages/transactions/widgets/transaction_line.dart';
|
||||
import 'package:krezus/domains/transaction/transaction_bloc.dart';
|
||||
import 'package:krezus/pages/transactions/widgets/transaction_line.dart';
|
||||
|
||||
class TransactionsList extends StatelessWidget {
|
||||
const TransactionsList({super.key});
|
||||
@@ -15,10 +15,10 @@ class TransactionsList extends StatelessWidget {
|
||||
itemCount: state.transactionsLinesFiltered.length,
|
||||
itemBuilder: (context, index) => TransactionLine(
|
||||
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 'package:tunas/clients/storage/storage_client.dart';
|
||||
import 'package:tunas/repositories/json/models/json.dart';
|
||||
import 'package:krezus/clients/storage/json_storage_client.dart';
|
||||
import 'package:krezus/repositories/json/models/json.dart';
|
||||
|
||||
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({
|
||||
required storageClient,
|
||||
}) : _storageClient = storageClient;
|
||||
|
||||
saveJson(Json json) async {
|
||||
await _storageClient.save(json.getJsonFileName(), jsonEncode(json.toJson()));
|
||||
void saveJson(Json json) {
|
||||
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 {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import 'package:rxdart/subjects.dart';
|
||||
import 'package:tunas/repositories/json/json_repository.dart';
|
||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
||||
import 'package:tunas/repositories/metadata/models/metadata.dart';
|
||||
import 'package:krezus/repositories/json/json_repository.dart';
|
||||
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||
import 'package:krezus/repositories/metadata/models/metadata.dart';
|
||||
import 'package:krezus/repositories/metadata/models/settings.dart';
|
||||
|
||||
class MetadataRepository {
|
||||
|
||||
@@ -11,15 +12,24 @@ class MetadataRepository {
|
||||
final _categoriesController = BehaviorSubject<List<Category>>.seeded(const []);
|
||||
final _budgetController = BehaviorSubject<List<Budget>>.seeded(const []);
|
||||
final _accountController = BehaviorSubject<List<Account>>.seeded(const []);
|
||||
final _settingsController = BehaviorSubject<Settings>.seeded(const Settings());
|
||||
|
||||
MetadataRepository({
|
||||
required jsonRepository,
|
||||
}) : _jsonRepository = jsonRepository;
|
||||
|
||||
List<Category> getCategories() {
|
||||
return _categoriesController.value;
|
||||
}
|
||||
|
||||
Stream<List<Category>> getCategoriesStream() {
|
||||
return _categoriesController.asBroadcastStream();
|
||||
}
|
||||
|
||||
List<Budget> getBudgets() {
|
||||
return _budgetController.value;
|
||||
}
|
||||
|
||||
Stream<List<Budget>> getBudgetsStream() {
|
||||
return _budgetController.asBroadcastStream();
|
||||
}
|
||||
@@ -32,42 +42,62 @@ class MetadataRepository {
|
||||
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());
|
||||
_broadcastMetadata(metadata);
|
||||
}
|
||||
|
||||
saveCategories(List<Category> categories) async {
|
||||
List<Category> saveCategories(List<Category> categories) {
|
||||
Metadata metadata = _constructMetadataFromControllers();
|
||||
metadata.categories = categories;
|
||||
await _jsonRepository.saveJson(metadata);
|
||||
_jsonRepository.saveJson(metadata);
|
||||
_categoriesController.add(categories);
|
||||
return categories;
|
||||
}
|
||||
|
||||
saveBudgets(List<Budget> budgets) async {
|
||||
List<Budget> saveBudgets(List<Budget> budgets) {
|
||||
Metadata metadata = _constructMetadataFromControllers();
|
||||
metadata.budgets = budgets;
|
||||
await _jsonRepository.saveJson(metadata);
|
||||
_jsonRepository.saveJson(metadata);
|
||||
_budgetController.add(budgets);
|
||||
return budgets;
|
||||
}
|
||||
|
||||
saveAccounts(List<Account> accounts) async {
|
||||
List<Account> saveAccounts(List<Account> accounts) {
|
||||
Metadata metadata = _constructMetadataFromControllers();
|
||||
metadata.accounts = accounts;
|
||||
await _jsonRepository.saveJson(metadata);
|
||||
_jsonRepository.saveJson(metadata);
|
||||
_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();
|
||||
await _jsonRepository.saveJson(metadata);
|
||||
_jsonRepository.saveJson(metadata);
|
||||
_broadcastMetadata(metadata);
|
||||
}
|
||||
|
||||
_broadcastMetadata(Metadata metadata) {
|
||||
void _broadcastMetadata(Metadata metadata) {
|
||||
_categoriesController.add(metadata.categories);
|
||||
_budgetController.add(metadata.budgets);
|
||||
_accountController.add(metadata.accounts);
|
||||
_settingsController.add(metadata.settings);
|
||||
}
|
||||
|
||||
Metadata _constructMetadataFromControllers() {
|
||||
@@ -75,6 +105,7 @@ class MetadataRepository {
|
||||
categories: _categoriesController.value,
|
||||
budgets: _budgetController.value,
|
||||
accounts: _accountController.value,
|
||||
settings: _settingsController.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,13 @@ class Account {
|
||||
String label;
|
||||
String color;
|
||||
bool saving;
|
||||
double interest;
|
||||
|
||||
Account({
|
||||
this.label = '',
|
||||
this.color = '',
|
||||
this.saving = false,
|
||||
this.interest = 0.0,
|
||||
});
|
||||
|
||||
factory Account.fromJson(Map<String, dynamic> json) {
|
||||
@@ -16,6 +18,7 @@ class Account {
|
||||
label: json['label'],
|
||||
color: json['color'],
|
||||
saving: bool.parse(json['saving']),
|
||||
interest: double.parse(json['intereset']),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -23,6 +26,7 @@ class Account {
|
||||
'label': label,
|
||||
'color': color,
|
||||
'saving': saving.toString(),
|
||||
'intereset': interest.toString(),
|
||||
};
|
||||
|
||||
Color rgbToColor() {
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
class Budget {
|
||||
String label;
|
||||
bool monthly;
|
||||
double value;
|
||||
|
||||
Budget({
|
||||
this.label = '',
|
||||
this.monthly = false,
|
||||
this.value = 0.0,
|
||||
});
|
||||
|
||||
factory Budget.fromJson(Map<String, dynamic> json) {
|
||||
return Budget(
|
||||
monthly: json['monthly'],
|
||||
label: json['label'],
|
||||
monthly: bool.parse(json['monthly']),
|
||||
value: double.parse(json['value']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {
|
||||
'label': label,
|
||||
'monthly': monthly.toString(),
|
||||
'value': value.toString(),
|
||||
};
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import 'package:tunas/repositories/metadata/models/budget.dart';
|
||||
import 'package:tunas/repositories/metadata/models/category.dart';
|
||||
import 'package:tunas/repositories/json/models/json.dart';
|
||||
import 'package:tunas/repositories/metadata/models/account.dart';
|
||||
import 'package:krezus/repositories/metadata/models/budget.dart';
|
||||
import 'package:krezus/repositories/metadata/models/category.dart';
|
||||
import 'package:krezus/repositories/json/models/json.dart';
|
||||
import 'package:krezus/repositories/metadata/models/account.dart';
|
||||
import 'package:krezus/repositories/metadata/models/settings.dart';
|
||||
|
||||
class Metadata implements Json {
|
||||
List<Budget> budgets;
|
||||
List<Category> categories;
|
||||
List<Account> accounts;
|
||||
Settings settings;
|
||||
|
||||
Metadata({
|
||||
this.budgets = const [],
|
||||
this.categories = const [],
|
||||
this.accounts = const [],
|
||||
this.settings = const Settings(),
|
||||
});
|
||||
|
||||
@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';
|
||||
|
||||
class Transaction {
|
||||
String uuid;
|
||||
DateTime date;
|
||||
String category;
|
||||
String description;
|
||||
String account;
|
||||
double value;
|
||||
class Transaction extends Equatable {
|
||||
final String uuid;
|
||||
final DateTime date;
|
||||
final String category;
|
||||
final String description;
|
||||
final String account;
|
||||
final double value;
|
||||
|
||||
Transaction({
|
||||
const Transaction({
|
||||
required this.uuid,
|
||||
required this.date,
|
||||
required this.category,
|
||||
@@ -36,4 +37,7 @@ class Transaction {
|
||||
'account': account,
|
||||
'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:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:krezus/repositories/json/models/json.dart';
|
||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||
|
||||
class Transactions implements Json {
|
||||
List<Transaction> transactions;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:rxdart/subjects.dart';
|
||||
import 'package:tunas/repositories/json/json_repository.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transaction.dart';
|
||||
import 'package:tunas/repositories/transactions/models/transactions.dart';
|
||||
import 'package:krezus/repositories/json/json_repository.dart';
|
||||
import 'package:krezus/repositories/transactions/models/transaction.dart';
|
||||
import 'package:krezus/repositories/transactions/models/transactions.dart';
|
||||
|
||||
class TransactionsRepository {
|
||||
|
||||
@@ -20,20 +20,20 @@ class TransactionsRepository {
|
||||
return _transactionsController.asBroadcastStream();
|
||||
}
|
||||
|
||||
loadTransactions() async {
|
||||
Future<void> loadTransactions() async {
|
||||
Transactions transactions = await _jsonRepository.loadJson(Transactions(), TransactionsFactory());
|
||||
_transactionsController.add(transactions.transactions);
|
||||
}
|
||||
|
||||
saveTransactions(List<Transaction> transactionsList) async {
|
||||
void saveTransactions(List<Transaction> transactionsList) {
|
||||
Transactions transactions = Transactions(transactions: transactionsList);
|
||||
await _jsonRepository.saveJson(transactions);
|
||||
_jsonRepository.saveJson(transactions);
|
||||
_transactionsController.add(transactionsList);
|
||||
}
|
||||
|
||||
deleteTransactions() async {
|
||||
void deleteTransactions() {
|
||||
Transactions transactions = Transactions();
|
||||
await _jsonRepository.saveJson(transactions);
|
||||
_jsonRepository.saveJson(transactions);
|
||||
_transactionsController.add([]);
|
||||
}
|
||||
}
|
||||
@@ -4,10 +4,10 @@ project(runner LANGUAGES CXX)
|
||||
|
||||
# The name of the executable created for the application. Change this to change
|
||||
# the on-disk name of your application.
|
||||
set(BINARY_NAME "tunas")
|
||||
set(BINARY_NAME "krezus")
|
||||
# The unique GTK application identifier for this application. See:
|
||||
# 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
|
||||
# versions of CMake.
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <dynamic_color/dynamic_color_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) dynamic_color_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "DynamicColorPlugin");
|
||||
dynamic_color_plugin_register_with_registrar(dynamic_color_registrar);
|
||||
}
|
||||
|
||||