Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何使用flatter在snackbar中放置图标_Flutter - Fatal编程技术网

Flutter 如何使用flatter在snackbar中放置图标

Flutter 如何使用flatter在snackbar中放置图标,flutter,Flutter,我是个新手,我不知道是否可以这样做。我想在文本的左侧放置一个图标 SnackBar( backgroundColor: Colors.red, content: Text(_accion_toast + ". " + mensaje), duration: Duration(milliseconds: 1500), ); 您可以将SnackBar的内容参数更改为首先包含图标,然后包含文本的行。例如: SnackBar( backgroundColor: Colo

我是个新手,我不知道是否可以这样做。我想在文本的左侧放置一个图标

SnackBar(    
  backgroundColor: Colors.red,
  content: Text(_accion_toast + ". " + mensaje),
  duration: Duration(milliseconds: 1500),
);

您可以将SnackBar的内容参数更改为首先包含图标,然后包含文本的行。例如:

SnackBar(    
  backgroundColor: Colors.red,
  content: Row(
    children: <Widget>[
      //Icon widget of your choice HERE,
      Text(_accion_toast + ". " + mensaje)
    ]
  ),
  duration: Duration(milliseconds: 1500),
);
Snackbar的content属性接受一个小部件

在您的情况下,您可以传递Row小部件,因为您希望将项目与图标和文本并排放置

检查下面的代码,它工作正常:

   SnackBar(
      // background color of your snack-bar
      backgroundColor: Colors.red,
      // make the content property take a Row
      content: Row(
        children: <Widget>[
          // add your preferred icon here
          Icon(
            Icons.close,
            color: Colors.white,
          ),
          // add your preferred text content here
          Text(_accion_toast + ". " + mensaje),
        ],
      ),
      // the duration of your snack-bar
      duration: Duration(milliseconds: 1500),
    );
  }