gpt4 book ai didi

带有图标和文字的 Flutter 按钮看起来很奇怪

转载 作者:IT王子 更新时间:2023-10-29 06:47:45 25 4
gpt4 key购买 nike

我正在尝试创建一个 Flutter 应用程序,它有一个带有文本和图标作为标签的按钮,该图标位于文本的右侧。 this post 中描述的方法产生一个看起来很奇怪的按钮,它似乎扩展到应用程序的宽度,请看这张图片(链接,因为我不允许附加图片):

Button becomes wide when adding a Row widget as child

我不清楚使用哪些布局小部件来调整文本+图像按钮以将其格式化为纯文本按钮。

产生上述例子的代码:

Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
'You have pushed the button this many times:',
),
new Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
new RaisedButton(
onPressed: _incrementCounter,
child: new Row(
children: <Widget>[
new Text("Button with text and icon!"),
new Icon(Icons.lightbulb_outline)
],
),
),
new RaisedButton(
onPressed: _incrementCounter,
child: new Text("Button with only text")
),
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: new Icon(Icons.add),
),
);
}
}

最佳答案

行属性 mainAxisSize: MainAxisSize.min 在这里发挥作用。

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Home'),
),
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new RaisedButton(
onPressed: () {},
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Text('Button with text and icon!'),
new Icon(Icons.lightbulb_outline),
],
),
),
new RaisedButton(
onPressed: () {},
child: new Text('Button with only text'),
)
],
),
),
);
}

关于带有图标和文字的 Flutter 按钮看起来很奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50636414/

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