Flutter &引用;右侧的RenderFlex溢出了97个像素。”;在“颤振警报”对话框中
我对AlertDialog的操作有此问题Flutter &引用;右侧的RenderFlex溢出了97个像素。”;在“颤振警报”对话框中,flutter,flutter-layout,Flutter,Flutter Layout,我对AlertDialog的操作有此问题 AlertDialog( title: ..., content: ..., actions: <Widget>[ FlatButton(onPressed: ..., child: Text(btn_download)), FlatButton(onPressed: ..., child: Text
AlertDialog(
title: ...,
content: ...,
actions: <Widget>[
FlatButton(onPressed: ...,
child: Text(btn_download)),
FlatButton(onPressed: ...,
child: Text('btn_select')),
FlatButton(onPressed: ...,
child: Text(btn_qr)),
FlatButton(onPressed: ...,
child: Text(btn_cancel)),
],
);
警报对话框(
标题:。。。,
内容:。。。,
行动:[
扁平按钮(按下时:。。。,
子:文本(btn_下载)),
扁平按钮(按下时:。。。,
子项:文本('btn_select'),
扁平按钮(按下时:。。。,
子:文本(btn_qr)),
扁平按钮(按下时:。。。,
子项:文本(btn_取消)),
],
);
当我显示此对话框时,我得到以下信息:
我尝试使用Wrap或其他滚动和多子widets,但没有任何帮助。
发现了同样的问题,但还没有答案
有人知道如何解决这个问题吗?我无法访问AndroidStudio来验证我的假设,但我会尝试以下方法:
AlertDialog(
title: ...,
content: ...,
actions: <Widget>[
new Container (
child: new Column (
children: <Widget>[
FlatButton(onPressed: ...,
child: Text(btn_download)),
FlatButton(onPressed: ...,
child: Text('btn_select'))
),
new Container (
child: new Column (
children: <Widget>[
FlatButton(onPressed: ...,
child: Text(btn_gr)),
FlatButton(onPressed: ...,
child: Text('btn_cancel'))
),
),
],
);
按钮栏
不是为这么多按钮而设计的
将按钮放置在
包装
小部件或列中
即使没有容器也可以工作,但这不是我的最佳解决方案-将按钮张贴到列中,尤其是在横向上。我想做一些像Wrap这样的东西,但在我的答案上它不起作用,添加了一个完整示例的代码。谢谢,它可以成为解决方案。但我使用了ConstrainedBox而不是容器,并且在WidgetBuilder中计算了宽度,所以它会随着不同的方向而变化。我写过——我尝试过包装——它没有帮助。立柱可以工作,但它不是景观中的最佳解决方案
import 'package:flutter/material.dart';
import 'dart:async';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
Future<Null> _neverSatisfied() async {
double c_width = MediaQuery.of(context).size.width*0.75;
return showDialog<Null>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return new AlertDialog(
title: new Text('Rewind and remember'),
content: new SingleChildScrollView(
child: new ListBody(
children: <Widget>[
new Text('You will never be satisfied.'),
new Text('You\’re like me. I’m never satisfied.'),
],
),
),
actions: <Widget>[
new Container(
width: c_width,
child: new Wrap(
spacing: 4.0,
runSpacing: 4.0,
children: <Widget>[
new FlatButton(
child: new Text('The Lamb'),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('Lies Down'),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('On'),
onPressed: () {
Navigator.of(context).pop();
},
),
new FlatButton(
child: new Text('Broadway'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
)
)
],
);
},
);
}
void _doNeverSatisfied() {
_neverSatisfied()
.then( (Null) {
print("Satisfied, at last. ");
});
}
@override
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,
),
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: _doNeverSatisfied,
tooltip: 'Call dialog',
child: new Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}