dev
dart 158 lines 5.47 KB
Raw
1 // ignore: must_be_immutable
2 import 'package:cake_wallet/generated/i18n.dart';
3 import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
4 import 'package:flutter/material.dart';
5 import 'package:flutter/widgets.dart';
6 import 'package:flutter_svg/svg.dart';
7
8 class QRFormatSelectionDialog extends BaseAlertDialog {
9 final List<String> formats;
10 final int currentIndex;
11 final Function(int) onFormatSelected;
12
13 QRFormatSelectionDialog({
14 required this.formats,
15 required this.currentIndex,
16 required this.onFormatSelected,
17 });
18
19 @override
20 String get titleText => S.current.choose_qr_code_format;
21
22 @override
23 Widget content(BuildContext context) {
24 return SingleChildScrollView(
25 child: Column(
26 mainAxisSize: MainAxisSize.min,
27 children: [
28 Text(
29 S.current.choose_qr_code_format_note,
30 textAlign: TextAlign.center,
31 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
32 fontSize: 16,
33 decoration: TextDecoration.none,
34 ),
35 ),
36 SizedBox(height: 16),
37 ...formats.asMap().entries.map((entry) {
38 final index = entry.key;
39 final format = entry.value;
40 final isSelected = index == currentIndex;
41
42 return Container(
43 margin: EdgeInsets.only(bottom: 8),
44 decoration: BoxDecoration(
45 color: isSelected
46 ? Theme.of(context).colorScheme.primaryContainer
47 : Theme.of(context).colorScheme.surfaceContainer,
48 borderRadius: BorderRadius.circular(12),
49 border: isSelected
50 ? Border.all(
51 color: Theme.of(context).colorScheme.primary,
52 width: 2,
53 )
54 : null,
55 ),
56 child: Material(
57 color: Colors.transparent,
58 child: InkWell(
59 borderRadius: BorderRadius.circular(12),
60 onTap: () => onFormatSelected(index),
61 child: Padding(
62 padding: EdgeInsets.all(16),
63 child: Row(
64 children: [
65 if (format.startsWith('Cupcake'))
66 Container(
67 width: 32,
68 height: 32,
69 decoration: BoxDecoration(
70 borderRadius: BorderRadius.circular(6),
71 ),
72 child: ClipRRect(
73 borderRadius: BorderRadius.circular(6),
74 child: SvgPicture.asset(
75 'assets/images/cupcake.svg',
76 width: 32,
77 height: 32,
78 fit: BoxFit.cover,
79 ),
80 ),
81 ),
82 SizedBox(width: 12),
83 Expanded(
84 child: Column(
85 crossAxisAlignment: CrossAxisAlignment.start,
86 children: [
87 Text(
88 _getFormatName(format),
89 style: TextStyle(
90 fontSize: 14,
91 fontWeight: FontWeight.w600,
92 color: isSelected
93 ? Theme.of(context).colorScheme.onPrimaryContainer
94 : Theme.of(context).colorScheme.onSurface,
95 ),
96 ),
97 Text(
98 _getFormatSubtitle(format),
99 style: TextStyle(
100 fontSize: 12,
101 color: isSelected
102 ? Theme.of(context)
103 .colorScheme
104 .onPrimaryContainer
105 .withOpacity(0.6)
106 : Theme.of(context).colorScheme.onSurface.withOpacity(0.6),
107 ),
108 ),
109 ],
110 ),
111 ),
112 if (isSelected) ...[
113 Icon(
114 Icons.check_circle,
115 color: Theme.of(context).colorScheme.primary,
116 size: 20,
117 ),
118 ],
119 ],
120 ),
121 ),
122 ),
123 ),
124 );
125 }).toList(),
126 ],
127 ),
128 );
129 }
130
131 @override
132 String get leftActionButtonText => "";
133
134 @override
135 String get rightActionButtonText => "";
136
137 @override
138 VoidCallback get actionLeft => () {};
139
140 @override
141 VoidCallback get actionRight => () {};
142
143 @override
144 bool get isBottomDividerExists => false;
145
146 @override
147 Widget actionButtons(BuildContext context) {
148 return SizedBox.shrink(); // get rid fo cancel button
149 }
150
151 String _getFormatName(String format) {
152 return format.split(' ')[0];
153 }
154
155 String _getFormatSubtitle(String format) {
156 return format.substring(format.indexOf(' ') + 1);
157 }
158 }