Skip to content

Commit a0620c2

Browse files
committed
perf(action_sheet): the show function adds the containerColor and textColor parameters
1 parent 1775008 commit a0620c2

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/action_sheet.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ class ActionSheetPressDetails {
1313

1414
typedef ActionSheetPressVoidCallBack = void Function(ActionSheetPressDetails details);
1515

16-
1716
///展示手机action
1817
class ActionSheet {
1918
///展示ActionSheet
20-
static show({BuildContext context, List<String> data, ActionSheetPressVoidCallBack onPress}) {
19+
static show({
20+
BuildContext context,
21+
List<String> data,
22+
ActionSheetPressVoidCallBack onPress,
23+
Color containerColor = const Color(0xEFEFF4),
24+
Color textColor = Colors.black,
25+
}) {
2126
List<Widget> widgets = List<Widget>();
2227
for (int i = data.length - 1; i >= 0; i--) {
2328
widgets.insert(
2429
0,
2530
_Cell(
31+
textColor: textColor,
2632
text: data.elementAt(i),
2733
onPressed: () {
2834
if (onPress != null) onPress(ActionSheetPressDetails(index: i, text: data.elementAt(i)));
@@ -34,6 +40,7 @@ class ActionSheet {
3440
widgets.add(Padding(
3541
padding: const EdgeInsets.only(top: 6),
3642
child: _Cell(
43+
textColor: textColor,
3744
text: "取消",
3845
onPressed: () => Navigator.of(context).pop(),
3946
),
@@ -42,7 +49,7 @@ class ActionSheet {
4249
context: context,
4350
builder: (BuildContext context) {
4451
return Container(
45-
color: Color(0xEFEFF4),
52+
color: containerColor,
4653
child: Column(
4754
mainAxisSize: MainAxisSize.min,
4855
children: widgets.toList(),
@@ -53,10 +60,11 @@ class ActionSheet {
5360
}
5461

5562
class _Cell extends StatefulWidget {
56-
_Cell({Key key, this.text, this.onPressed}) : super(key: key);
63+
_Cell({Key key, this.text, this.onPressed,this.textColor}) : super(key: key);
5764

5865
final String text;
5966
final VoidCallback onPressed;
67+
final Color textColor;
6068

6169
@override
6270
__CellState createState() => __CellState();
@@ -92,7 +100,7 @@ class __CellState extends State<_Cell> {
92100
children: <Widget>[
93101
Text(
94102
widget.text,
95-
style: TextStyle(fontSize: 18),
103+
style: TextStyle(fontSize: 18, color: widget.textColor),
96104
)
97105
],
98106
),

0 commit comments

Comments
 (0)