问题描述
您好,我的问题是关于构建一个好的 alertdialog
。
我有一个 Listtile Listtile
,其中 leading
是一种颜色,title
是颜色的名称。
点按 Listtile
会显示带有颜色选项的警告对话框。
这是我期待存档的内容。
我希望通过在颜色上使用地图并在警报对话框中将它们打印为 Listview
来存档此结果。预先感谢您的帮助
解决方法
这个问题不就是如何将东西发送到另一个页面吗?
根据评论,您想通过他们的名字传递颜色。所以它可以像这样传递到第二个屏幕。
第一页,
var colors = {};
colors['color_x'] = 'COLORX';
colors['color_y'] = 'COLORY';
Navigator.push(
context,MaterialPageRoute(
builder: (context) => SecondScreen(colors: colors),),);
在第二页,
class SecondScreen extends StatelessWidget {
final Map colors;
SecondScreen({Key key,@required this.colors}) : super(key: key);
...
}
,
-
创建枚举:
enum ColorEnum {red,green,blue}
-
第 2 页:
Navigator.of(context).pop(ColorEnum.red);
-
如果你使用 Dialog call .then 之后:
showDialog().then(colorValue){ //你的代码 };
-
如果您使用 Navigator 推送新页面:在它之后使用 .then:
导航器.push( 语境, 材质页面路由( 构建器:(上下文)=> SecondScreen(颜色:颜色), ),).then(colorValue){//你的代码}