-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathweb_settings_tile.dart
170 lines (164 loc) · 6.05 KB
/
web_settings_tile.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:settings_ui/settings_ui.dart';
class WebSettingsTile extends StatelessWidget {
const WebSettingsTile({
required this.tileType,
required this.leading,
required this.title,
required this.description,
required this.onPressed,
required this.onToggle,
required this.value,
required this.initialValue,
required this.activeSwitchColor,
required this.enabled,
required this.trailing,
required this.compact,
Key? key,
}) : super(key: key);
final SettingsTileType tileType;
final Widget? leading;
final Widget? title;
final Widget? description;
final Function(BuildContext context)? onPressed;
final Function(bool value)? onToggle;
final Widget? value;
final bool initialValue;
final bool enabled;
final Widget? trailing;
final Color? activeSwitchColor;
final bool compact;
@override
Widget build(BuildContext context) {
final theme = SettingsTheme.of(context);
final scaleFactor = MediaQuery.of(context).textScaleFactor;
final double tilePadding = this.compact ? 10 : 19;
final cantShowAnimation = tileType == SettingsTileType.switchTile
? onToggle == null && onPressed == null
: onPressed == null;
return IgnorePointer(
ignoring: !enabled,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: cantShowAnimation
? null
: () {
if (tileType == SettingsTileType.switchTile) {
onToggle?.call(!initialValue);
} else {
onPressed?.call(context);
}
},
highlightColor: theme.themeData.tileHighlightColor,
child: Container(
child: Row(
children: [
if (leading != null)
Padding(
padding: const EdgeInsetsDirectional.only(
start: 24,
),
child: IconTheme(
data: IconTheme.of(context).copyWith(
color: theme.themeData.leadingIconsColor,
),
child: leading!,
),
),
Expanded(
child: Padding(
padding: EdgeInsetsDirectional.only(
start: 24,
end: 24,
bottom: tilePadding * scaleFactor,
top: tilePadding * scaleFactor,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DefaultTextStyle(
style: TextStyle(
color: theme.themeData.settingsTileTextColor,
fontSize: 18,
fontWeight: FontWeight.w400,
),
child: title ?? Container(),
),
if (value != null)
Padding(
padding: EdgeInsets.only(top: 4.0),
child: DefaultTextStyle(
style: TextStyle(
color: theme.themeData.tileDescriptionTextColor,
),
child: value!,
),
)
else if (description != null)
Padding(
padding: EdgeInsets.only(top: 4.0),
child: DefaultTextStyle(
style: TextStyle(
color: theme.themeData.tileDescriptionTextColor,
),
child: description!,
),
),
],
),
),
),
// if (tileType == SettingsTileType.navigationTile)
// Padding(
// padding:
// const EdgeInsetsDirectional.only(start: 6, end: 15),
// child: IconTheme(
// data: IconTheme.of(context)
// .copyWith(color: theme.themeData.leadingIconsColor),
// child: Icon(
// CupertinoIcons.chevron_forward,
// size: 18 * scaleFactor,
// ),
// ),
// ),
if (trailing != null && tileType == SettingsTileType.switchTile)
Row(
children: [
trailing!,
Padding(
padding: const EdgeInsetsDirectional.only(end: 8),
child: Switch(
activeColor: activeSwitchColor ??
Color.fromRGBO(138, 180, 248, 1.0),
value: initialValue,
onChanged: onToggle,
),
),
],
)
else if (tileType == SettingsTileType.switchTile)
Padding(
padding:
const EdgeInsetsDirectional.only(start: 16, end: 8),
child: Switch(
value: initialValue,
activeColor: activeSwitchColor ??
Color.fromRGBO(138, 180, 248, 1.0),
onChanged: onToggle,
),
)
else if (trailing != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: trailing!,
),
],
),
),
),
),
);
}
}