![](/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.