-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathapp_bar_widget.dart
More file actions
134 lines (126 loc) · 4.39 KB
/
Copy pathapp_bar_widget.dart
File metadata and controls
134 lines (126 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/build_context_x.dart';
import 'package:bb_mobile/core/wallet/domain/entities/wallet.dart';
import 'package:bb_mobile/core/widgets/bottom_sheet/x.dart';
import 'package:bb_mobile/core/widgets/buttons/button.dart';
import 'package:bb_mobile/core/widgets/text/text.dart';
import 'package:bb_mobile/features/test_wallet_backup/presentation/bloc/test_wallet_backup_bloc.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:bull_ui/bull_ui.dart' show Gap;
import 'package:go_router/go_router.dart';
class AppBarWidget extends StatelessWidget {
const AppBarWidget({super.key, required this.title});
final String title;
@override
PreferredSizeWidget build(BuildContext context) {
final wallets = context.watch<TestWalletBackupBloc>().state.wallets;
final selectedWallet = context
.watch<TestWalletBackupBloc>()
.state
.selectedWallet;
return AppBar(
leading: IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => context.pop(),
),
title: Text(title),
actions: [
if (wallets.length > 1)
IconButton(
icon: const Icon(CupertinoIcons.chevron_down),
onPressed: () async {
final bloc = context.read<TestWalletBackupBloc>();
final selectedId = selectedWallet?.id;
final selectedIndex = wallets.indexWhere(
(w) => w.id == selectedId,
);
final selectedWalletId = await _showWalletPicker(
context: context,
wallets: wallets,
initialIndex: selectedIndex,
);
if (selectedWalletId != null) {
bloc.add(WalletSelected(wallet: selectedWallet!));
}
},
),
],
);
}
}
Future<String?> _showWalletPicker({
required BuildContext context,
required List<Wallet> wallets,
required int initialIndex,
}) {
final controller = FixedExtentScrollController(
initialItem: initialIndex >= 0 ? initialIndex : 0,
);
return BlurredBottomSheet.show<String>(
context: context,
isDismissible: true,
child: Container(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.4,
),
decoration: BoxDecoration(
color: context.appColors.onSecondary,
borderRadius: const BorderRadius.vertical(top: Radius.circular(32)),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
child: Column(
mainAxisSize: .min,
children: [
Row(
children: [
const Spacer(),
IconButton(
icon: Icon(Icons.close, color: context.appColors.secondary),
onPressed: () => Navigator.of(context).pop(),
),
],
),
const Gap(8),
Expanded(
child: CupertinoPicker(
scrollController: controller,
itemExtent: 70,
onSelectedItemChanged: (index) {},
children: [
for (final wallet in wallets)
Center(
child: BBText(
wallet.isDefault
? context.loc.testBackupDefaultWallets
: wallet.displayLabel(context),
style: context.font.bodyLarge?.copyWith(
fontWeight: .w600,
fontSize: 18,
color: context.appColors.secondary,
),
),
),
],
),
),
BBButton.big(
label: context.loc.testBackupConfirm,
onPressed: () {
final wallet = wallets[controller.selectedItem];
context.read<TestWalletBackupBloc>().add(
WalletSelected(wallet: wallet),
);
Navigator.of(context).pop();
},
bgColor: context.appColors.secondary,
textColor: context.appColors.onSecondary,
),
],
),
),
),
);
}