大佬教程收集整理的这篇文章主要介绍了dart – 颤振垂直视口无界高度误差,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是Main.dart
import 'package:Flutter/material.dart'; import 'package:url_launcher/url_launcher.dart'; import 'dart:async' show Future; import 'package:Flutter/services.dart' show rootBundle; import 'dart:convert'; import 'package:emas_app/model/accounts_model.dart'; Future<String> _loadAsset() async{ return await rootBundle.loadString('Assets/accounts.json'); } Future<Accounts> loadAccounts() async{ final response = await _loadAsset(); final jsonResponse = json.decode(responsE); Accounts accounts = new Accounts.fromJson(jsonResponsE); return accounts; } class ProviderList extends StatefulWidget { @override ListState createState() { return new ListState(); } } class ListState extends State<ProviderList> { @override Widget build(BuildContext context) { Widget newbody = new ExpansionTile( title: new Text("State Name"),children: <Widget>[ new FutureBuilder<Accounts>( future: loadAccounts(),builder: (context,snapshot){ if(snapshot.hasData){ return new ListView.builder( itemCount: snapshot.data.accounTinfo.length,itemBuilder: (context,indeX){ String username = snapshot.data.accounTinfo[index].name; String address = snapshot.data.accounTinfo[index].street; String lat = snapshot.data.accounTinfo[index].coordinates.lat; String lng = snapshot.data.accounTinfo[index].coordinates.lng; return new ListTile( title: new Text(userName),@R_197_9829@ling: new Row( mainAxisSize: MainAxisSize.min,mainAxisAlignment: MainAxisAlignment.end,children: <Widget>[ new IconButton( icon: Icon(Icons.info),onPressed: null ),new IconButton( icon: Icon(Icons.directions),onPressed: null ) ],) ); }); }else{ return new Center( child: new CircularProgressInDicator(),); } }) ]); return new Scaffold( appBar: new AppBar(title: new Text("Providers")),body: newbody ); } }
这是显示扩展的ExpansionTile为空的输出:
这是错误抓住:
I/Flutter ( 6305): Vertical viewport was given unbounded height. I/Flutter ( 6305): Viewports expand in the scrolling direction to fill their container.In this case,a vertical I/Flutter ( 6305): viewport was given an unlimited amount of vertical space in which to expand. This situation I/Flutter ( 6305): typically happens when a scrollable widget is nested inside another scrollable widget.
我已经尝试了我可以在Stack Overflow中找到的所有可能的解决方案,通过使用Expanded或Flexible包装ListView.builder但它不起作用.关于如何解决这个问题的任何想法?
>使用ListView的shrinkWrap属性
new ListView.builder( shrinkWrap: true,itemCount: ...
原因:
在您的情况下,ListView位于ExpansionTile中. ExpansionTile将展示扩展并展示有多少孩子.当ListView放置在ExpansionTile(无界约束小部件)中时,ListView将扩展到scrollDirection中的最大大小.根据文档,
If the scroll view does not shrink wrap,then the scroll view will expand to the maximum allowed size in the [scrollDirection]. If the scroll view has unbounded cons@R_197_9829@nts in the [scrollDirection],then [shrinkWrap] must be true.
>使用SizedBox为ListView提供固定高度.
SizedBox(height: 200.0,child: new ListView.builder(...))
以上是大佬教程为你收集整理的dart – 颤振垂直视口无界高度误差全部内容,希望文章能够帮你解决dart – 颤振垂直视口无界高度误差所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。