mirror of
https://github.com/koloideal/Casha.git
synced 2026-06-10 10:25:28 +03:00
update
This commit is contained in:
@@ -12,6 +12,7 @@ class AddTransactionState {
|
||||
final String? editingId;
|
||||
final String overrideCurrency;
|
||||
final String overrideCurrencyCode;
|
||||
final int? selectedAccountId;
|
||||
|
||||
const AddTransactionState({
|
||||
this.amount,
|
||||
@@ -23,6 +24,7 @@ class AddTransactionState {
|
||||
this.editingId,
|
||||
this.overrideCurrency = '\$',
|
||||
this.overrideCurrencyCode = 'USD',
|
||||
this.selectedAccountId,
|
||||
});
|
||||
|
||||
factory AddTransactionState.fromTransaction(Transaction tx) {
|
||||
@@ -35,11 +37,12 @@ class AddTransactionState {
|
||||
editingId: tx.id,
|
||||
overrideCurrency: tx.currency,
|
||||
overrideCurrencyCode: tx.currencyCode,
|
||||
selectedAccountId: tx.accountId,
|
||||
);
|
||||
}
|
||||
|
||||
factory AddTransactionState.empty() {
|
||||
return AddTransactionState(date: DateTime.now());
|
||||
return AddTransactionState(date: DateTime.now(), selectedAccountId: null);
|
||||
}
|
||||
|
||||
AddTransactionState copyWith({
|
||||
@@ -52,8 +55,8 @@ class AddTransactionState {
|
||||
String? editingId,
|
||||
String? overrideCurrency,
|
||||
String? overrideCurrencyCode,
|
||||
}) =>
|
||||
AddTransactionState(
|
||||
int? selectedAccountId,
|
||||
}) => AddTransactionState(
|
||||
amount: amount ?? this.amount,
|
||||
category: category ?? this.category,
|
||||
type: type ?? this.type,
|
||||
@@ -63,6 +66,7 @@ class AddTransactionState {
|
||||
editingId: editingId ?? this.editingId,
|
||||
overrideCurrency: overrideCurrency ?? this.overrideCurrency,
|
||||
overrideCurrencyCode: overrideCurrencyCode ?? this.overrideCurrencyCode,
|
||||
selectedAccountId: selectedAccountId ?? this.selectedAccountId,
|
||||
);
|
||||
|
||||
bool get isEditing => editingId != null;
|
||||
@@ -70,9 +74,11 @@ class AddTransactionState {
|
||||
|
||||
class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
||||
AddTransactionNotifier(Transaction? initial)
|
||||
: super(initial != null
|
||||
: super(
|
||||
initial != null
|
||||
? AddTransactionState.fromTransaction(initial)
|
||||
: AddTransactionState.empty());
|
||||
: AddTransactionState.empty(),
|
||||
);
|
||||
|
||||
void setAmount(double? v) => state = state.copyWith(amount: v);
|
||||
|
||||
@@ -90,19 +96,26 @@ class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
||||
void setSubmitting(bool v) => state = state.copyWith(isSubmitting: v);
|
||||
|
||||
void setCurrency(String symbol, String code) {
|
||||
state = state.copyWith(overrideCurrency: symbol, overrideCurrencyCode: code);
|
||||
state = state.copyWith(
|
||||
overrideCurrency: symbol,
|
||||
overrideCurrencyCode: code,
|
||||
);
|
||||
}
|
||||
|
||||
void setAccountId(int id) => state = state.copyWith(selectedAccountId: id);
|
||||
|
||||
void reset() => state = AddTransactionState.empty();
|
||||
}
|
||||
|
||||
final addTransactionProvider = StateNotifierProvider.autoDispose
|
||||
.family<AddTransactionNotifier, AddTransactionState, Transaction?>(
|
||||
(ref, initial) => AddTransactionNotifier(initial),
|
||||
);
|
||||
);
|
||||
|
||||
final availableCategoriesProvider =
|
||||
Provider.autoDispose.family<List<String>, Transaction?>((ref, initial) {
|
||||
final type = ref.watch(addTransactionProvider(initial).select((s) => s.type));
|
||||
final availableCategoriesProvider = Provider.autoDispose
|
||||
.family<List<String>, Transaction?>((ref, initial) {
|
||||
final type = ref.watch(
|
||||
addTransactionProvider(initial).select((s) => s.type),
|
||||
);
|
||||
return AppCategories.forType(type);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../../core/constants.dart';
|
||||
import '../../core/l10n/app_strings.dart';
|
||||
import '../../core/l10n/locale_provider.dart';
|
||||
import '../../core/services/haptic_service.dart';
|
||||
import '../../shared/models/account.dart';
|
||||
import '../../shared/models/transaction.dart';
|
||||
import '../dashboard/provider.dart';
|
||||
import '../settings/provider.dart';
|
||||
@@ -44,11 +45,13 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _amountController = TextEditingController();
|
||||
final _noteController = TextEditingController();
|
||||
final _accountIndicatorKey = GlobalKey();
|
||||
late AnimationController _shakeController;
|
||||
late Animation<Color?> _borderColorAnimation;
|
||||
bool _showError = false;
|
||||
late DateTime _selectedDate;
|
||||
late TimeOfDay _selectedTime;
|
||||
bool _showAccountDropdown = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -166,9 +169,15 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
);
|
||||
|
||||
final activeAccount = ref.read(activeAccountProvider);
|
||||
final selectedId = ref
|
||||
.read(addTransactionProvider(widget.initial))
|
||||
.selectedAccountId;
|
||||
int accountId;
|
||||
|
||||
if (activeAccount != null) {
|
||||
if (selectedId != null && selectedId != 0) {
|
||||
print('Using selected account ID: $selectedId');
|
||||
accountId = selectedId;
|
||||
} else if (activeAccount != null) {
|
||||
print(
|
||||
'Using active account ID: ${activeAccount.id}, Name: ${activeAccount.name}',
|
||||
);
|
||||
@@ -347,49 +356,90 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
body: SafeArea(
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
child: Stack(
|
||||
children: [
|
||||
ListView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
// Symmetrical Account + Type Toggle Row
|
||||
Row(
|
||||
children: [
|
||||
// Left: Account Indicator (50% width)
|
||||
Expanded(
|
||||
child: accountsAsync.when(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
accountsAsync.when(
|
||||
data: (accounts) {
|
||||
final displayAccount =
|
||||
final txAccountId = ref
|
||||
.read(
|
||||
addTransactionProvider(widget.initial),
|
||||
)
|
||||
.selectedAccountId;
|
||||
final Account displayAccount;
|
||||
if (txAccountId != null) {
|
||||
displayAccount = accounts.firstWhere(
|
||||
(a) => a.id == txAccountId,
|
||||
orElse: () => accounts.firstWhere(
|
||||
(a) => a.isMain,
|
||||
orElse: () => accounts.first,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
displayAccount =
|
||||
activeAccount ??
|
||||
accounts.firstWhere(
|
||||
(a) => a.isMain,
|
||||
orElse: () => accounts.first,
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
final canChangeAccount = activeAccount == null;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: canChangeAccount
|
||||
? () => setState(
|
||||
() => _showAccountDropdown =
|
||||
!_showAccountDropdown,
|
||||
)
|
||||
: null,
|
||||
child: Container(
|
||||
key: _accountIndicatorKey,
|
||||
height: 56,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.1),
|
||||
color: const Color(
|
||||
0xFF7C6DED,
|
||||
).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.3),
|
||||
color: const Color(
|
||||
0xFF7C6DED,
|
||||
).withOpacity(0.3),
|
||||
width: 1.5,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
const Icon(
|
||||
Icons.account_balance_wallet_rounded,
|
||||
size: 18,
|
||||
color: const Color(0xFF7C6DED),
|
||||
color: Color(0xFF7C6DED),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: Text(
|
||||
displayAccount.name,
|
||||
style: Theme.of(context).textTheme.bodyMedium
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: const Color(0xFF7C6DED),
|
||||
color: const Color(
|
||||
0xFF7C6DED,
|
||||
),
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14,
|
||||
),
|
||||
@@ -397,7 +447,18 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
if (canChangeAccount) ...[
|
||||
const SizedBox(width: 6),
|
||||
Icon(
|
||||
_showAccountDropdown
|
||||
? Icons.arrow_drop_up
|
||||
: Icons.arrow_drop_down,
|
||||
size: 18,
|
||||
color: const Color(0xFF7C6DED),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -416,6 +477,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Right: Type Toggle (50% width)
|
||||
@@ -446,7 +509,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
decoration: BoxDecoration(
|
||||
color: state.type == TransactionType.income
|
||||
color:
|
||||
state.type == TransactionType.income
|
||||
? AppColors.income.withOpacity(0.15)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
@@ -454,7 +518,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.arrow_downward_rounded,
|
||||
color: state.type == TransactionType.income
|
||||
color:
|
||||
state.type == TransactionType.income
|
||||
? AppColors.income
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
@@ -478,7 +543,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
decoration: BoxDecoration(
|
||||
color: state.type == TransactionType.expense
|
||||
color:
|
||||
state.type == TransactionType.expense
|
||||
? AppColors.expense.withOpacity(0.15)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
@@ -486,7 +552,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.arrow_upward_rounded,
|
||||
color: state.type == TransactionType.expense
|
||||
color:
|
||||
state.type ==
|
||||
TransactionType.expense
|
||||
? AppColors.expense
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
@@ -516,7 +584,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
? Colors.transparent
|
||||
: const Color(0xFFCCCCDD);
|
||||
final borderColor = isError
|
||||
? (_borderColorAnimation.value ?? const Color(0xFFE05C6B))
|
||||
? (_borderColorAnimation.value ??
|
||||
const Color(0xFFE05C6B))
|
||||
: normalBorder;
|
||||
|
||||
return Container(
|
||||
@@ -531,7 +600,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
),
|
||||
child: Text(
|
||||
overrideCurrency,
|
||||
style: Theme.of(context).textTheme.bodyLarge
|
||||
@@ -546,7 +617,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _amountController,
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
keyboardType:
|
||||
const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
style: Theme.of(context).textTheme.headlineSmall
|
||||
@@ -731,7 +803,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_selectedTime.format(context),
|
||||
style: Theme.of(context).textTheme.bodyMedium
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
@@ -765,7 +839,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
maxLength,
|
||||
}) => Text(
|
||||
'$currentLength/$maxLength',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withOpacity(0.4),
|
||||
@@ -778,7 +853,10 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: isDark
|
||||
? BorderSide.none
|
||||
: const BorderSide(color: Color(0xFFCCCCDD), width: 1),
|
||||
: const BorderSide(
|
||||
color: Color(0xFFCCCCDD),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -843,6 +921,135 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_showAccountDropdown)
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() => _showAccountDropdown = false),
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
),
|
||||
if (_showAccountDropdown)
|
||||
Positioned(
|
||||
top: 76,
|
||||
left: 20,
|
||||
right: MediaQuery.of(context).size.width / 2 + 6,
|
||||
child: Material(
|
||||
elevation: 8,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.transparent,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: const Color(0xFF7C6DED).withOpacity(0.3),
|
||||
width: 1.5,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: accountsAsync.when(
|
||||
data: (accounts) {
|
||||
final txAccountId = ref
|
||||
.read(addTransactionProvider(widget.initial))
|
||||
.selectedAccountId;
|
||||
final Account displayAccount;
|
||||
if (txAccountId != null) {
|
||||
displayAccount = accounts.firstWhere(
|
||||
(a) => a.id == txAccountId,
|
||||
orElse: () => accounts.firstWhere(
|
||||
(a) => a.isMain,
|
||||
orElse: () => accounts.first,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
displayAccount =
|
||||
activeAccount ??
|
||||
accounts.firstWhere(
|
||||
(a) => a.isMain,
|
||||
orElse: () => accounts.first,
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: accounts.map((account) {
|
||||
final isSelected =
|
||||
account.id == displayAccount.id;
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: () {
|
||||
ref
|
||||
.read(
|
||||
addTransactionProvider(
|
||||
widget.initial,
|
||||
).notifier,
|
||||
)
|
||||
.setAccountId(account.id);
|
||||
setState(() => _showAccountDropdown = false);
|
||||
HapticService.light();
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 12,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.account_balance_wallet_rounded,
|
||||
size: 16,
|
||||
color: isSelected
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
account.name,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: isSelected
|
||||
? FontWeight.w600
|
||||
: FontWeight.w400,
|
||||
color: isSelected
|
||||
? const Color(0xFF7C6DED)
|
||||
: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (isSelected)
|
||||
const Icon(
|
||||
Icons.check_rounded,
|
||||
size: 16,
|
||||
color: Color(0xFF7C6DED),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
},
|
||||
loading: () => const SizedBox.shrink(),
|
||||
error: (_, __) => const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user