1
+ import 'dart:async' ;
2
+
1
3
import 'package:drift/drift.dart' hide Column;
4
+ import 'package:flutter/foundation.dart' ;
2
5
import 'package:flutter/material.dart' ;
3
6
4
7
import '../generated/l10n/zulip_localizations.dart' ;
5
8
import '../model/database.dart' ;
6
9
import '../model/settings.dart' ;
7
10
import 'page.dart' ;
8
11
import 'store.dart' ;
12
+ import 'text.dart' ;
9
13
10
14
class SettingsPage extends StatelessWidget {
11
15
const SettingsPage ({super .key});
@@ -18,46 +22,86 @@ class SettingsPage extends StatelessWidget {
18
22
Widget build (BuildContext context) {
19
23
final globalStore = GlobalStoreWidget .of (context);
20
24
final zulipLocalizations = ZulipLocalizations .of (context);
25
+ final themeData = Theme .of (context);
21
26
22
27
return Scaffold (
23
28
appBar: AppBar (title: Text (zulipLocalizations.settingsPageTitle)),
24
- body: Column (children: [
25
- _Select (initialValue: globalStore.globalSettings.themeSetting),
26
- ]));
29
+ body: SafeArea (
30
+ bottom: false ,
31
+ child: SingleChildScrollView (
32
+ child: SafeArea (
33
+ minimum: const EdgeInsets .only (bottom: 8 ),
34
+ child: Column (children: [
35
+ Theme (
36
+ data: themeData.copyWith (splashColor: Colors .transparent),
37
+ child: _ThemeSetting (initialValue: globalStore.globalSettings.themeSetting)),
38
+ ]),
39
+ ))));
27
40
}
28
41
}
29
42
30
- class _Select extends StatefulWidget {
31
- const _Select ({required this .initialValue});
43
+ class _ThemeSetting extends StatefulWidget {
44
+ const _ThemeSetting ({required this .initialValue});
32
45
33
46
final ThemeSetting initialValue;
34
47
35
48
@override
36
- State <_Select > createState () => _SelectState ();
49
+ State <_ThemeSetting > createState () => _ThemeSettingState ();
37
50
}
38
51
39
- class _SelectState extends State <_Select > {
40
- late ThemeSetting value = widget.initialValue;
52
+ class _ThemeSettingState extends State <_ThemeSetting > {
53
+ late ThemeSetting currentThemeSetting = widget.initialValue;
54
+ static const entryHeight = 38.0 ;
41
55
42
56
@override
43
57
Widget build (BuildContext context) {
44
58
final globalStore = GlobalStoreWidget .of (context);
45
- return Column (
46
- children: [
47
- const ListTile (title: Text ('Theme' )),
48
- for (final option in ThemeSetting .values)
49
- ListTile (
50
- title: Text (option.name),
51
- leading: Radio .adaptive (
52
- value: option,
53
- groupValue: value,
59
+ final zulipLocalizations = ZulipLocalizations .of (context);
60
+ final themeSettingOptions = [
61
+ ThemeSetting .dark,
62
+ ThemeSetting .light,
63
+ ThemeSetting .unset,
64
+ ];
65
+ debugDefaultTargetPlatformOverride = TargetPlatform .iOS;
66
+ return ListTileTheme (
67
+ data: const ListTileThemeData (
68
+ contentPadding: EdgeInsets .symmetric (horizontal: 8 ),
69
+ dense: true ,
70
+ minVerticalPadding: 0 ,
71
+ minTileHeight: 38 ,
72
+
73
+ horizontalTitleGap: 0 ,
74
+ minLeadingWidth: 38 ,
75
+ ),
76
+ child: Column (
77
+ children: [
78
+ Container (
79
+ height: entryHeight,
80
+ padding: const EdgeInsets .symmetric (horizontal: 16 ),
81
+ alignment: Alignment .bottomLeft,
82
+ child: Text (zulipLocalizations.themeSettingLabel,
83
+ style: const TextStyle (
84
+ fontSize: 18 ,
85
+ height: 19 / 18 ,
86
+ ).merge (weightVariableTextStyle (context, wght: 600 )))),
87
+ for (final themeSettingOption in themeSettingOptions)
88
+ RadioListTile (
89
+ title: Text (themeSettingOption.displayName (zulipLocalizations),
90
+ style: const TextStyle (
91
+ fontSize: 19 ,
92
+ height: 26 / 19 )),
93
+ groupValue: currentThemeSetting,
94
+ value: themeSettingOption,
95
+ // This hides the circular overlay over the Radio, and leaves
96
+ // the overlay over the ListTile unaffected.
97
+ overlayColor: const WidgetStatePropertyAll (Colors .transparent),
54
98
onChanged: (newValue) {
55
99
setState (() {
56
- value = newValue! ;
100
+ currentThemeSetting = newValue! ;
57
101
});
58
- globalStore.updateGlobalSettings (GlobalSettingsCompanion (
59
- themeSetting: Value (value )));
60
- })) ,
61
- ] );
102
+ unawaited ( globalStore.updateGlobalSettings (GlobalSettingsCompanion (
103
+ themeSetting: Value (currentThemeSetting) )));
104
+ }),
105
+ ]) );
62
106
}
63
107
}
0 commit comments