Skip to content

Commit 058a3f3

Browse files
committed
added Cupertino List Tile
1 parent 1d2414c commit 058a3f3

File tree

4 files changed

+146
-20
lines changed

4 files changed

+146
-20
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
4+
class CupertinoSwitchListTile extends StatelessWidget {
5+
/// This has been shamelessly copied from Material/SwitchListTile.
6+
/// The applicable license applies.
7+
/// source: StackOverflow
8+
const CupertinoSwitchListTile({
9+
Key key,
10+
@required this.value,
11+
@required this.onChanged,
12+
this.activeColor,
13+
this.title,
14+
this.subtitle,
15+
this.isThreeLine: false,
16+
this.dense,
17+
this.secondary,
18+
this.selected: false,
19+
}) : assert(value != null),
20+
assert(isThreeLine != null),
21+
assert(!isThreeLine || subtitle != null),
22+
assert(selected != null),
23+
super(key: key);
24+
25+
/// Whether this switch is checked.
26+
///
27+
/// This property must not be null.
28+
final bool value;
29+
30+
/// Called when the user toggles the switch on or off.
31+
///
32+
/// The switch passes the new value to the callback but does not actually
33+
/// change state until the parent widget rebuilds the switch tile with the
34+
/// new value.
35+
///
36+
/// If null, the switch will be displayed as disabled.
37+
///
38+
/// The callback provided to [onChanged] should update the state of the parent
39+
/// [StatefulWidget] using the [State.setState] method, so that the parent
40+
/// gets rebuilt; for example:
41+
///
42+
/// ```dart
43+
/// new SwitchListTile(
44+
/// value: _lights,
45+
/// onChanged: (bool newValue) {
46+
/// setState(() {
47+
/// _lights = newValue;
48+
/// });
49+
/// },
50+
/// title: new Text('Lights'),
51+
/// )
52+
/// ```
53+
final ValueChanged<bool> onChanged;
54+
55+
/// The color to use when this switch is on.
56+
///
57+
/// Defaults to accent color of the current [Theme].
58+
final Color activeColor;
59+
60+
/// The primary content of the list tile.
61+
///
62+
/// Typically a [Text] widget.
63+
final Widget title;
64+
65+
/// Additional content displayed below the title.
66+
///
67+
/// Typically a [Text] widget.
68+
final Widget subtitle;
69+
70+
/// A widget to display on the opposite side of the tile from the switch.
71+
///
72+
/// Typically an [Icon] widget.
73+
final Widget secondary;
74+
75+
/// Whether this list tile is intended to display three lines of text.
76+
///
77+
/// If false, the list tile is treated as having one line if the subtitle is
78+
/// null and treated as having two lines if the subtitle is non-null.
79+
final bool isThreeLine;
80+
81+
/// Whether this list tile is part of a vertically dense list.
82+
///
83+
/// If this property is null then its value is based on [ListTileTheme.dense].
84+
final bool dense;
85+
86+
/// Whether to render icons and text in the [activeColor].
87+
///
88+
/// No effort is made to automatically coordinate the [selected] state and the
89+
/// [value] state. To have the list tile appear selected when the switch is
90+
/// on, pass the same value to both.
91+
///
92+
/// Normally, this property is left to its default value, false.
93+
final bool selected;
94+
95+
@override
96+
Widget build(BuildContext context) {
97+
var color = activeColor ?? Theme.of(context).accentColor;
98+
print("Active color: ${color.red} ${color.green} ${color.blue}");
99+
final Widget control = new CupertinoSwitch(
100+
value: value,
101+
onChanged: onChanged,
102+
activeColor: activeColor ?? CupertinoColors.activeGreen,
103+
);
104+
return new MergeSemantics(
105+
child: ListTileTheme.merge(
106+
selectedColor: activeColor ?? CupertinoColors.activeGreen,
107+
child: new ListTile(
108+
leading: secondary,
109+
title: title,
110+
subtitle: subtitle,
111+
trailing: control,
112+
isThreeLine: isThreeLine,
113+
dense: dense,
114+
enabled: onChanged != null,
115+
onTap: onChanged != null
116+
? () {
117+
onChanged(!value);
118+
}
119+
: null,
120+
selected: selected,
121+
),
122+
),
123+
);
124+
}
125+
}

lib/views/Settings part/AboutPage.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ class AboutAppPage extends StatelessWidget {
159159
textAlign: TextAlign.center,
160160
),
161161
onTap: () {
162-
LaunchUrl.normalLaunchUrl(
163-
url: kReleaseNotesLink, usesWebView: false);
162+
LaunchUrl.normalLaunchUrl(url: kReleaseNotesLink);
164163
},
165164
),
166165
),

lib/views/Settings part/SettingsPage.dart

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:get_storage/get_storage.dart';
44
import 'package:provider/provider.dart';
55
import 'package:waktusolatmalaysia/CONSTANTS.dart' as Constants;
66
import 'package:waktusolatmalaysia/utils/AppInformation.dart';
7+
import 'package:waktusolatmalaysia/utils/cupertinoSwitchListTile.dart';
78
import 'package:waktusolatmalaysia/views/Settings%20part/AboutPage.dart';
89
import 'package:waktusolatmalaysia/views/Settings%20part/settingsProvider.dart';
910

@@ -66,19 +67,17 @@ class _SettingsPageState extends State<SettingsPage> {
6667
height: 5,
6768
),
6869
Card(
69-
child: ListTile(
70+
child: CupertinoSwitchListTile(
7071
title: Text('Show other prayer times'),
7172
subtitle: Text('Imsak, Syuruk, Dhuha'),
72-
trailing: CupertinoSwitch(
73-
onChanged: (bool value) {
74-
setState(() {
75-
setting.showOtherPrayerTime = value;
76-
GetStorage()
77-
.write(Constants.kStoredShowOtherPrayerTime, value);
78-
});
79-
},
80-
value: setting.showOtherPrayerTime,
81-
),
73+
onChanged: (bool value) {
74+
setState(() {
75+
setting.showOtherPrayerTime = value;
76+
GetStorage()
77+
.write(Constants.kStoredShowOtherPrayerTime, value);
78+
});
79+
},
80+
value: setting.showOtherPrayerTime,
8281
),
8382
),
8483
Divider(

lib/views/feedbackPage.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,16 @@ class _FeedbackPageState extends State<FeedbackPage> {
162162
),
163163
Align(
164164
alignment: Alignment.centerLeft,
165-
child: TextButton(
166-
onPressed: () {
167-
LaunchUrl.normalLaunchUrl(
168-
url: Constants.kGithubRepoLink + '/issues');
169-
},
170-
child: Text('Follow issues on GitHub',
171-
style: TextStyle(fontWeight: FontWeight.bold)),
165+
child: Padding(
166+
padding: const EdgeInsets.all(8.0),
167+
child: TextButton(
168+
onPressed: () {
169+
LaunchUrl.normalLaunchUrl(
170+
url: Constants.kGithubRepoLink + '/issues');
171+
},
172+
child: Text('Report / Follow issues on GitHub',
173+
style: TextStyle(fontWeight: FontWeight.bold)),
174+
),
172175
),
173176
),
174177
],

0 commit comments

Comments
 (0)