-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathview_selector.dart
103 lines (96 loc) · 2.42 KB
/
view_selector.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
///
/// Created by NieBin on 18-12-3
/// Github: https://github.com/nb312
/// Email: niebin312@gmail.com
///
import "package:flutter/material.dart";
import '../constant/size_const.dart';
class ViewSelector extends StatefulWidget {
ViewSelector(
{Key key,
this.title,
this.values,
this.onClick,
this.mainColor = Colors.white})
: super(key: key);
final String title;
final List<String> values;
final ValueChanged<int> onClick;
final Color mainColor;
@override
_ViewSelectorState createState() => _ViewSelectorState();
}
class _ViewSelectorState extends State<ViewSelector> {
var curPos = 0;
void _update() {
setState(() {});
widget.onClick(curPos);
}
void _next() {
curPos++;
if (curPos >= widget.values.length) {
curPos = 0;
}
_update();
}
void _back() {
curPos--;
if (curPos < 0) {
curPos = widget.values.length - 1;
}
_update();
}
@override
Widget build(BuildContext context) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Divider(color: widget.mainColor),
Padding(
padding: EdgeInsets.all(1),
child: Center(
child: Text(
widget.title,
style: TextStyle(
color: widget.mainColor,
fontSize: TEXT_NORMAL_SIZE,
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
IconButton(
icon: Icon(
Icons.arrow_left,
color: widget.mainColor,
),
onPressed: _back,
),
Text(
widget.values[curPos],
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.w700,
color: widget.mainColor,
fontSize: TEXT_NORMAL_SIZE,
),
),
IconButton(
icon: Icon(
Icons.arrow_right,
color: widget.mainColor,
),
onPressed: _next,
),
],
),
],
),
);
}
}