-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswitches_page.dart
84 lines (79 loc) · 2.37 KB
/
switches_page.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
import 'package:example/helpers.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:platty/platty.dart';
class SwitchesPage extends StatefulWidget {
@override
SwitchesPageState createState() {
return new SwitchesPageState();
}
}
class SwitchesPageState extends State<SwitchesPage> {
var states = [false, false, false];
_buildSwitch({String title, Widget Function() switchBuilder}) => Padding(
padding: EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: Text(title),
),
switchBuilder(),
],
),
);
_updateState(int index) {
setState(() {
states[index] = !states[index];
});
}
@override
Widget build(BuildContext context) {
return PScaffold(
appBar: navBarFor(title: "Switches"),
backgroundColor: Colors.white,
child: Row(
children: <Widget>[
Column(
children: <Widget>[
_buildSwitch(
title: "Platform Switch",
switchBuilder: () => PSwitch(
value: states[0],
androidInactiveThumbColor: Colors.grey,
activeColor: Colors.red,
onChanged: (value) {
_updateState(0);
},
),
),
_buildSwitch(
title: "IOS Switch",
switchBuilder: () => PSwitch(
activeColor: Colors.red,
renderPlatform: TargetPlatform.iOS,
value: states[1],
onChanged: (value) {
_updateState(1);
},
),
),
_buildSwitch(
title: "Android Switch",
switchBuilder: () => PSwitch(
activeColor: Colors.red,
androidInactiveThumbColor: Colors.white,
renderPlatform: TargetPlatform.android,
value: states[2],
onChanged: (value) {
_updateState(2);
},
),
),
],
),
],
),
);
}
}