我收到此错误 A renderFlex 在底部溢出 100 像素
Posted
技术标签:
【中文标题】我收到此错误 A renderFlex 在底部溢出 100 像素【英文标题】:I got this error A renderFlex overFlowed by 100 pixels on the bottom 【发布时间】:2020-08-18 08:21:57 【问题描述】:如下所示,我尝试添加一个 TextFormFiled,添加后出现错误 A renderFlex overFlowed :
Widget build(BuildContext context)
return Column(
children: <Widget>[
Text('Rate the order !', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(starCount, (index)=>buildStar(context, index)),
),
Padding(
padding: EdgeInsets.all(10),
child: Form(child:TextFormField(
decoration: (InputDecoration(
labelText: 'add your notes'
)),
textInputAction: TextInputAction.done,
)),
)
],
);
【问题讨论】:
【参考方案1】:将列包装在 SingleChildScrollView 中。
DartPad 上的工作示例: https://dartpad.dev/b6409e10de32b280b8938aa75364fa7b
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
class MyHomePage extends StatefulWidget
MyHomePage(Key key, this.title) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
class _MyHomePageState extends State<MyHomePage>
Widget build(BuildContext context)
return Material(child:
SingleChildScrollView(child:
Column(
children: <Widget>[
Text('Rate the order !', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(10, (index)=>Icon(Icons.star)),
),
SizedBox(height: 10,),
Column(
mainAxisAlignment: MainAxisAlignment.center,
// add many children just to overflow on the bottom
children: List.generate(100, (index)=>Icon(Icons.video_call)),
),
Padding(
padding: EdgeInsets.all(10),
child: Form(child:TextFormField(
decoration: (InputDecoration(
labelText: 'add your notes'
)),
textInputAction: TextInputAction.done,
)),
)
],
),),);
【讨论】:
【参考方案2】:给列或行内的列表一个固定的高度。使用 Container 或任何其他小部件
【讨论】:
【参考方案3】:效果很好,看看吧。见以下代码:
import 'package:flutter/material.dart';
Widget build(BuildContext context)
return Column(
children: <Widget>[
Text('Rate the order !', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),),
SizedBox(height: 10,),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List.generate(starCount, (index)=>buildStar(context, index)),
),
),
Padding(
padding: EdgeInsets.all(10),
child: Form(child:TextFormField(
decoration: (InputDecoration(
labelText: 'add your notes'
)),
textInputAction: TextInputAction.done,
)),
)
],
);
希望对你有帮助。
【讨论】:
【参考方案4】:把Column
作为SingleChildScrollView
的child
【讨论】:
我做到了,它没有显示错误,但视图本身消失了 您是否设置了列mainAxisSize: MainAxisSize.min
?以上是关于我收到此错误 A renderFlex 在底部溢出 100 像素的主要内容,如果未能解决你的问题,请参考以下文章
一个 RenderFlex 在底部溢出了 729 个像素。在 SingleChildScrollView
又抛出了一个异常:A RenderFlex 右边溢出了 3.0 像素
I/flutter (17109):抛出另一个异常:A RenderFlex 溢出右侧 80 像素