【发布时间】:2018-09-01 07:39:55
【问题描述】:
昨天问了一个非常相似的问题,关于在 AlertDialog 中显示 GridView 并得到了将 Widget 包装在容器中并添加宽度的完美答案。现在我决定 SimpleDialog 会更好,以提供更多功能/自定义,即搜索文本字段和多操作按钮。显示文本字段和图标按钮时,我得到了所需的结果,但是当我尝试添加 GridView 时,它会出错。我应用了以前的规则,但在 UI 消失但没有小部件显示的情况下,我遇到了类似的错误。我试过为不同的小部件添加宽度,但没有成功。这是我的代码...
Future<Null> _neverSatisfied() async {
return showDialog<Null>(
context: context,
barrierDismissible: false, // user must tap button!
child: new SimpleDialog(
contentPadding: const EdgeInsets.all(10.0),
title: new Text(
'CHOOSE YOUR GIF PROFILE IMAGE',
style: new TextStyle(fontWeight: FontWeight.bold, color: Colors.blue),
textAlign: TextAlign.center,
),
children: <Widget>[
new Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Padding(padding: new EdgeInsets.all(10.0)),
new Expanded(
child: new TextField(
decoration:
new InputDecoration(labelText: "SEARCH GIF'S"),
controller: _searchController,
onSubmitted: (str) {
setState(() {
str = _searchController.text;
});
})),
new Padding(padding: new EdgeInsets.all(2.0)),
new IconButton(
icon: new Icon(
Icons.search,
color: Colors.blue,
),
onPressed: () {
print('${_searchController.text}');
},
highlightColor: Colors.amber,
splashColor: Colors.amber,
iconSize: 25.0,
),
]),
new Padding(padding: new EdgeInsets.all(2.0)),
new Container(
// Specify some width
width: MediaQuery.of(context).size.width * .5,
child: new InkWell(
splashColor: Colors.blue,
onTap: null,
child: new GridView.count(
crossAxisCount: 4,
childAspectRatio: 1.0,
padding: const EdgeInsets.all(4.0),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
children: <String>[
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
'http://www.for-example.org/img/main/forexamplelogo.png',
].map((String url) {
return new GridTile(
child: new Image.network(url, fit: BoxFit.cover, width: 12.0, height: 12.0,));
}).toList()),
)
),
new Padding(padding: new EdgeInsets.all(2.0)),
new IconButton(
splashColor: Colors.green,
icon: new Icon(
Icons.cancel,
color: Colors.blue,
),
onPressed: () {
Navigator.of(context).pop();
})
],
),
],
),
);
}
这是我的错误日志...
══╡ 渲染库发现异常 ╞═════════════════════════════════════════════════ ════════ 在 performLayout() 期间引发了以下断言:RenderViewport 不支持返回固有尺寸。计算 内在维度将需要实例化 视口,它打败了视口懒惰的观点。如果你是 只是试图在主轴方向上收缩包裹视口, 考虑一个 RenderShrinkWrappingViewport 渲染对象 (ShrinkWrappingViewport 小部件),无需 实现内部维度 API。
【问题讨论】:
标签: user-interface gridview widget flutter simpledialog