如何将颜色列表视图放在警报对话框中,以领先为颜色

问题描述

您好,我的问题是关于构建一个好的 alertdialog

我有一个 Listtile Listtile,其中 leading 是一种颜色,title 是颜色的名称。 点按 Listtile显示带有颜色选项的警告对话框。

这是我期待存档的内容

enter image description here

enter image description here

我从一个页面找到了这个解决方案,但代码真的很难扩展。

我希望通过在颜色上使用地图并在警报对话框中将它们打印为 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){//你的代码}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...