Skip to content

Commit fe897e0

Browse files
committed
feat(CellSelect): add CellSelect widget
1 parent ad553aa commit fe897e0

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

lib/cells.dart

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:meta/meta.dart';
33
import 'package:flutter/services.dart';
4+
import 'action_sheet.dart';
45

56
class Cells extends StatelessWidget {
67
Cells({@required this.children, Key key}) : super(key: key);
@@ -37,7 +38,79 @@ class Cells extends StatelessWidget {
3738
}
3839
}
3940

40-
enum KeyBoardType { text, number, password }
41+
class CellSelect extends StatefulWidget {
42+
CellSelect({Key key, this.label = "label", @required this.options, this.onChanged, this.initialIndex = 0})
43+
: assert(options != null),
44+
super(key: key);
45+
final String label;
46+
final List<String> options;
47+
final ValueChanged<String> onChanged;
48+
final int initialIndex;
49+
@override
50+
_CellSelectState createState() => _CellSelectState();
51+
}
52+
53+
class _CellSelectState extends State<CellSelect> {
54+
String value;
55+
56+
_handleTap(BuildContext context) {
57+
ActionSheet.show(
58+
context: context,
59+
data: widget.options,
60+
onPress: (detail) {
61+
setState(() {
62+
value = detail.text;
63+
});
64+
if (widget.onChanged != null) widget.onChanged(detail.text);
65+
});
66+
}
67+
68+
@override
69+
void initState() {
70+
super.initState();
71+
value = widget.options.elementAt(widget.initialIndex);
72+
}
73+
74+
@override
75+
Widget build(BuildContext context) {
76+
return GestureDetector(
77+
onTap: () => _handleTap(context),
78+
child: Container(
79+
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
80+
color: Colors.white,
81+
child: Row(
82+
crossAxisAlignment: CrossAxisAlignment.center,
83+
children: <Widget>[
84+
SizedBox(
85+
child: Text(
86+
widget.label,
87+
style: TextStyle(
88+
fontSize: 17,
89+
),
90+
),
91+
width: 105,
92+
),
93+
Expanded(
94+
child: Text(
95+
value,
96+
style: TextStyle(
97+
fontSize: 17,
98+
),
99+
),
100+
),
101+
Icon(
102+
Icons.chevron_right,
103+
color: Color(0xFF888888),
104+
size: 20,
105+
),
106+
],
107+
),
108+
),
109+
);
110+
}
111+
}
112+
113+
enum KeyBoardType { text, number, password }
41114

42115
class CellInput extends StatelessWidget {
43116
CellInput({Key key, this.placeholder, this.label = "label", this.onChanged, this.keyBoardType = KeyBoardType.text}) : super(key: key);
@@ -51,7 +124,6 @@ class CellInput extends StatelessWidget {
51124
}
52125

53126
TextInputType _getKeyBorderType() {
54-
55127
Map<KeyBoardType, TextInputType> map = const {
56128
KeyBoardType.text: TextInputType.text,
57129
KeyBoardType.number: TextInputType.number,
@@ -64,6 +136,7 @@ class CellInput extends StatelessWidget {
64136
Widget build(BuildContext context) {
65137
return Container(
66138
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
139+
color: Colors.white,
67140
child: Row(
68141
crossAxisAlignment: CrossAxisAlignment.center,
69142
children: <Widget>[

0 commit comments

Comments
 (0)