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 左对齐图标按钮展开_Flutter_Flutter Layout - Fatal编程技术网

Flutter 左对齐图标按钮展开

Flutter 左对齐图标按钮展开,flutter,flutter-layout,Flutter,Flutter Layout,我有一个按钮在颤振中展开的问题,我需要对齐按钮左侧的图标,我用widget行创建它,因为这是我找到的最好的方法。但是,文本没有正确居中 SizedBox( width: double.infinity, child: RaisedButton( onPressed: () => {}, color: Colors.blue, textColor: Colors.white, child: Row( children: <

我有一个按钮在颤振中展开的问题,我需要对齐按钮左侧的图标,我用widget行创建它,因为这是我找到的最好的方法。但是,文本没有正确居中

   SizedBox(
    width: double.infinity,
    child: RaisedButton(
    onPressed: () => {},
    color: Colors.blue,
    textColor: Colors.white,
    child: Row(
     children: <Widget>[
      Icon(Icons.send),
      Expanded(
       child: Text('Enviar', textAlign: TextAlign.center)
      )
     ],
    )
   ),
  ),
SizedBox(
宽度:double.infinity,
孩子:升起按钮(
按下:()=>{},
颜色:颜色,蓝色,
textColor:Colors.white,
孩子:排(
儿童:[
图标(Icons.send),
扩大(
子项:Text('Enviar',textAlign:textAlign.center)
)
],
)
),
),
结果是


有没有更好的方法来制作具有这种样式的按钮(文本在所有按钮中居中,而不仅仅是在其空间中)

您可以尝试两种常见的方法,我没有实施它们,但我只是给您提供了核心想法:

  • 使用,将
    图标设置为
    前导属性,将对齐的
    文本设置为
    标题属性。这种方法看起来可能更干净、更容易,但我怀疑您可能在对齐的
    文本方面也有同样的问题
  • 使用并用
    对齐
    小部件包装
    图标
    ,设置其
    对齐
    属性以满足您的需要。然后,用
    Text
    Center
    小部件替换展开的
    ,这样您就不需要
    textAlign:textAlign.Center
    属性。我想这对你来说可能更好

您可以尝试两种常见的方法,我没有实施它们,但我只是给您提供了核心想法:

  • 使用,将
    图标设置为
    前导属性,将对齐的
    文本设置为
    标题属性。这种方法看起来可能更干净、更容易,但我怀疑您可能在对齐的
    文本方面也有同样的问题
  • 使用并用
    对齐
    小部件包装
    图标
    ,设置其
    对齐
    属性以满足您的需要。然后,用
    Text
    Center
    小部件替换展开的
    ,这样您就不需要
    textAlign:textAlign.Center
    属性。我想这对你来说可能更好

    • 问题在于行中的两个元素。这个代码应该适合你

      SizedBox(
              width: double.infinity,
              child: RaisedButton(
                  onPressed: () => {},
                  color: Colors.blue,
                  textColor: Colors.white,
                  child: Stack(
                    alignment: Alignment.centerLeft,
                    children: <Widget>[
                      Icon(Icons.send),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text('Enviar'),
                        ],
                      ),
                    ],
                  )
              ),
            ),
      
      SizedBox(
      宽度:double.infinity,
      孩子:升起按钮(
      按下:()=>{},
      颜色:颜色,蓝色,
      textColor:Colors.white,
      子:堆栈(
      对齐:alignment.centerLeft,
      儿童:[
      图标(Icons.send),
      划船(
      mainAxisAlignment:mainAxisAlignment.center,
      儿童:[
      文本(“Enviar”),
      ],
      ),
      ],
      )
      ),
      ),
      
      问题在于行中的两个元素。这个代码应该适合你

      SizedBox(
              width: double.infinity,
              child: RaisedButton(
                  onPressed: () => {},
                  color: Colors.blue,
                  textColor: Colors.white,
                  child: Stack(
                    alignment: Alignment.centerLeft,
                    children: <Widget>[
                      Icon(Icons.send),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text('Enviar'),
                        ],
                      ),
                    ],
                  )
              ),
            ),
      
      SizedBox(
      宽度:double.infinity,
      孩子:升起按钮(
      按下:()=>{},
      颜色:颜色,蓝色,
      textColor:Colors.white,
      子:堆栈(
      对齐:alignment.centerLeft,
      儿童:[
      图标(Icons.send),
      划船(
      mainAxisAlignment:mainAxisAlignment.center,
      儿童:[
      文本(“Enviar”),
      ],
      ),
      ],
      )
      ),
      ),
      
      List tile效果不太好,我将尝试使用Stack,谢谢。List tile效果不太好,我将尝试使用Stack,谢谢。