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? editingId;
|
||||||
final String overrideCurrency;
|
final String overrideCurrency;
|
||||||
final String overrideCurrencyCode;
|
final String overrideCurrencyCode;
|
||||||
|
final int? selectedAccountId;
|
||||||
|
|
||||||
const AddTransactionState({
|
const AddTransactionState({
|
||||||
this.amount,
|
this.amount,
|
||||||
@@ -23,6 +24,7 @@ class AddTransactionState {
|
|||||||
this.editingId,
|
this.editingId,
|
||||||
this.overrideCurrency = '\$',
|
this.overrideCurrency = '\$',
|
||||||
this.overrideCurrencyCode = 'USD',
|
this.overrideCurrencyCode = 'USD',
|
||||||
|
this.selectedAccountId,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory AddTransactionState.fromTransaction(Transaction tx) {
|
factory AddTransactionState.fromTransaction(Transaction tx) {
|
||||||
@@ -35,11 +37,12 @@ class AddTransactionState {
|
|||||||
editingId: tx.id,
|
editingId: tx.id,
|
||||||
overrideCurrency: tx.currency,
|
overrideCurrency: tx.currency,
|
||||||
overrideCurrencyCode: tx.currencyCode,
|
overrideCurrencyCode: tx.currencyCode,
|
||||||
|
selectedAccountId: tx.accountId,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
factory AddTransactionState.empty() {
|
factory AddTransactionState.empty() {
|
||||||
return AddTransactionState(date: DateTime.now());
|
return AddTransactionState(date: DateTime.now(), selectedAccountId: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTransactionState copyWith({
|
AddTransactionState copyWith({
|
||||||
@@ -52,8 +55,8 @@ class AddTransactionState {
|
|||||||
String? editingId,
|
String? editingId,
|
||||||
String? overrideCurrency,
|
String? overrideCurrency,
|
||||||
String? overrideCurrencyCode,
|
String? overrideCurrencyCode,
|
||||||
}) =>
|
int? selectedAccountId,
|
||||||
AddTransactionState(
|
}) => AddTransactionState(
|
||||||
amount: amount ?? this.amount,
|
amount: amount ?? this.amount,
|
||||||
category: category ?? this.category,
|
category: category ?? this.category,
|
||||||
type: type ?? this.type,
|
type: type ?? this.type,
|
||||||
@@ -63,6 +66,7 @@ class AddTransactionState {
|
|||||||
editingId: editingId ?? this.editingId,
|
editingId: editingId ?? this.editingId,
|
||||||
overrideCurrency: overrideCurrency ?? this.overrideCurrency,
|
overrideCurrency: overrideCurrency ?? this.overrideCurrency,
|
||||||
overrideCurrencyCode: overrideCurrencyCode ?? this.overrideCurrencyCode,
|
overrideCurrencyCode: overrideCurrencyCode ?? this.overrideCurrencyCode,
|
||||||
|
selectedAccountId: selectedAccountId ?? this.selectedAccountId,
|
||||||
);
|
);
|
||||||
|
|
||||||
bool get isEditing => editingId != null;
|
bool get isEditing => editingId != null;
|
||||||
@@ -70,9 +74,11 @@ class AddTransactionState {
|
|||||||
|
|
||||||
class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
||||||
AddTransactionNotifier(Transaction? initial)
|
AddTransactionNotifier(Transaction? initial)
|
||||||
: super(initial != null
|
: super(
|
||||||
|
initial != null
|
||||||
? AddTransactionState.fromTransaction(initial)
|
? AddTransactionState.fromTransaction(initial)
|
||||||
: AddTransactionState.empty());
|
: AddTransactionState.empty(),
|
||||||
|
);
|
||||||
|
|
||||||
void setAmount(double? v) => state = state.copyWith(amount: v);
|
void setAmount(double? v) => state = state.copyWith(amount: v);
|
||||||
|
|
||||||
@@ -90,9 +96,14 @@ class AddTransactionNotifier extends StateNotifier<AddTransactionState> {
|
|||||||
void setSubmitting(bool v) => state = state.copyWith(isSubmitting: v);
|
void setSubmitting(bool v) => state = state.copyWith(isSubmitting: v);
|
||||||
|
|
||||||
void setCurrency(String symbol, String code) {
|
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();
|
void reset() => state = AddTransactionState.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,8 +112,10 @@ final addTransactionProvider = StateNotifierProvider.autoDispose
|
|||||||
(ref, initial) => AddTransactionNotifier(initial),
|
(ref, initial) => AddTransactionNotifier(initial),
|
||||||
);
|
);
|
||||||
|
|
||||||
final availableCategoriesProvider =
|
final availableCategoriesProvider = Provider.autoDispose
|
||||||
Provider.autoDispose.family<List<String>, Transaction?>((ref, initial) {
|
.family<List<String>, Transaction?>((ref, initial) {
|
||||||
final type = ref.watch(addTransactionProvider(initial).select((s) => s.type));
|
final type = ref.watch(
|
||||||
|
addTransactionProvider(initial).select((s) => s.type),
|
||||||
|
);
|
||||||
return AppCategories.forType(type);
|
return AppCategories.forType(type);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import '../../core/constants.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/haptic_service.dart';
|
import '../../core/services/haptic_service.dart';
|
||||||
|
import '../../shared/models/account.dart';
|
||||||
import '../../shared/models/transaction.dart';
|
import '../../shared/models/transaction.dart';
|
||||||
import '../dashboard/provider.dart';
|
import '../dashboard/provider.dart';
|
||||||
import '../settings/provider.dart';
|
import '../settings/provider.dart';
|
||||||
@@ -44,11 +45,13 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _amountController = TextEditingController();
|
final _amountController = TextEditingController();
|
||||||
final _noteController = TextEditingController();
|
final _noteController = TextEditingController();
|
||||||
|
final _accountIndicatorKey = GlobalKey();
|
||||||
late AnimationController _shakeController;
|
late AnimationController _shakeController;
|
||||||
late Animation<Color?> _borderColorAnimation;
|
late Animation<Color?> _borderColorAnimation;
|
||||||
bool _showError = false;
|
bool _showError = false;
|
||||||
late DateTime _selectedDate;
|
late DateTime _selectedDate;
|
||||||
late TimeOfDay _selectedTime;
|
late TimeOfDay _selectedTime;
|
||||||
|
bool _showAccountDropdown = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -166,9 +169,15 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
);
|
);
|
||||||
|
|
||||||
final activeAccount = ref.read(activeAccountProvider);
|
final activeAccount = ref.read(activeAccountProvider);
|
||||||
|
final selectedId = ref
|
||||||
|
.read(addTransactionProvider(widget.initial))
|
||||||
|
.selectedAccountId;
|
||||||
int accountId;
|
int accountId;
|
||||||
|
|
||||||
if (activeAccount != null) {
|
if (selectedId != null && selectedId != 0) {
|
||||||
|
print('Using selected account ID: $selectedId');
|
||||||
|
accountId = selectedId;
|
||||||
|
} else if (activeAccount != null) {
|
||||||
print(
|
print(
|
||||||
'Using active account ID: ${activeAccount.id}, Name: ${activeAccount.name}',
|
'Using active account ID: ${activeAccount.id}, Name: ${activeAccount.name}',
|
||||||
);
|
);
|
||||||
@@ -347,49 +356,90 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: ListView(
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
ListView(
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
children: [
|
children: [
|
||||||
// Symmetrical Account + Type Toggle Row
|
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
// Left: Account Indicator (50% width)
|
// Left: Account Indicator (50% width)
|
||||||
Expanded(
|
Expanded(
|
||||||
child: accountsAsync.when(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
accountsAsync.when(
|
||||||
data: (accounts) {
|
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 ??
|
activeAccount ??
|
||||||
accounts.firstWhere(
|
accounts.firstWhere(
|
||||||
(a) => a.isMain,
|
(a) => a.isMain,
|
||||||
orElse: () => accounts.first,
|
orElse: () => accounts.first,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Container(
|
final canChangeAccount = activeAccount == null;
|
||||||
|
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: canChangeAccount
|
||||||
|
? () => setState(
|
||||||
|
() => _showAccountDropdown =
|
||||||
|
!_showAccountDropdown,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
child: Container(
|
||||||
|
key: _accountIndicatorKey,
|
||||||
height: 56,
|
height: 56,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 14,
|
||||||
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFF7C6DED).withOpacity(0.1),
|
color: const Color(
|
||||||
|
0xFF7C6DED,
|
||||||
|
).withOpacity(0.1),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: const Color(0xFF7C6DED).withOpacity(0.3),
|
color: const Color(
|
||||||
|
0xFF7C6DED,
|
||||||
|
).withOpacity(0.3),
|
||||||
width: 1.5,
|
width: 1.5,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
const Icon(
|
||||||
Icons.account_balance_wallet_rounded,
|
Icons.account_balance_wallet_rounded,
|
||||||
size: 18,
|
size: 18,
|
||||||
color: const Color(0xFF7C6DED),
|
color: Color(0xFF7C6DED),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
displayAccount.name,
|
displayAccount.name,
|
||||||
style: Theme.of(context).textTheme.bodyMedium
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium
|
||||||
?.copyWith(
|
?.copyWith(
|
||||||
color: const Color(0xFF7C6DED),
|
color: const Color(
|
||||||
|
0xFF7C6DED,
|
||||||
|
),
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
@@ -397,7 +447,18 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
textAlign: TextAlign.center,
|
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),
|
const SizedBox(width: 12),
|
||||||
// Right: Type Toggle (50% width)
|
// Right: Type Toggle (50% width)
|
||||||
@@ -446,7 +509,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: state.type == TransactionType.income
|
color:
|
||||||
|
state.type == TransactionType.income
|
||||||
? AppColors.income.withOpacity(0.15)
|
? AppColors.income.withOpacity(0.15)
|
||||||
: Colors.transparent,
|
: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(11),
|
borderRadius: BorderRadius.circular(11),
|
||||||
@@ -454,7 +518,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: Center(
|
child: Center(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.arrow_downward_rounded,
|
Icons.arrow_downward_rounded,
|
||||||
color: state.type == TransactionType.income
|
color:
|
||||||
|
state.type == TransactionType.income
|
||||||
? AppColors.income
|
? AppColors.income
|
||||||
: Theme.of(context)
|
: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
@@ -478,7 +543,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: state.type == TransactionType.expense
|
color:
|
||||||
|
state.type == TransactionType.expense
|
||||||
? AppColors.expense.withOpacity(0.15)
|
? AppColors.expense.withOpacity(0.15)
|
||||||
: Colors.transparent,
|
: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(11),
|
borderRadius: BorderRadius.circular(11),
|
||||||
@@ -486,7 +552,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: Center(
|
child: Center(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.arrow_upward_rounded,
|
Icons.arrow_upward_rounded,
|
||||||
color: state.type == TransactionType.expense
|
color:
|
||||||
|
state.type ==
|
||||||
|
TransactionType.expense
|
||||||
? AppColors.expense
|
? AppColors.expense
|
||||||
: Theme.of(context)
|
: Theme.of(context)
|
||||||
.colorScheme
|
.colorScheme
|
||||||
@@ -516,7 +584,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
? Colors.transparent
|
? Colors.transparent
|
||||||
: const Color(0xFFCCCCDD);
|
: const Color(0xFFCCCCDD);
|
||||||
final borderColor = isError
|
final borderColor = isError
|
||||||
? (_borderColorAnimation.value ?? const Color(0xFFE05C6B))
|
? (_borderColorAnimation.value ??
|
||||||
|
const Color(0xFFE05C6B))
|
||||||
: normalBorder;
|
: normalBorder;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
@@ -531,7 +600,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 14,
|
||||||
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
overrideCurrency,
|
overrideCurrency,
|
||||||
style: Theme.of(context).textTheme.bodyLarge
|
style: Theme.of(context).textTheme.bodyLarge
|
||||||
@@ -546,7 +617,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: _amountController,
|
controller: _amountController,
|
||||||
keyboardType: const TextInputType.numberWithOptions(
|
keyboardType:
|
||||||
|
const TextInputType.numberWithOptions(
|
||||||
decimal: true,
|
decimal: true,
|
||||||
),
|
),
|
||||||
style: Theme.of(context).textTheme.headlineSmall
|
style: Theme.of(context).textTheme.headlineSmall
|
||||||
@@ -731,7 +803,9 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
_selectedTime.format(context),
|
_selectedTime.format(context),
|
||||||
style: Theme.of(context).textTheme.bodyMedium
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium
|
||||||
?.copyWith(
|
?.copyWith(
|
||||||
color: Theme.of(
|
color: Theme.of(
|
||||||
context,
|
context,
|
||||||
@@ -765,7 +839,8 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
maxLength,
|
maxLength,
|
||||||
}) => Text(
|
}) => Text(
|
||||||
'$currentLength/$maxLength',
|
'$currentLength/$maxLength',
|
||||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
style: Theme.of(context).textTheme.bodySmall
|
||||||
|
?.copyWith(
|
||||||
color: Theme.of(
|
color: Theme.of(
|
||||||
context,
|
context,
|
||||||
).colorScheme.onSurface.withOpacity(0.4),
|
).colorScheme.onSurface.withOpacity(0.4),
|
||||||
@@ -778,7 +853,10 @@ class _AddTransactionScreenState extends ConsumerState<AddTransactionScreen>
|
|||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
borderSide: isDark
|
borderSide: isDark
|
||||||
? BorderSide.none
|
? BorderSide.none
|
||||||
: const BorderSide(color: Color(0xFFCCCCDD), width: 1),
|
: const BorderSide(
|
||||||
|
color: Color(0xFFCCCCDD),
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
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