![](/img/trans.png)
[英]A RenderFlex overflowed by 299423 pixels on the bottom. problem seems to be made by the Column
[英]How to 'A RenderFlex overflowed by 61 pixels on the bottom.' on the top of the virtual Keyboard for android
这是用户界面。 下面是 main.dart 文件和错误信息 我在我的 Flutter 应用程序中使用文本字段,它在虚拟键盘的顶部给出了渲染 flex 错误。 请检查以下代码。 在底部,我添加了错误消息。 之前我尝试了所有其他方法来解决问题,但我没有
import 'package:flutter/material.dart';
import './transaction.dart';
import 'package:intl/intl.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Expenses Tracker',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
final List<Transaction> transactions = [
Transaction(
id: 't1',
title: 'New Shoes',
amount: 87.25,
date: DateTime.now(),
),
Transaction(
id: 't2',
title: 'Weekly Groceries',
amount: 83.25,
date: DateTime.now(),
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Expenses Tracker'),
),
body: Column(
children: <Widget>[
Container(
width: double.infinity,
child: Card(
child: Text("Chart!"),
color: Colors.deepOrange,
elevation: 9,
),
),
Card(
elevation: 5,
child: Container(
padding: EdgeInsets.all(10),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(labelText: 'Title'),
),
TextField(
decoration: InputDecoration(labelText: 'Amount'),
),
],
),
),
),
Column(
children: transactions.map((tx) {
return Card(
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(
vertical: 10,
horizontal: 15,
),
decoration: BoxDecoration(
border: Border.all(
color: Colors.purple,
width: 3,
),
),
padding: EdgeInsets.all(10),
child: Text(
'\$ ${tx.amount}',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.purple,
),
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
tx.title,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
Text(
DateFormat.yMMMEd().format(tx.date),
style: TextStyle(color: Colors.grey, fontSize: 14),
),
],
),
],
),
);
}).toList(),
),
],
),
);
}
}
下面是错误。
════════════════════════════════════════════════════════════════════════════════
══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during layout:
A RenderFlex overflowed by 61 pixels on the bottom.
The relevant error-causing widget was:
Column
lib\main.dart:41
The overflowing RenderFlex has an orientation of Axis.vertical.
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.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
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
ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
like a ListView.
The specific RenderFlex in question is: RenderFlex#0559b relayoutBoundary=up1 OVERFLOWING:
needs compositing
creator: Column ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
_InkFeatures-[GlobalKey#39d3c ink renderer] ← NotificationListener<LayoutChangedNotification> ←
PhysicalModel ← AnimatedPhysicalModel ← ⋯
parentData: offset=Offset(0.0, 80.0); id=_ScaffoldSlot.body (can use size)
constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=263.0)
size: Size(360.0, 263.0)
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
════════════════════════════════════════════════════════════════════════════════════════════════════
Scaffold
内的小部件来调整自己的大小,但是这样,某些小部件可能会
obscured
键盘obscured
我们可以使用Scaffold
小部件上的resizeToAvoidBottomInset
属性来做到这一点。
例子:
return Scaffold(
resizeToAvoidBottomInset: false, //new line
appBar: AppBar(
title: Text('Expenses Tracker'),
),
body: Column(
children: <Widget>[
...... // other widgets
],
),
);
Column
小部件包装到一个可滚动的小部件中。 Flutter
提供的一个运行良好的内置小部件是SingleChildScrollView
。 这是避免键盘打开时出现“Bottom overflowed”
错误的最佳解决方案。 return Scaffold(
appBar: AppBar(
title: Text('Expenses Tracker'),
),
body: SingleChildScrollView( // wrap with a scrollable widget
child: Column(
children: <Widget>[
...... // other widgets
],
),
),
);
尝试在您的Scaffold
设置resizeToAvoidBottomInset: false,
像这样。
Scaffold(
resizeToAvoidBottomInset: false,
...
)
您必须使用 SingleChildScrollView 。 这意味着可以滚动单个小部件的框。 所以首先去 colums ctrls+Shift+R 你可以获得 wrapwith 小部件并单击它并添加 SingleChildScrollView
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Expenses Tracker'),
),
body: SingleChildScrollView(child:Column(
children: <Widget>[
Container(
width: double.infinity,
child: Card(
child: Text("Chart!"),
color: Colors.deepOrange,
elevation: 9,
),
),).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.