Reputation: 407
class TransactionWidget extends StatelessWidget {
final List<Transaction> _transaction;
TransactionWidget(this._transaction);
@override
Widget build(BuildContext context) {
return Container(
height: 500,
child: ListView.builder(
itemBuilder: (ctx, index) {
return Card(
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
child: Text(
'\$${_transaction[index].amount.toString()}',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.blue),
),
decoration: BoxDecoration(
border: Border.all(width: 2, color: Colors.lightBlue)),
padding: EdgeInsets.all(8),
), // amount ICON (Left)
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_transaction[index].title,
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 17),
), // Text Title
Text(
DateFormat('dd-MM-yyyy').format(_transaction[index].date),
style: TextStyle(fontSize: 13, color: Colors.grey),
), // Text Date
],
) // Text of Title and Date
],
));
},
itemCount: _transaction.length,
));
}
}
I am building a flutter app that shows a list of transactions entered by the user. The following code is to build and display multiple transactions, however whenever I open the keyboard to enter a new transaction the overflow error occurs. Above the transaction list I have added the 'Card' widget that takes the user input and adds a new transaction. The screenshot of the app
Upvotes: 0
Views: 544
Reputation: 1
Instead of setting a height for your listview container to 500, you can wrap your listview container with the Expanded widget, this will adjust the listview to changes in the screen size and orientation.
Upvotes: 0
Reputation: 2244
You are using a fixed size in your Container
, the 'height: 500
', so don't care if you are using a ListView
.
Try to remove if you can, because the ListView
will manage the size.
Upvotes: 0
Reputation: 730
Scaffold(
resizeToAvoidBottomInset: false,
...
)
This will avoid resizing when keyboard opens and thus avoid any overflows
Upvotes: 1