dev
dart 203 lines 5.87 KB
Raw
1 import 'package:cake_wallet/generated/i18n.dart';
2 import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
3 import 'package:cake_wallet/src/widgets/standard_checkbox.dart';
4 import 'package:flutter/material.dart';
5 import 'package:url_launcher/url_launcher.dart';
6
7 class ThreeCheckboxAlert extends BaseAlertDialog {
8 ThreeCheckboxAlert({
9 required this.alertTitle,
10 required this.leftButtonText,
11 required this.rightButtonText,
12 required this.actionLeftButton,
13 required this.actionRightButton,
14 this.alertBarrierDismissible = true,
15 Key? key,
16 });
17
18 final String alertTitle;
19 final String leftButtonText;
20 final String rightButtonText;
21 final VoidCallback actionLeftButton;
22 final Function(bool, bool, bool) actionRightButton;
23 final bool alertBarrierDismissible;
24
25 bool checkbox1 = false;
26 void toggleCheckbox1() => checkbox1 = !checkbox1;
27 bool checkbox2 = false;
28 void toggleCheckbox2() => checkbox2 = !checkbox2;
29 bool checkbox3 = false;
30 void toggleCheckbox3() => checkbox3 = !checkbox3;
31
32 bool showValidationMessage = true;
33
34 @override
35 String get titleText => alertTitle;
36
37 @override
38 bool get isDividerExists => true;
39
40 @override
41 String get leftActionButtonText => leftButtonText;
42
43 @override
44 String get rightActionButtonText => rightButtonText;
45
46 @override
47 VoidCallback get actionLeft => actionLeftButton;
48
49 @override
50 VoidCallback get actionRight => () {
51 actionRightButton(checkbox1, checkbox2, checkbox3);
52 };
53
54 @override
55 bool get barrierDismissible => alertBarrierDismissible;
56
57 @override
58 Widget content(BuildContext context) {
59 return ThreeCheckboxAlertContent(
60 checkbox1: checkbox1,
61 toggleCheckbox1: toggleCheckbox1,
62 checkbox2: checkbox2,
63 toggleCheckbox2: toggleCheckbox2,
64 checkbox3: checkbox3,
65 toggleCheckbox3: toggleCheckbox3,
66 );
67 }
68 }
69
70 class ThreeCheckboxAlertContent extends StatefulWidget {
71 ThreeCheckboxAlertContent({
72 required this.checkbox1,
73 required this.toggleCheckbox1,
74 required this.checkbox2,
75 required this.toggleCheckbox2,
76 required this.checkbox3,
77 required this.toggleCheckbox3,
78 Key? key,
79 }) : super(key: key);
80
81 bool checkbox1;
82 void Function() toggleCheckbox1;
83 bool checkbox2;
84 void Function() toggleCheckbox2;
85 bool checkbox3;
86 void Function() toggleCheckbox3;
87
88 @override
89 _ThreeCheckboxAlertContentState createState() => _ThreeCheckboxAlertContentState(
90 checkbox1: checkbox1,
91 toggleCheckbox1: toggleCheckbox1,
92 checkbox2: checkbox2,
93 toggleCheckbox2: toggleCheckbox2,
94 checkbox3: checkbox3,
95 toggleCheckbox3: toggleCheckbox3,
96 );
97
98 static _ThreeCheckboxAlertContentState? of(BuildContext context) {
99 return context.findAncestorStateOfType<_ThreeCheckboxAlertContentState>();
100 }
101 }
102
103 class _ThreeCheckboxAlertContentState extends State<ThreeCheckboxAlertContent> {
104 _ThreeCheckboxAlertContentState({
105 required this.checkbox1,
106 required this.toggleCheckbox1,
107 required this.checkbox2,
108 required this.toggleCheckbox2,
109 required this.checkbox3,
110 required this.toggleCheckbox3,
111 });
112
113 bool checkbox1;
114 void Function() toggleCheckbox1;
115 bool checkbox2;
116 void Function() toggleCheckbox2;
117 bool checkbox3;
118 void Function() toggleCheckbox3;
119
120 bool showValidationMessage = true;
121
122 bool get areAllCheckboxesChecked => checkbox1 && checkbox2 && checkbox3;
123
124 @override
125 Widget build(BuildContext context) {
126 return Form(
127 child: Column(
128 mainAxisSize: MainAxisSize.min,
129 children: [
130 StandardCheckbox(
131 value: checkbox1,
132 caption: S.of(context).cakepay_confirm_no_vpn,
133 onChanged: (bool? value) {
134 setState(() {
135 checkbox1 = value ?? false;
136 toggleCheckbox1();
137 showValidationMessage = !areAllCheckboxesChecked;
138 });
139 },
140 ),
141 StandardCheckbox(
142 value: checkbox2,
143 caption: S.of(context).cakepay_confirm_voided_refund,
144 onChanged: (bool? value) {
145 setState(() {
146 checkbox2 = value ?? false;
147 toggleCheckbox2();
148 showValidationMessage = !areAllCheckboxesChecked;
149 });
150 },
151 ),
152 StandardCheckbox(
153 value: checkbox3,
154 caption: S.of(context).cakepay_confirm_terms_agreed,
155 onChanged: (bool? value) {
156 setState(() {
157 checkbox3 = value ?? false;
158 toggleCheckbox3();
159 showValidationMessage = !areAllCheckboxesChecked;
160 });
161 },
162 ),
163 GestureDetector(
164 behavior: HitTestBehavior.opaque,
165 onTap: () => launchUrl(
166 Uri.parse("https://cakepay.com/cakepay-web-terms.txt"),
167 mode: LaunchMode.externalApplication,
168 ),
169 child: Padding(
170 padding: const EdgeInsets.only(top: 8.0),
171 child: Text(
172 S.of(context).settings_terms_and_conditions,
173 style: TextStyle(
174 fontSize: 16,
175 fontFamily: 'Lato',
176 fontWeight: FontWeight.w400,
177 color: Colors.blueAccent,
178 decoration: TextDecoration.none,
179 height: 1,
180 ),
181 softWrap: true,
182 ),
183 ),
184 ),
185 if (showValidationMessage)
186 Padding(
187 padding: const EdgeInsets.only(top: 8.0),
188 child: Text(
189 'Please confirm all checkboxes',
190 style: TextStyle(
191 color: Colors.red,
192 fontSize: 14,
193 fontFamily: 'Lato',
194 fontWeight: FontWeight.w400,
195 decoration: TextDecoration.none,
196 ),
197 ),
198 ),
199 ],
200 ),
201 );
202 }
203 }