This commit is contained in:
2026-03-24 12:02:46 +03:00
parent c295649128
commit 6750b996fc
3 changed files with 288 additions and 230 deletions
+43 -27
View File
@@ -33,11 +33,17 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
Color tempPrimary = CardColorService.defaultPrimary; Color tempPrimary = CardColorService.defaultPrimary;
Color tempSecondary = CardColorService.defaultSecondary; Color tempSecondary = CardColorService.defaultSecondary;
HSVColor tempPrimaryHSV = HSVColor.fromColor(CardColorService.defaultPrimary); HSVColor tempPrimaryHSV = HSVColor.fromColor(CardColorService.defaultPrimary);
HSVColor tempSecondaryHSV = HSVColor.fromColor(CardColorService.defaultSecondary); HSVColor tempSecondaryHSV = HSVColor.fromColor(
CardColorService.defaultSecondary,
);
Color savedPrimary = CardColorService.defaultPrimary; Color savedPrimary = CardColorService.defaultPrimary;
Color savedSecondary = CardColorService.defaultSecondary; Color savedSecondary = CardColorService.defaultSecondary;
HSVColor savedPrimaryHSV = HSVColor.fromColor(CardColorService.defaultPrimary); HSVColor savedPrimaryHSV = HSVColor.fromColor(
HSVColor savedSecondaryHSV = HSVColor.fromColor(CardColorService.defaultSecondary); CardColorService.defaultPrimary,
);
HSVColor savedSecondaryHSV = HSVColor.fromColor(
CardColorService.defaultSecondary,
);
GradientType tempGradientType = CardColorService.defaultGradient; GradientType tempGradientType = CardColorService.defaultGradient;
GradientType savedGradientType = CardColorService.defaultGradient; GradientType savedGradientType = CardColorService.defaultGradient;
OverlayEntry? overlayEntry; OverlayEntry? overlayEntry;
@@ -59,7 +65,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
tempPrimaryHSV = HSVColor.fromColor(colors.primary); tempPrimaryHSV = HSVColor.fromColor(colors.primary);
tempSecondaryHSV = HSVColor.fromColor(colors.secondary); tempSecondaryHSV = HSVColor.fromColor(colors.secondary);
tempGradientType = colors.gradientType; tempGradientType = colors.gradientType;
setState(() { setState(() {
editingCard = true; editingCard = true;
editingPrimary = true; editingPrimary = true;
@@ -69,10 +75,8 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
void _showOverlay() { void _showOverlay() {
overlayEntry = OverlayEntry( overlayEntry = OverlayEntry(
builder: (overlayContext) => FullScreenBlurOverlay( builder: (overlayContext) =>
dashboardState: this, FullScreenBlurOverlay(dashboardState: this, context: context),
context: context,
),
); );
Overlay.of(context, rootOverlay: true).insert(overlayEntry!); Overlay.of(context, rootOverlay: true).insert(overlayEntry!);
} }
@@ -80,7 +84,9 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
void closeOverlay({required bool apply}) { void closeOverlay({required bool apply}) {
if (apply) { if (apply) {
HapticService.medium(); HapticService.medium();
ref.read(cardColorsProvider.notifier).save(tempPrimary, tempSecondary, tempGradientType); ref
.read(cardColorsProvider.notifier)
.save(tempPrimary, tempSecondary, tempGradientType);
} else { } else {
setState(() { setState(() {
tempPrimary = savedPrimary; tempPrimary = savedPrimary;
@@ -105,7 +111,7 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
tempPrimaryHSV = HSVColor.fromColor(colors.primary); tempPrimaryHSV = HSVColor.fromColor(colors.primary);
tempSecondaryHSV = HSVColor.fromColor(colors.secondary); tempSecondaryHSV = HSVColor.fromColor(colors.secondary);
tempGradientType = colors.gradientType; tempGradientType = colors.gradientType;
setState(() { setState(() {
editingAccount = account; editingAccount = account;
tempAccountName = account.name; tempAccountName = account.name;
@@ -118,10 +124,8 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
void _showAccountOverlay() { void _showAccountOverlay() {
overlayEntry = OverlayEntry( overlayEntry = OverlayEntry(
builder: (overlayContext) => AccountEditorOverlay( builder: (overlayContext) =>
dashboardState: this, AccountEditorOverlay(dashboardState: this, context: context),
context: context,
),
); );
Overlay.of(context, rootOverlay: true).insert(overlayEntry!); Overlay.of(context, rootOverlay: true).insert(overlayEntry!);
} }
@@ -129,14 +133,12 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
void closeAccountOverlay({required bool apply}) async { void closeAccountOverlay({required bool apply}) async {
if (apply && editingAccount != null) { if (apply && editingAccount != null) {
HapticService.medium(); HapticService.medium();
// Save colors // Save colors
await ref.read(accountCardColorsProvider(editingAccount!.id).notifier).save( await ref
tempPrimary, .read(accountCardColorsProvider(editingAccount!.id).notifier)
tempSecondary, .save(tempPrimary, tempSecondary, tempGradientType);
tempGradientType,
);
// Update account name and currency // Update account name and currency
final updatedAccount = Account( final updatedAccount = Account(
id: editingAccount!.id, id: editingAccount!.id,
@@ -146,16 +148,21 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
currency: tempAccountCurrency, currency: tempAccountCurrency,
createdAt: editingAccount!.createdAt, createdAt: editingAccount!.createdAt,
); );
await ref.read(accountRepositoryProvider).update(updatedAccount); await ref.read(accountRepositoryProvider).update(updatedAccount);
} else { } else {
// Restore original values on cancel
setState(() { setState(() {
tempPrimary = savedPrimary; tempPrimary = savedPrimary;
tempSecondary = savedSecondary; tempSecondary = savedSecondary;
tempGradientType = savedGradientType; tempGradientType = savedGradientType;
if (editingAccount != null) {
tempAccountName = editingAccount!.name;
tempAccountCurrency = editingAccount!.currency;
}
}); });
} }
overlayEntry?.remove(); overlayEntry?.remove();
overlayEntry = null; overlayEntry = null;
setState(() { setState(() {
@@ -224,12 +231,19 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
child: Center( child: Center(
child: Builder( child: Builder(
builder: (context) { builder: (context) {
final raw = DateFormat('LLLL, yyyy', s.dateLocale).format(DateTime.now()); final raw = DateFormat(
final capitalized = raw.isNotEmpty ? '${raw[0].toUpperCase()}${raw.substring(1)}' : raw; 'LLLL, yyyy',
s.dateLocale,
).format(DateTime.now());
final capitalized = raw.isNotEmpty
? '${raw[0].toUpperCase()}${raw.substring(1)}'
: raw;
return Text( return Text(
capitalized, capitalized,
style: Theme.of(context).textTheme.bodyMedium?.copyWith( style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5), color: Theme.of(
context,
).colorScheme.onSurface.withOpacity(0.5),
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
), ),
); );
@@ -268,7 +282,9 @@ class _DashboardScreenState extends ConsumerState<DashboardScreen> {
onAccountLongPress: _onAccountCardLongPress, onAccountLongPress: _onAccountCardLongPress,
previewPrimary: editingCard ? tempPrimary : null, previewPrimary: editingCard ? tempPrimary : null,
previewSecondary: editingCard ? tempSecondary : null, previewSecondary: editingCard ? tempSecondary : null,
previewGradientType: editingCard ? tempGradientType : null, previewGradientType: editingCard
? tempGradientType
: null,
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
SummaryRow( SummaryRow(
@@ -5,6 +5,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/l10n/app_strings.dart'; import '../../../core/l10n/app_strings.dart';
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 '../../../shared/models/transaction.dart';
import '../../settings/provider.dart'; import '../../settings/provider.dart';
import '../provider.dart'; import '../provider.dart';
import 'balance_card.dart'; import 'balance_card.dart';
@@ -32,15 +33,35 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
dynamic get dash => widget.dashboardState; dynamic get dash => widget.dashboardState;
late TextEditingController _nameController; late TextEditingController _nameController;
late String _selectedCurrency; late String _selectedCurrency;
late String _originalCurrency;
bool _showCurrencyDropdown = false; bool _showCurrencyDropdown = false;
bool _showLimitError = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_nameController = TextEditingController(text: dash.tempAccountName); _nameController = TextEditingController(text: dash.tempAccountName);
_selectedCurrency = dash.tempAccountCurrency; _selectedCurrency = dash.tempAccountCurrency;
_originalCurrency = dash.tempAccountCurrency;
_nameController.addListener(() { _nameController.addListener(() {
dash.tempAccountName = _nameController.text; final text = _nameController.text;
if (text.length > 17) {
_nameController.text = text.substring(0, 17);
_nameController.selection = TextSelection.fromPosition(
const TextPosition(offset: 17),
);
setState(() => _showLimitError = true);
Future.delayed(const Duration(seconds: 2), () {
if (mounted) setState(() => _showLimitError = false);
});
return; // Skip updating dash to avoid out-of-bounds
}
// Real-time update on card
dash.setState(() {
dash.tempAccountName = _nameController.text;
});
dash.overlayEntry?.markNeedsBuild();
}); });
} }
@@ -60,90 +81,107 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
final colorPanelTop = editorPanelTop + editorPanelHeight + 12; final colorPanelTop = editorPanelTop + editorPanelHeight + 12;
const colorPanelHeight = 410.0; const colorPanelHeight = 410.0;
return Material( return Consumer(
color: Colors.transparent, builder: (context, ref, _) {
child: Stack( final exchangeService = ref.watch(exchangeRateServiceProvider);
children: [
Positioned.fill( // Get the original balance from the editing account
child: BackdropFilter( double originalBalance = ref.read(totalBalanceProvider);
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20), if (dash.editingAccount != null) {
child: Container(color: Colors.black.withOpacity(0.6)), // Get the account's actual balance
), final txs = ref.watch(accountFilteredTransactionsProvider);
), final accountTxs = txs.where((t) => t.accountId == dash.editingAccount!.id);
Positioned.fill( originalBalance = accountTxs.fold<double>(
child: GestureDetector( 0.0,
onTap: () { (sum, t) => sum + (t.type == TransactionType.income ? t.amount : -t.amount),
if (_showCurrencyDropdown) { );
setState(() { }
_showCurrencyDropdown = false;
}); // Convert to the preview currency
} else { final previewBalance = exchangeService.convert(
dash.closeAccountOverlay(apply: false); originalBalance,
} _originalCurrency,
}, dash.tempAccountCurrency,
behavior: HitTestBehavior.translucent, );
child: const SizedBox.expand(),
), return Material(
), color: Colors.transparent,
// Preview Card child: Stack(
Positioned( children: [
top: cardTop, Positioned.fill(
left: 20, child: BackdropFilter(
right: 20, filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
child: Consumer( child: Container(color: Colors.black.withOpacity(0.6)),
builder: (ctx, ref, _) => BalanceCard(
balance: ref.read(totalBalanceProvider),
currencyInfo: CurrencyInfo(
currencyMap[dash.tempAccountCurrency]?.symbol ?? '\$',
dash.tempAccountCurrency,
), ),
onLongPress: null,
accountName: dash.tempAccountName,
previewPrimary: dash.tempPrimary,
previewSecondary: dash.tempSecondary,
previewGradientType: dash.tempGradientType,
), ),
), Positioned.fill(
), child: GestureDetector(
// Account Editor Panel onTap: () {
Positioned( if (_showCurrencyDropdown) {
top: editorPanelTop, setState(() {
left: 20, _showCurrencyDropdown = false;
right: 20, });
child: GestureDetector( } else {
onTap: () {}, dash.closeAccountOverlay(apply: false);
behavior: HitTestBehavior.opaque, }
child: _buildEditorPanel(editorPanelHeight), },
), behavior: HitTestBehavior.translucent,
), child: const SizedBox.expand(),
// Color Picker Panel ),
Positioned( ),
top: colorPanelTop, // Preview Card
left: 20, Positioned(
right: 20, top: cardTop,
child: GestureDetector( left: 20,
onTap: () { right: 20,
if (_showCurrencyDropdown) { child: BalanceCard(
setState(() { balance: previewBalance,
_showCurrencyDropdown = false; currencyInfo: CurrencyInfo(
}); currencyMap[dash.tempAccountCurrency]?.symbol ?? '\$',
} dash.tempAccountCurrency,
}, ),
behavior: HitTestBehavior.opaque, onLongPress: null,
child: _buildColorPanel(colorPanelHeight), accountName: dash.tempAccountName,
), previewPrimary: dash.tempPrimary,
), previewSecondary: dash.tempSecondary,
// Currency Dropdown - Above everything previewGradientType: dash.tempGradientType,
if (_showCurrencyDropdown) ),
Positioned( ),
top: editorPanelTop + 58, // Position below the currency button // Account Editor Panel
left: 20 + 14 + (MediaQuery.of(context).size.width - 40 - 28) * 0.75 + 8, // Align with currency button Positioned(
width: (MediaQuery.of(context).size.width - 40 - 28) * 0.25, // Same width as currency button top: editorPanelTop,
child: Consumer( left: 20,
builder: (context, ref, _) { right: 20,
final exchangeService = ref.read(exchangeRateServiceProvider); child: GestureDetector(
onTap: () {},
return Material( behavior: HitTestBehavior.opaque,
child: _buildEditorPanel(editorPanelHeight),
),
),
// Color Picker Panel
Positioned(
top: colorPanelTop,
left: 20,
right: 20,
child: GestureDetector(
onTap: () {
if (_showCurrencyDropdown) {
setState(() {
_showCurrencyDropdown = false;
});
}
},
behavior: HitTestBehavior.opaque,
child: _buildColorPanel(colorPanelHeight),
),
),
// Currency Dropdown - Above everything
if (_showCurrencyDropdown)
Positioned(
top: editorPanelTop + 62,
right: 34, // 20 (panel padding) + 14 (inner padding)
width: (MediaQuery.of(context).size.width - 68) * 0.25, // 25% of the inner row width
child: Material(
elevation: 12, elevation: 12,
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
child: Container( child: Container(
@@ -166,18 +204,15 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
final isSelected = entry.$1 == _selectedCurrency; final isSelected = entry.$1 == _selectedCurrency;
return InkWell( return InkWell(
onTap: () { onTap: () {
final oldCurrency = _selectedCurrency;
final newCurrency = entry.$1;
setState(() { setState(() {
_selectedCurrency = newCurrency; _selectedCurrency = entry.$1;
dash.tempAccountCurrency = newCurrency; // Update temp currency for preview
dash.setState(() {
dash.tempAccountCurrency = entry.$1;
});
dash.overlayEntry?.markNeedsBuild();
_showCurrencyDropdown = false; _showCurrencyDropdown = false;
}); });
// Note: Currency conversion will happen automatically
// when the account is saved, as the exchangeRateServiceProvider
// will handle the conversion in the balance calculations
}, },
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
child: Padding( child: Padding(
@@ -217,42 +252,42 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
}).toList(), }).toList(),
), ),
), ),
);
},
),
),
// Close Button - Top Right
Positioned(
top: mq.padding.top + 8,
right: 20,
child: SafeArea(
child: GestureDetector(
onTap: () => dash.closeAccountOverlay(apply: false),
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Theme.of(widget.context).colorScheme.surface,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
), ),
child: Icon( ),
Icons.close_rounded, // Close Button - Top Right
size: 24, Positioned(
color: Theme.of(widget.context).colorScheme.onSurface, top: mq.padding.top + 8,
right: 20,
child: SafeArea(
child: GestureDetector(
onTap: () => dash.closeAccountOverlay(apply: false),
child: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Theme.of(widget.context).colorScheme.surface,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Icon(
Icons.close_rounded,
size: 24,
color: Theme.of(widget.context).colorScheme.onSurface,
),
),
), ),
), ),
), ),
), ],
), ),
], );
), },
); );
} }
@@ -289,87 +324,94 @@ class _AccountEditorOverlayState extends State<AccountEditorOverlay> {
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Row( IntrinsicHeight(
crossAxisAlignment: CrossAxisAlignment.start, child: Row(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Expanded( children: [
flex: 3, Expanded(
child: TextField( flex: 3,
controller: _nameController, child: TextField(
maxLength: 17, controller: _nameController,
buildCounter: (context, {required currentLength, required isFocused, maxLength}) => null, buildCounter: (context, {required currentLength, required isFocused, maxLength}) => null,
style: const TextStyle(fontSize: 13), style: const TextStyle(fontSize: 13),
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Account name', hintText: 'Account name',
hintStyle: TextStyle(fontSize: 13, color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.4)), hintStyle: TextStyle(fontSize: 13, color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.4)),
filled: true, filled: true,
fillColor: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.05), fillColor: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.05),
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
borderSide: BorderSide( borderSide: BorderSide(
color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15), color: _showLimitError
width: 1.5, ? Colors.red
), : Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
), width: 1.5,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(
color: Color(0xFF7C6DED),
width: 1.5,
),
),
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
),
),
),
const SizedBox(width: 8),
Expanded(
child: GestureDetector(
onTap: () {
setState(() {
_showCurrencyDropdown = !_showCurrencyDropdown;
});
},
child: Container(
height: 44, // Increased to match TextField height
decoration: BoxDecoration(
color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: _showCurrencyDropdown
? const Color(0xFF7C6DED)
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
width: 1.5,
),
),
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
[('USD', '\$'), ('EUR', ''), ('BYN', 'Br'), ('RUB', '')]
.firstWhere((c) => c.$1 == _selectedCurrency).$2,
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
), ),
const SizedBox(width: 4), ),
Icon( enabledBorder: OutlineInputBorder(
_showCurrencyDropdown ? Icons.arrow_drop_up : Icons.arrow_drop_down, borderRadius: BorderRadius.circular(12),
size: 20, borderSide: BorderSide(
color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.6), color: _showLimitError
? Colors.red
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
width: 1.5,
), ),
], ),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: _showLimitError
? Colors.red
: const Color(0xFF7C6DED),
width: 1.5,
),
),
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12),
), ),
), ),
), ),
), const SizedBox(width: 8),
], Expanded(
child: GestureDetector(
onTap: () {
setState(() {
_showCurrencyDropdown = !_showCurrencyDropdown;
});
},
child: Container(
height: double.infinity,
decoration: BoxDecoration(
color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: _showCurrencyDropdown
? const Color(0xFF7C6DED)
: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.15),
width: 1.5,
),
),
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
[('USD', '\$'), ('EUR', ''), ('BYN', 'Br'), ('RUB', '')]
.firstWhere((c) => c.$1 == _selectedCurrency).$2,
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
),
const SizedBox(width: 4),
Icon(
_showCurrencyDropdown ? Icons.arrow_drop_up : Icons.arrow_drop_down,
size: 20,
color: Theme.of(widget.context).colorScheme.onSurface.withOpacity(0.6),
),
],
),
),
),
),
],
),
), ),
], ],
), ),
+4 -4
View File
@@ -213,18 +213,18 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: drift name: drift
sha256: "61f876c0291b194980bafd203f48e85d5fb04e4a7334367d1a89f44004dbcb83" sha256: "055c249d1f91be5a47fe447f88afc24c4ca6f4cd6c5ed66767b4797d48acc2e5"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.32.0" version: "2.32.1"
drift_dev: drift_dev:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: drift_dev name: drift_dev
sha256: d687e955cc4b1706ad49b3860fcc1045c09bbf1d84c3c7383615f7f9c3320aa2 sha256: "88a9de3af8571518148a6d8a513b57779fd1e60a026d3ab8a481a878fba01d91"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.32.0" version: "2.32.1"
equatable: equatable:
dependency: transitive dependency: transitive
description: description: