gpt4 book ai didi

ios - 如何从数据库值创建 cupertinoactionsheet

转载 作者:行者123 更新时间:2023-11-29 05:29:46 27 4
gpt4 key购买 nike

我正在尝试返回 cupertinoactionsheet 以在未来的构建器上使用它。这些值存储在本地

到目前为止,我只能检索 cupertinoactionsheetactions。

我尝试返回整个操作表,但失败了

我们的目标是让应用程序看起来尽可能地原生。这就是我不想使用任何 Material 小部件的原因

欢迎任何答案

非常感谢

void _modalBottomSheetMenu() {
showCupertinoModalPopup(
context: context,
builder: (builder) {
return new Container(
height: 450.0,
color: Color(0xFF737373),

child: new Container(
decoration: new BoxDecoration(
color: CupertinoColors.white,
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(10.0),
topRight: const Radius.circular(10.0))),
child:
// some more code

new FutureBuilder(
future: plates,
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:

case ConnectionState.waiting:
return new Text('loading...');
default:
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
else
return createListView(context, snapshot);
}
},
)
])),
);
});
}


Widget createListView(BuildContext context, AsyncSnapshot snapshot) {
List<String> values = snapshot.data;
return new ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: values.length,
itemBuilder: (BuildContext context, int index) {
return new Column(
children: <Widget>[
new CupertinoActionSheetAction(
//leading: new Icon(CupertinoIcons.directions_car),
child: new Text(values[index]),
onPressed: () => {
setState(() {
_carplate = values[index];
}),
Navigator.pop(context)
}),
],
);
},
);
}


最佳答案

虽然上述代码有效,但请注意,将所有 CupertinoActionSheetAction 嵌入到一个容器中将导致在点击其中任何一个时,所有这些操作都会突出显示。

这是 flutter 的官方文档:

Future<void> _handleClickMe() async {
return showCupertinoModalPopup<void>(
context: context,
builder: (BuildContext context) {
return CupertinoActionSheet(
title: Text('Favorite Dessert'),
message: Text('Please select the best dessert from the options below.'),
actions: <Widget>[
CupertinoActionSheetAction(
child: Text('Profiteroles'),
onPressed: () { /** */ },
),
CupertinoActionSheetAction(
child: Text('Cannolis'),
onPressed: () { /** */ },
),
CupertinoActionSheetAction(
child: Text('Trifie'),
onPressed: () { /** */ },
),
],
cancelButton: CupertinoActionSheetAction(
isDefaultAction: true,
child: Text('Cancel'),
onPressed: () { /** */ },
),
);
},
);
}

下面是我如何使动态项目列表执行相同的行为。当用户点击一个选项时,CupertinoActionSheetAction 将突出显示,并且您还将按预期注意到项目之间的分隔符。

void _showActionSheetIOS(context, Customer customer) {
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) => CupertinoActionSheet(
title: Text('Choose an option for ${customer.name}'),
message: const Text('Your options are '),
actions: _yourLstCustomerObjs
.map((item) => CupertinoActionSheetAction(
child: Text(item.option),
onPressed: () {
Navigator.pop(context);
_selectItem(item);
},
))
.toList(),
cancelButton: CupertinoActionSheetAction(
child: const Text('Cancel'),
isDefaultAction: true,
onPressed: () {
Navigator.pop(context, 'Cancel');
},
)),
);
}

关于ios - 如何从数据库值创建 cupertinoactionsheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57756596/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com