Overflow of DropdownButton widget in ListView
代码是:
class Datainput extends StatefulWidget { @overrIDe State createState() => new DatainputState(""); } enum dismissDialogAction { cancel,discard,save,} class DatainputState extends State<Datainput> { final String _data; static const types = const <Map<String,String>>[ const { "ID": "103","desc": "0001 - lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum" },const { "ID": "804","desc": "0002 - lorem ipsum lorem ipsum" },]; DatainputState(this._data); @overrIDe Widget build(BuildContext context) { final themeData theme = theme.of(context); return new Scaffold( appbar: new Appbar( Title: const Text("Details"),actions: <Widget>[ new Flatbutton( onpressed: () => Navigator.pop(context,dismissDialogAction.save),child: new Row( children: <Widget>[ new Icon(Icons.save,color: colors.white,),new Text( "Save",style: theme.texttheme.body1.copyWith( color: colors.white,) ) ],) ),],body: new ListVIEw( shrinkWrap: true,children: <Widget>[ new Text("Set Label"),new TextFIEld( autocorrect: false,new Text("Select Type"),new Container( wIDth: new FractionColumnWIDth(0.5).value,child: new Dropdownbutton( items: types.map((m) => new DropdownMenuItem( key: new Key(m["ID"]),child: new Text(m["desc"])) ).toList(growable: false),onChanged: null ),); } }
错误:
══╡ EXCEPTION CAUGHT BY RENDERING liBRARY ╞═════════════════════════════════════════════════════════ The following message was thrown during layout: A horizontal RenderFlex overflowed by 433 pixels. The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex. RenderFlex to fit within the available space instead of being sized to their natural size. This is consIDered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space,consIDer clipPing it with a RectClip Widget before putting it in the flex,or using a scrollable container rather than a Flex,for example using ListVIEw. The specific RenderFlex in question is: RenderFlex#cc264 relayoutBoundary=up12 OVERFLOWING creator: Row ← SizedBox ← DefaultTextStyle ← Stack ← Listener ← _GestureSemantics ← RawGestureDetector ← GestureDetector ← Dropdownbutton ← ConstrainedBox ← Container ← RepaintBoundary-[<3>] ← ⋯ direction: horizontal mainAxisAlignment: space-between mainAxisSize: min crossAxisAlignment: center textDirection: ltr verticalDirection: down
我尝试了以下方法,但它们不起作用:
>在行,列,填充和ClipRect中包含下拉列表
有人可以帮助我理解这一点,并说明如何解决它?
更新
使用FittedBox可以防止溢出,但文本大小会缩小到不可读.
如果您需要立即修复,您实际上可以自己修补DropDownbutton!为此:
>从Flutter Framework打开dropdown.dart,并将其作为fixed_dropdown.dart粘贴到您自己的项目中.
>从此文件中删除DropDownMenuItem类,以免与正常的Flutter导入冲突
>将DropDownbutton重命名为FixedDropDownbutton,因此它不会与Flutter导入冲突
>导航到_DropdownbuttonState的构建方法.找到一行内的IndexedStack.使用Expanded小部件包装IndexedStack.
我在Github问题本身上发布了这个信息,如果你想看到修复程序在行动中,也可以找到这个解决方案的截图!
总结以上是内存溢出为你收集整理的dart – Flutter – ListView中的DropdownButton溢出全部内容,希望文章能够帮你解决dart – Flutter – ListView中的DropdownButton溢出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)