mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -171,4 +171,20 @@ class AccountRepository {
|
|||||||
createdAt: Value(account.createdAt),
|
createdAt: Value(account.createdAt),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> add(model.Account account) async {
|
||||||
|
await _db.into(_db.accounts).insert(
|
||||||
|
AccountsCompanion.insert(
|
||||||
|
id: Value(account.id),
|
||||||
|
name: account.name,
|
||||||
|
isMain: Value(account.isMain),
|
||||||
|
currency: Value(account.currency),
|
||||||
|
sortOrder: Value(account.sortOrder),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> delete(int id) async {
|
||||||
|
await (_db.delete(_db.accounts)..where((a) => a.id.equals(id))).go();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:drift/drift.dart' as drift;
|
|
||||||
import '../../core/l10n/locale_provider.dart';
|
import '../../core/l10n/locale_provider.dart';
|
||||||
import '../../core/services/card_color_service.dart';
|
import '../../core/services/card_color_service.dart';
|
||||||
import '../../core/services/haptic_service.dart';
|
import '../../core/services/haptic_service.dart';
|
||||||
import '../../data/database/app_database.dart' hide Account;
|
|
||||||
import '../../shared/models/account.dart';
|
import '../../shared/models/account.dart';
|
||||||
import '../settings/provider.dart';
|
import '../settings/provider.dart';
|
||||||
import 'provider.dart';
|
import 'provider.dart';
|
||||||
@@ -163,23 +161,23 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
|
|
||||||
if (isAddingAccount) {
|
if (isAddingAccount) {
|
||||||
// Create new account
|
// Create new account
|
||||||
final newId = DateTime.now().millisecondsSinceEpoch;
|
final newAccount = Account(
|
||||||
|
id: DateTime.now().millisecondsSinceEpoch,
|
||||||
// Insert the new account using Drift's insert method
|
|
||||||
final db = ref.read(appDatabaseProvider);
|
|
||||||
await db.into(db.accounts).insert(
|
|
||||||
AccountsCompanion.insert(
|
|
||||||
id: drift.Value(newId),
|
|
||||||
name: tempAccountName.trim(),
|
name: tempAccountName.trim(),
|
||||||
isMain: const drift.Value(false),
|
isMain: false,
|
||||||
currency: drift.Value(tempAccountCurrency),
|
sortOrder: 99,
|
||||||
sortOrder: const drift.Value(99),
|
currency: tempAccountCurrency,
|
||||||
),
|
createdAt: DateTime.now(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Save the chosen colors for the newly created account
|
await ref.read(accountRepositoryProvider).add(newAccount);
|
||||||
|
|
||||||
|
// FIX: Fetch the actual ID assigned by the database to save colors correctly
|
||||||
|
final accounts = await ref.read(accountRepositoryProvider).getAll();
|
||||||
|
final actualNewAccount = accounts.lastWhere((a) => a.name == tempAccountName.trim());
|
||||||
|
|
||||||
await ref
|
await ref
|
||||||
.read(accountCardColorsProvider(newId).notifier)
|
.read(accountCardColorsProvider(actualNewAccount.id).notifier)
|
||||||
.save(tempPrimary, tempSecondary, tempGradientType);
|
.save(tempPrimary, tempSecondary, tempGradientType);
|
||||||
} else if (editingAccount != null) {
|
} else if (editingAccount != null) {
|
||||||
// Existing edit logic
|
// Existing edit logic
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
late String _selectedCurrency;
|
late String _selectedCurrency;
|
||||||
bool _showCurrencyDropdown = false;
|
bool _showCurrencyDropdown = false;
|
||||||
bool _showLimitError = false;
|
bool _showLimitError = false;
|
||||||
|
bool _showDeleteDialog = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -260,12 +261,41 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Close Button - Top Right
|
// Top Right Buttons (Delete & Close)
|
||||||
Positioned(
|
Positioned(
|
||||||
top: mq.padding.top + 8,
|
top: mq.padding.top + 8,
|
||||||
right: 20,
|
right: 20,
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: GestureDetector(
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
if (!dash.isAddingAccount && (ref.watch(accountsProvider).valueOrNull?.length ?? 0) > 1) ...[
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () => setState(() => _showDeleteDialog = true),
|
||||||
|
child: Container(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(widget.context).colorScheme.surface,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.red.withOpacity(0.2),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.delete_outline_rounded,
|
||||||
|
size: 22,
|
||||||
|
color: Colors.red,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 12),
|
||||||
|
],
|
||||||
|
GestureDetector(
|
||||||
onTap: () => dash.closeAccountOverlay(apply: false),
|
onTap: () => dash.closeAccountOverlay(apply: false),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 40,
|
width: 40,
|
||||||
@@ -288,6 +318,58 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Custom Dialog Overlay
|
||||||
|
if (_showDeleteDialog)
|
||||||
|
Positioned.fill(
|
||||||
|
child: Container(
|
||||||
|
color: Colors.black.withOpacity(0.4),
|
||||||
|
child: Center(
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: AlertDialog(
|
||||||
|
backgroundColor: Theme.of(widget.context).colorScheme.surface,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
title: const Text('Delete Account?'),
|
||||||
|
content: const Text(
|
||||||
|
'Are you sure you want to delete this account? All associated transactions will also be permanently deleted.',
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => setState(() => _showDeleteDialog = false),
|
||||||
|
child: const Text('Cancel'),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
if (dash.editingAccount == null) return;
|
||||||
|
|
||||||
|
final accountId = dash.editingAccount!.id;
|
||||||
|
|
||||||
|
dash.closeAccountOverlay(apply: false);
|
||||||
|
|
||||||
|
final txs = ref.read(transactionsProvider).valueOrNull ?? [];
|
||||||
|
final accountTxs = txs.where((t) => t.accountId == accountId).toList();
|
||||||
|
for (final t in accountTxs) {
|
||||||
|
await ref.read(transactionsProvider.notifier).delete(t.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
await ref.read(accountRepositoryProvider).delete(accountId);
|
||||||
|
|
||||||
|
if (ref.read(hapticEnabledProvider)) {
|
||||||
|
HapticService.medium();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('Delete', style: TextStyle(color: Colors.red)),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -298,6 +380,8 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEditorPanel(double panelHeight) {
|
Widget _buildEditorPanel(double panelHeight) {
|
||||||
|
return Consumer(
|
||||||
|
builder: (context, ref, _) {
|
||||||
return Container(
|
return Container(
|
||||||
height: panelHeight,
|
height: panelHeight,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -423,6 +507,8 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildColorPanel(double panelHeight) {
|
Widget _buildColorPanel(double panelHeight) {
|
||||||
@@ -521,7 +607,8 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
GestureDetector(
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
onTap: isSolid ? null : () {
|
onTap: isSolid ? null : () {
|
||||||
dash.setState(() {
|
dash.setState(() {
|
||||||
dash.tempGradientType = GradientType.solid;
|
dash.tempGradientType = GradientType.solid;
|
||||||
@@ -533,7 +620,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
height: double.infinity,
|
height: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 10, vertical: 6),
|
horizontal: 4, vertical: 6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isSolid
|
color: isSolid
|
||||||
? const Color(0xFF7C6DED).withOpacity(0.15)
|
? const Color(0xFF7C6DED).withOpacity(0.15)
|
||||||
@@ -568,6 +655,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -937,7 +1025,7 @@ class PanelTab extends StatelessWidget {
|
|||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 150),
|
duration: const Duration(milliseconds: 150),
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isSelected ? const Color(0xFF7C6DED).withOpacity(0.15) : Colors.transparent,
|
color: isSelected ? const Color(0xFF7C6DED).withOpacity(0.15) : Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
|||||||
Reference in New Issue
Block a user