dev
dart 163 lines 6.85 KB
Raw
1 import 'package:cake_wallet/src/widgets/alert_close_button.dart';
2 import 'package:cake_wallet/src/widgets/rounded_checkbox.dart';
3 import 'package:cake_wallet/src/widgets/alert_background.dart';
4 import 'package:cake_wallet/typography.dart';
5 import 'package:cake_wallet/utils/show_pop_up.dart';
6 import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart';
7 import 'package:flutter/material.dart';
8 import 'package:flutter_mobx/flutter_mobx.dart';
9 import 'package:cake_wallet/generated/i18n.dart';
10
11 class PresentReceiveOptionPicker extends StatelessWidget {
12 PresentReceiveOptionPicker({required this.receiveOptionViewModel, required this.color});
13
14 final ReceiveOptionViewModel receiveOptionViewModel;
15 final Color color;
16
17 @override
18 Widget build(BuildContext context) {
19 final arrowBottom = Image.asset(
20 'assets/images/arrow_bottom_purple_icon.png',
21 color: Theme.of(context).colorScheme.primary,
22 height: 6,
23 );
24
25 return Padding(
26 padding: EdgeInsets.only(left: 6),
27 child: TextButton(
28 onPressed: () => _showPicker(context),
29 style: ButtonStyle(
30 padding: WidgetStateProperty.all(EdgeInsets.zero),
31 splashFactory: NoSplash.splashFactory,
32 foregroundColor: WidgetStateProperty.all(Colors.transparent),
33 overlayColor: WidgetStateProperty.all(Colors.transparent),
34 ),
35 child: Row(
36 mainAxisSize: MainAxisSize.min,
37 crossAxisAlignment: CrossAxisAlignment.start,
38 children: <Widget>[
39 Column(
40 crossAxisAlignment: CrossAxisAlignment.center,
41 mainAxisSize: MainAxisSize.min,
42 children: <Widget>[
43 Text(
44 S.current.receive,
45 style: Theme.of(context).textTheme.bodyMedium!.copyWith(
46 fontSize: 17.0,
47 fontWeight: FontWeight.bold,
48 color: Theme.of(context).colorScheme.onSurface,
49 ),
50 ),
51 Row(
52 children: [
53 Observer(
54 builder: (_) => Text(
55 receiveOptionViewModel.selectedReceiveOption
56 .toString()
57 .replaceAll(RegExp(r'silent payments', caseSensitive: false),
58 S.current.silent_payments)
59 .replaceAll(RegExp(r'default', caseSensitive: false),
60 S.current.string_default),
61 style: Theme.of(context).textTheme.bodySmall!.copyWith(
62 fontSize: 10.0,
63 fontWeight: FontWeight.w500,
64 color: Theme.of(context).colorScheme.onSurfaceVariant,
65 ),
66 ),
67 ),
68 ],
69 ),
70 ],
71 ),
72 SizedBox(width: 5),
73 Padding(
74 padding: EdgeInsets.only(top: 12),
75 child: arrowBottom,
76 )
77 ],
78 ),
79 ));
80 }
81
82 void _showPicker(BuildContext context) async {
83 await showPopUp<void>(
84 builder: (BuildContext popUpContext) => Scaffold(
85 resizeToAvoidBottomInset: false,
86 backgroundColor: Colors.transparent,
87 body: Stack(
88 alignment: AlignmentDirectional.center,
89 children: [
90 AlertBackground(
91 child: Column(
92 mainAxisSize: MainAxisSize.min,
93 mainAxisAlignment: MainAxisAlignment.center,
94 children: [
95 Spacer(),
96 Container(
97 margin: EdgeInsets.symmetric(horizontal: 24),
98 decoration: BoxDecoration(
99 borderRadius: BorderRadius.circular(30),
100 color: Theme.of(context).colorScheme.surface,
101 ),
102 child: Padding(
103 padding: const EdgeInsets.only(top: 24, bottom: 24),
104 child: (ListView.separated(
105 padding: EdgeInsets.zero,
106 shrinkWrap: true,
107 itemCount: receiveOptionViewModel.options.length,
108 itemBuilder: (_, index) {
109 final option = receiveOptionViewModel.options[index];
110 return InkWell(
111 onTap: () {
112 Navigator.pop(popUpContext);
113
114 receiveOptionViewModel.selectReceiveOption(option);
115 },
116 child: Padding(
117 padding: const EdgeInsets.only(left: 24, right: 24),
118 child: Observer(builder: (_) {
119 final value = receiveOptionViewModel.selectedReceiveOption;
120
121 return Row(
122 mainAxisAlignment: MainAxisAlignment.spaceBetween,
123 children: [
124 Text(
125 option
126 .toString()
127 .replaceAll(
128 RegExp(r'silent payments', caseSensitive: false),
129 S.current.silent_payments)
130 .replaceAll(RegExp(r'default', caseSensitive: false),
131 S.current.string_default),
132 textAlign: TextAlign.left,
133 style: textSmall(
134 color: Theme.of(context).colorScheme.onSurface,
135 ).copyWith(
136 fontWeight:
137 value == option ? FontWeight.w800 : FontWeight.w500,
138 )),
139 RoundedCheckbox(
140 value: value == option,
141 )
142 ],
143 );
144 }),
145 ),
146 );
147 },
148 separatorBuilder: (_, index) => SizedBox(height: 30),
149 )),
150 ),
151 ),
152 Spacer()
153 ],
154 ),
155 ),
156 AlertCloseButton(onTap: () => Navigator.of(popUpContext).pop(), bottom: 40)
157 ],
158 ),
159 ),
160 context: context,
161 );
162 }
163 }