|
1 | 1 | import 'package:expansion_tile_card/expansion_tile_card.dart';
|
2 | 2 | import 'package:flood_mobile/Blocs/language_bloc/language_bloc.dart';
|
3 | 3 | import 'package:flood_mobile/Blocs/theme_bloc/theme_bloc.dart';
|
| 4 | +import 'package:flood_mobile/Blocs/user_interface_bloc/user_interface_bloc.dart'; |
4 | 5 | import 'package:flood_mobile/Constants/languages.dart';
|
5 | 6 | import 'package:flood_mobile/Pages/widgets/flood_snackbar.dart';
|
6 | 7 | import 'package:flood_mobile/Pages/widgets/text_size.dart';
|
7 | 8 | import 'package:flood_mobile/l10n/l10n.dart';
|
8 | 9 | import 'package:flutter/material.dart';
|
9 | 10 | import 'package:flutter_bloc/flutter_bloc.dart';
|
10 | 11 |
|
11 |
| -class UserInterfaceSection extends StatelessWidget { |
| 12 | +// ignore: must_be_immutable |
| 13 | +class UserInterfaceSection extends StatefulWidget { |
12 | 14 | final int themeIndex;
|
13 | 15 | final double hp;
|
| 16 | + Map<String, bool> torrentScreenItems; |
| 17 | + Map<String, bool> contextMenuItems; |
| 18 | + |
14 | 19 | UserInterfaceSection({
|
15 | 20 | Key? key,
|
16 | 21 | required this.themeIndex,
|
17 | 22 | required this.hp,
|
| 23 | + required this.torrentScreenItems, |
| 24 | + required this.contextMenuItems, |
18 | 25 | }) : super(key: key);
|
19 | 26 |
|
| 27 | + @override |
| 28 | + State<UserInterfaceSection> createState() => _UserInterfaceSectionState(); |
| 29 | +} |
| 30 | + |
| 31 | +class _UserInterfaceSectionState extends State<UserInterfaceSection> { |
20 | 32 | @override
|
21 | 33 | Widget build(BuildContext context) {
|
22 | 34 | final AppLocalizations l10n = context.l10n;
|
23 | 35 | return BlocBuilder<LanguageBloc, LanguageState>(builder: (context, state) {
|
24 | 36 | String selectedLanguageCode = state.locale?.languageCode ?? 'auto';
|
25 | 37 | String selectedLanguage = Languages[selectedLanguageCode] ?? 'Automatic';
|
26 |
| - return ExpansionTileCard( |
27 |
| - key: Key('User Interface Expansion Card'), |
28 |
| - onExpansionChanged: (value) {}, |
29 |
| - elevation: 0, |
30 |
| - expandedColor: ThemeBloc.theme(themeIndex).primaryColor, |
31 |
| - baseColor: ThemeBloc.theme(themeIndex).primaryColor, |
32 |
| - expandedTextColor: ThemeBloc.theme(themeIndex).colorScheme.secondary, |
33 |
| - title: MText(text: l10n.settings_tabs_user_interface), |
34 |
| - leading: Icon(Icons.mobile_friendly), |
35 |
| - contentPadding: EdgeInsets.all(0), |
36 |
| - children: [ |
37 |
| - Column( |
38 |
| - key: Key('User Interface options display column'), |
39 |
| - crossAxisAlignment: CrossAxisAlignment.start, |
40 |
| - mainAxisAlignment: MainAxisAlignment.start, |
| 38 | + return BlocBuilder<UserInterfaceBloc, UserInterfaceState>( |
| 39 | + builder: (context, userInterfaceState) { |
| 40 | + return ExpansionTileCard( |
| 41 | + key: Key('User Interface Expansion Card'), |
| 42 | + onExpansionChanged: (value) {}, |
| 43 | + elevation: 0, |
| 44 | + expandedColor: ThemeBloc.theme(widget.themeIndex).primaryColor, |
| 45 | + baseColor: ThemeBloc.theme(widget.themeIndex).primaryColor, |
| 46 | + expandedTextColor: |
| 47 | + ThemeBloc.theme(widget.themeIndex).colorScheme.secondary, |
| 48 | + title: MText(text: l10n.settings_tabs_user_interface), |
| 49 | + leading: Icon(Icons.mobile_friendly), |
| 50 | + contentPadding: EdgeInsets.all(0), |
41 | 51 | children: [
|
42 |
| - Container( |
43 |
| - width: double.infinity, |
44 |
| - ), |
45 |
| - SText( |
46 |
| - text: l10n.settings_language_section_heading, |
47 |
| - themeIndex: themeIndex), |
48 |
| - SizedBox(height: 15), |
49 | 52 | Column(
|
| 53 | + key: Key('User Interface options display column'), |
50 | 54 | crossAxisAlignment: CrossAxisAlignment.start,
|
| 55 | + mainAxisAlignment: MainAxisAlignment.start, |
51 | 56 | children: [
|
52 | 57 | Container(
|
53 |
| - padding: EdgeInsets.symmetric(horizontal: 20), |
54 |
| - width: double.infinity, |
55 |
| - height: 60, |
56 |
| - decoration: BoxDecoration( |
57 |
| - color: ThemeBloc.theme(themeIndex).primaryColorLight, |
58 |
| - border: null, |
59 |
| - borderRadius: BorderRadius.circular(8), |
60 |
| - ), |
61 |
| - child: Center( |
62 |
| - child: DropdownButtonFormField<String>( |
63 |
| - key: Key('Select Language Dropdown'), |
64 |
| - dropdownColor: |
65 |
| - ThemeBloc.theme(themeIndex).primaryColorLight, |
66 |
| - isExpanded: true, |
67 |
| - decoration: InputDecoration( |
68 |
| - enabledBorder: InputBorder.none, |
69 |
| - ), |
70 |
| - icon: Icon( |
71 |
| - Icons.arrow_drop_down, |
72 |
| - color: ThemeBloc.theme(themeIndex) |
73 |
| - .textTheme |
74 |
| - .bodyLarge |
75 |
| - ?.color, |
76 |
| - size: 25, |
| 58 | + width: double.infinity, |
| 59 | + ), |
| 60 | + SText( |
| 61 | + text: l10n.settings_language_section_heading, |
| 62 | + themeIndex: widget.themeIndex), |
| 63 | + SizedBox(height: widget.hp * 0.02), |
| 64 | + Column( |
| 65 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 66 | + children: [ |
| 67 | + Container( |
| 68 | + padding: EdgeInsets.symmetric(horizontal: 20), |
| 69 | + width: double.infinity, |
| 70 | + height: widget.hp * 0.072, |
| 71 | + decoration: BoxDecoration( |
| 72 | + color: ThemeBloc.theme(widget.themeIndex) |
| 73 | + .primaryColorLight, |
| 74 | + border: null, |
| 75 | + borderRadius: BorderRadius.circular(8), |
77 | 76 | ),
|
78 |
| - items: Languages.values |
79 |
| - .map((e) => DropdownMenuItem( |
80 |
| - value: e, |
81 |
| - child: Text(e), |
82 |
| - )) |
83 |
| - .toList(), |
84 |
| - onChanged: (newselectedLanguage) { |
85 |
| - Languages.forEach((key, value) { |
86 |
| - if (value == newselectedLanguage) { |
87 |
| - selectedLanguageCode = key; |
88 |
| - selectedLanguage = value; |
| 77 | + child: Center( |
| 78 | + child: DropdownButtonFormField<String>( |
| 79 | + key: Key('Select Language Dropdown'), |
| 80 | + dropdownColor: ThemeBloc.theme(widget.themeIndex) |
| 81 | + .primaryColorLight, |
| 82 | + isExpanded: true, |
| 83 | + decoration: InputDecoration( |
| 84 | + enabledBorder: InputBorder.none, |
| 85 | + ), |
| 86 | + icon: Icon( |
| 87 | + Icons.arrow_drop_down, |
| 88 | + color: ThemeBloc.theme(widget.themeIndex) |
| 89 | + .textTheme |
| 90 | + .bodyLarge |
| 91 | + ?.color, |
| 92 | + size: 25, |
| 93 | + ), |
| 94 | + items: Languages.values |
| 95 | + .map((e) => DropdownMenuItem( |
| 96 | + value: e, |
| 97 | + child: Text(e), |
| 98 | + )) |
| 99 | + .toList(), |
| 100 | + onChanged: (newselectedLanguage) { |
| 101 | + Languages.forEach((key, value) { |
| 102 | + if (value == newselectedLanguage) { |
| 103 | + selectedLanguageCode = key; |
| 104 | + selectedLanguage = value; |
| 105 | + } |
| 106 | + }); |
| 107 | + }, |
| 108 | + value: selectedLanguage, |
| 109 | + ), |
| 110 | + )), |
| 111 | + ], |
| 112 | + ), |
| 113 | + SizedBox(height: widget.hp * 0.02), |
| 114 | + Row( |
| 115 | + children: [ |
| 116 | + Expanded(child: Container()), |
| 117 | + Expanded( |
| 118 | + child: Container( |
| 119 | + height: widget.hp * 0.06, |
| 120 | + decoration: BoxDecoration( |
| 121 | + borderRadius: BorderRadius.circular(8)), |
| 122 | + child: ElevatedButton( |
| 123 | + onPressed: () async { |
| 124 | + if (selectedLanguage == 'Automatic') { |
| 125 | + BlocProvider.of<LanguageBloc>(context, |
| 126 | + listen: false) |
| 127 | + .add(ChangeLanguageEvent(null)); |
| 128 | + } else { |
| 129 | + BlocProvider.of<LanguageBloc>(context, |
| 130 | + listen: false) |
| 131 | + .add(ChangeLanguageEvent( |
| 132 | + Locale(selectedLanguageCode))); |
89 | 133 | }
|
90 |
| - }); |
91 |
| - }, |
92 |
| - value: selectedLanguage, |
| 134 | + await Future.delayed(Duration.zero); |
| 135 | + final setSpeedSnackbar = addFloodSnackBar( |
| 136 | + SnackbarType.information, |
| 137 | + context.l10n.settings_language_set_snackbar, |
| 138 | + context.l10n.button_dismiss, |
| 139 | + ); |
| 140 | + ScaffoldMessenger.of(context).clearSnackBars(); |
| 141 | + ScaffoldMessenger.of(context) |
| 142 | + .showSnackBar(setSpeedSnackbar); |
| 143 | + }, |
| 144 | + style: ElevatedButton.styleFrom( |
| 145 | + shape: RoundedRectangleBorder( |
| 146 | + borderRadius: BorderRadius.circular(8), |
| 147 | + ), |
| 148 | + backgroundColor: |
| 149 | + ThemeBloc.theme(widget.themeIndex) |
| 150 | + .colorScheme |
| 151 | + .secondary, |
| 152 | + ), |
| 153 | + child: Center( |
| 154 | + child: Text( |
| 155 | + l10n.button_set, |
| 156 | + style: TextStyle( |
| 157 | + color: Colors.white, |
| 158 | + fontSize: 16, |
| 159 | + fontWeight: FontWeight.w600, |
| 160 | + ), |
| 161 | + ), |
| 162 | + ), |
| 163 | + ), |
93 | 164 | ),
|
94 |
| - )), |
95 |
| - ], |
96 |
| - ), |
97 |
| - SizedBox(height: 25), |
98 |
| - Row( |
99 |
| - children: [ |
100 |
| - Expanded(child: Container()), |
101 |
| - Expanded( |
102 |
| - child: Container( |
103 |
| - height: hp * 0.06, |
104 |
| - decoration: |
105 |
| - BoxDecoration(borderRadius: BorderRadius.circular(8)), |
106 |
| - child: ElevatedButton( |
107 |
| - onPressed: () async { |
108 |
| - if (selectedLanguage == 'Automatic') { |
109 |
| - BlocProvider.of<LanguageBloc>(context, |
110 |
| - listen: false) |
111 |
| - .add(ChangeLanguageEvent(null)); |
112 |
| - } else { |
113 |
| - BlocProvider.of<LanguageBloc>(context, |
114 |
| - listen: false) |
115 |
| - .add(ChangeLanguageEvent( |
116 |
| - Locale(selectedLanguageCode))); |
117 |
| - } |
118 |
| - await Future.delayed(Duration.zero); |
119 |
| - final setSpeedSnackbar = addFloodSnackBar( |
120 |
| - SnackbarType.information, |
121 |
| - l10n.settings_language_set_snackbar, |
122 |
| - l10n.button_dismiss, |
| 165 | + ), |
| 166 | + ], |
| 167 | + ), |
| 168 | + SizedBox(height: widget.hp * 0.03), |
| 169 | + SText( |
| 170 | + text: l10n.torrent_screen_items_heading, |
| 171 | + themeIndex: widget.themeIndex, |
| 172 | + ), |
| 173 | + SizedBox(height: widget.hp * 0.02), |
| 174 | + Container( |
| 175 | + height: widget.hp * 0.4, |
| 176 | + decoration: BoxDecoration( |
| 177 | + color: ThemeBloc.theme(widget.themeIndex) |
| 178 | + .primaryColorLight, |
| 179 | + borderRadius: BorderRadius.circular(8), |
| 180 | + ), |
| 181 | + margin: EdgeInsets.symmetric(horizontal: 5), |
| 182 | + child: ListView.separated( |
| 183 | + itemBuilder: (BuildContext context, int index) { |
| 184 | + return CheckboxListTile( |
| 185 | + key: Key(widget.torrentScreenItems.keys |
| 186 | + .elementAt(index) |
| 187 | + .toString()), |
| 188 | + activeColor: ThemeBloc.theme(widget.themeIndex) |
| 189 | + .primaryColorDark, |
| 190 | + value: widget.torrentScreenItems.values |
| 191 | + .elementAt(index), |
| 192 | + onChanged: (value) { |
| 193 | + setState(() { |
| 194 | + widget.torrentScreenItems.update( |
| 195 | + widget.torrentScreenItems.keys |
| 196 | + .elementAt(index), |
| 197 | + (value) => !value); |
| 198 | + }); |
| 199 | + }, |
| 200 | + title: Text(widget.torrentScreenItems.keys |
| 201 | + .elementAt(index)), |
123 | 202 | );
|
124 |
| - ScaffoldMessenger.of(context).clearSnackBars(); |
125 |
| - ScaffoldMessenger.of(context) |
126 |
| - .showSnackBar(setSpeedSnackbar); |
127 | 203 | },
|
128 |
| - style: ElevatedButton.styleFrom( |
129 |
| - shape: RoundedRectangleBorder( |
130 |
| - borderRadius: BorderRadius.circular(8), |
131 |
| - ), |
132 |
| - backgroundColor: |
133 |
| - ThemeBloc.theme(themeIndex).colorScheme.secondary, |
134 |
| - ), |
135 |
| - child: Center( |
136 |
| - child: Text( |
137 |
| - l10n.button_set, |
138 |
| - style: TextStyle( |
139 |
| - color: Colors.white, |
140 |
| - fontSize: 16, |
141 |
| - fontWeight: FontWeight.w600, |
| 204 | + separatorBuilder: (BuildContext context, int index) { |
| 205 | + return Padding( |
| 206 | + padding: const EdgeInsets.symmetric(horizontal: 5), |
| 207 | + child: Divider( |
| 208 | + color: Colors.grey[400], |
| 209 | + height: 2, |
142 | 210 | ),
|
| 211 | + ); |
| 212 | + }, |
| 213 | + itemCount: widget.torrentScreenItems.length, |
| 214 | + )), |
| 215 | + SizedBox(height: widget.hp * 0.02), |
| 216 | + SText( |
| 217 | + text: l10n.context_menu_items_heading, |
| 218 | + themeIndex: widget.themeIndex, |
| 219 | + ), |
| 220 | + SizedBox(height: widget.hp * 0.02), |
| 221 | + Container( |
| 222 | + height: widget.hp * 0.4, |
| 223 | + decoration: BoxDecoration( |
| 224 | + color: |
| 225 | + ThemeBloc.theme(widget.themeIndex).primaryColorLight, |
| 226 | + borderRadius: BorderRadius.circular(8), |
| 227 | + ), |
| 228 | + margin: EdgeInsets.symmetric(horizontal: 5), |
| 229 | + child: ListView.separated( |
| 230 | + itemBuilder: (BuildContext context, int index) { |
| 231 | + return CheckboxListTile( |
| 232 | + key: Key(widget.contextMenuItems.keys |
| 233 | + .elementAt(index) |
| 234 | + .toString()), |
| 235 | + activeColor: ThemeBloc.theme(widget.themeIndex) |
| 236 | + .primaryColorDark, |
| 237 | + value: |
| 238 | + widget.contextMenuItems.values.elementAt(index), |
| 239 | + onChanged: (value) { |
| 240 | + setState(() { |
| 241 | + widget.contextMenuItems.update( |
| 242 | + widget.contextMenuItems.keys.elementAt(index), |
| 243 | + (value) => !value); |
| 244 | + }); |
| 245 | + }, |
| 246 | + title: Text( |
| 247 | + widget.contextMenuItems.keys.elementAt(index)), |
| 248 | + ); |
| 249 | + }, |
| 250 | + separatorBuilder: (BuildContext context, int index) { |
| 251 | + return Padding( |
| 252 | + padding: const EdgeInsets.symmetric(horizontal: 5), |
| 253 | + child: Divider( |
| 254 | + color: Colors.grey[400], |
| 255 | + height: 2, |
143 | 256 | ),
|
144 |
| - ), |
145 |
| - ), |
| 257 | + ); |
| 258 | + }, |
| 259 | + itemCount: widget.contextMenuItems.length, |
146 | 260 | ),
|
147 | 261 | ),
|
148 | 262 | ],
|
149 |
| - ), |
150 |
| - SizedBox(height: 25), |
| 263 | + ) |
151 | 264 | ],
|
152 |
| - ) |
153 |
| - ], |
| 265 | + ); |
| 266 | + }, |
154 | 267 | );
|
155 | 268 | });
|
156 | 269 | }
|
|
0 commit comments