mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 18:35:28 +03:00
update
This commit is contained in:
@@ -2,9 +2,11 @@ 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';
|
||||||
@@ -52,6 +54,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
Account? editingAccount;
|
Account? editingAccount;
|
||||||
String tempAccountName = '';
|
String tempAccountName = '';
|
||||||
String tempAccountCurrency = 'USD';
|
String tempAccountCurrency = 'USD';
|
||||||
|
bool isAddingAccount = false;
|
||||||
|
|
||||||
void _onCardLongPress() {
|
void _onCardLongPress() {
|
||||||
final colors = ref.read(cardColorsProvider);
|
final colors = ref.read(cardColorsProvider);
|
||||||
@@ -130,10 +133,56 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
Overlay.of(context, rootOverlay: true).insert(overlayEntry!);
|
Overlay.of(context, rootOverlay: true).insert(overlayEntry!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onAddAccountTapped() {
|
||||||
|
final colors = ref.read(cardColorsProvider);
|
||||||
|
savedPrimary = colors.primary;
|
||||||
|
savedSecondary = colors.secondary;
|
||||||
|
savedPrimaryHSV = HSVColor.fromColor(colors.primary);
|
||||||
|
savedSecondaryHSV = HSVColor.fromColor(colors.secondary);
|
||||||
|
savedGradientType = colors.gradientType;
|
||||||
|
tempPrimary = colors.primary;
|
||||||
|
tempSecondary = colors.secondary;
|
||||||
|
tempPrimaryHSV = HSVColor.fromColor(colors.primary);
|
||||||
|
tempSecondaryHSV = HSVColor.fromColor(colors.secondary);
|
||||||
|
tempGradientType = colors.gradientType;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
isAddingAccount = true;
|
||||||
|
editingAccount = null;
|
||||||
|
tempAccountName = '';
|
||||||
|
tempAccountCurrency = ref.read(currencyProvider).code;
|
||||||
|
editingCard = true;
|
||||||
|
editingPrimary = true;
|
||||||
|
});
|
||||||
|
_showAccountOverlay();
|
||||||
|
}
|
||||||
|
|
||||||
void closeAccountOverlay({required bool apply}) async {
|
void closeAccountOverlay({required bool apply}) async {
|
||||||
if (apply && editingAccount != null) {
|
if (apply && tempAccountName.trim().isNotEmpty) {
|
||||||
HapticService.medium();
|
HapticService.medium();
|
||||||
|
|
||||||
|
if (isAddingAccount) {
|
||||||
|
// Create new account
|
||||||
|
final newId = 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(),
|
||||||
|
isMain: const drift.Value(false),
|
||||||
|
currency: drift.Value(tempAccountCurrency),
|
||||||
|
sortOrder: const drift.Value(99),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Save the chosen colors for the newly created account
|
||||||
|
await ref
|
||||||
|
.read(accountCardColorsProvider(newId).notifier)
|
||||||
|
.save(tempPrimary, tempSecondary, tempGradientType);
|
||||||
|
} else if (editingAccount != null) {
|
||||||
|
// Existing edit logic
|
||||||
// Save colors
|
// Save colors
|
||||||
await ref
|
await ref
|
||||||
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
.read(accountCardColorsProvider(editingAccount!.id).notifier)
|
||||||
@@ -142,7 +191,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
// Update account name and currency
|
// Update account name and currency
|
||||||
final updatedAccount = Account(
|
final updatedAccount = Account(
|
||||||
id: editingAccount!.id,
|
id: editingAccount!.id,
|
||||||
name: tempAccountName,
|
name: tempAccountName.trim(),
|
||||||
isMain: editingAccount!.isMain,
|
isMain: editingAccount!.isMain,
|
||||||
sortOrder: editingAccount!.sortOrder,
|
sortOrder: editingAccount!.sortOrder,
|
||||||
currency: tempAccountCurrency,
|
currency: tempAccountCurrency,
|
||||||
@@ -150,6 +199,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await ref.read(accountRepositoryProvider).update(updatedAccount);
|
await ref.read(accountRepositoryProvider).update(updatedAccount);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Restore original values on cancel
|
// Restore original values on cancel
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -168,6 +218,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
editingCard = false;
|
editingCard = false;
|
||||||
editingAccount = null;
|
editingAccount = null;
|
||||||
|
isAddingAccount = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +338,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
|
|||||||
currencyInfo: currencyInfo,
|
currencyInfo: currencyInfo,
|
||||||
onLongPress: _onCardLongPress,
|
onLongPress: _onCardLongPress,
|
||||||
onAccountLongPress: _onAccountCardLongPress,
|
onAccountLongPress: _onAccountCardLongPress,
|
||||||
|
onAddAccountTap: _onAddAccountTapped,
|
||||||
previewPrimary: editingCard ? tempPrimary : null,
|
previewPrimary: editingCard ? tempPrimary : null,
|
||||||
previewSecondary: editingCard ? tempSecondary : null,
|
previewSecondary: editingCard ? tempSecondary : null,
|
||||||
previewGradientType: editingCard
|
previewGradientType: editingCard
|
||||||
|
|||||||
@@ -345,7 +345,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: _showLimitError
|
color: (_showLimitError || _nameController.text.trim().isEmpty)
|
||||||
? Colors.red
|
? Colors.red
|
||||||
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
|
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
|
||||||
width: 1.5,
|
width: 1.5,
|
||||||
@@ -354,7 +354,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: _showLimitError
|
color: (_showLimitError || _nameController.text.trim().isEmpty)
|
||||||
? Colors.red
|
? Colors.red
|
||||||
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
|
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
|
||||||
width: 1.5,
|
width: 1.5,
|
||||||
@@ -363,7 +363,7 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: _showLimitError
|
color: (_showLimitError || _nameController.text.trim().isEmpty)
|
||||||
? Colors.red
|
? Colors.red
|
||||||
: const Color(0xFF7C6DED),
|
: const Color(0xFF7C6DED),
|
||||||
width: 1.5,
|
width: 1.5,
|
||||||
@@ -879,7 +879,8 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
|
|||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12)),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
),
|
),
|
||||||
child: Text(s.apply,
|
child: Text(
|
||||||
|
dash.isAddingAccount ? 'Создать счёт' : s.apply,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.w700, fontSize: 14)),
|
fontWeight: FontWeight.w700, fontSize: 14)),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class BalanceCardCarousel extends ConsumerStatefulWidget {
|
|||||||
final CurrencyInfo currencyInfo;
|
final CurrencyInfo currencyInfo;
|
||||||
final VoidCallback? onLongPress;
|
final VoidCallback? onLongPress;
|
||||||
final void Function(Account)? onAccountLongPress;
|
final void Function(Account)? onAccountLongPress;
|
||||||
|
final VoidCallback? onAddAccountTap;
|
||||||
final Color? previewPrimary;
|
final Color? previewPrimary;
|
||||||
final Color? previewSecondary;
|
final Color? previewSecondary;
|
||||||
final GradientType? previewGradientType;
|
final GradientType? previewGradientType;
|
||||||
@@ -23,6 +24,7 @@ class BalanceCardCarousel extends ConsumerStatefulWidget {
|
|||||||
required this.currencyInfo,
|
required this.currencyInfo,
|
||||||
this.onLongPress,
|
this.onLongPress,
|
||||||
this.onAccountLongPress,
|
this.onAccountLongPress,
|
||||||
|
this.onAddAccountTap,
|
||||||
this.previewPrimary,
|
this.previewPrimary,
|
||||||
this.previewSecondary,
|
this.previewSecondary,
|
||||||
this.previewGradientType,
|
this.previewGradientType,
|
||||||
@@ -117,7 +119,7 @@ class _BalanceCardCarouselState extends ConsumerState<BalanceCardCarousel> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
cardWidget = AddAccountCard(
|
cardWidget = AddAccountCard(
|
||||||
onTap: () {},
|
onTap: widget.onAddAccountTap,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,11 +179,13 @@ class AddAccountCard extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 15), // makes it smaller
|
||||||
child: CustomPaint(
|
child: CustomPaint(
|
||||||
painter: _DashedBorderPainter(),
|
painter: _DashedBorderPainter(),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
height: 220,
|
height: 190, // reduced from 220
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface.withOpacity(0.4),
|
color: Theme.of(context).colorScheme.surface.withOpacity(0.4),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
@@ -207,6 +211,7 @@ class AddAccountCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user