我正在嘗試制作一個顯示最近金融交易的應用程式。
main.dart:
import 'package:flutter/material.dart';
import 'package:flutterapppproject/recentTransactions.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: recentTransactions(),
),
),
);
}
recentTransctions.dart:
import 'package:flutter/material.dart';
class recentTransactionsApp extends StatelessWidget {
const recentTransactionsApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
List <recentTransactionsClass> transactions = [recentTransactionsClass("10 March", "Money send", "500 USD", "None"), recentTransactionsClass("11 March", "Money send", "50 USD", "None")];
return Scaffold(
appBar: AppBar(
title: Text("Recent transactions"),
backgroundColor: Colors.red[500],
),
body: Center(
child: Column(
children: [
Text("\nRecent transactions", style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),),
Text("Welcome to recent transactions app.", style: TextStyle(fontSize: 20), textAlign: TextAlign.center,),
ListView.builder(
itemCount: islemler.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: ListTile(
leading: Icon(Icons.account_balance_wallet),
title: Text(transactions[index].transactionDate),
subtitle: Text(transactions[index].transactionType),
trailing: Text(transactions[index].transactionAmount),
),
);
},
),
],
),
),
);
}
}
class recentTransactionsClass {
String transactionDate;
String transactionType;
String transactionAmount;
String transactionDescription;
sonIslemler(this.transactionDate, this.transactionType, this.transactionAmount, this.transactionDescription);
}
我運行代碼,它把我扔到一個名為 viewport.dart 的檔案中。它還重定向到這一行:
throw FlutterError.fromParts(<DiagnosticsNode>[
它重定向的檔案中的整個代碼塊,在它重定向的行上:
@override
Size computeDryLayout(BoxConstraints constraints) {
assert(() {
if (!constraints.hasBoundedHeight || !constraints.hasBoundedWidth) {
switch (axis) {
case Axis.vertical:
if (!constraints.hasBoundedHeight) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Vertical viewport was given unbounded height.'),
ErrorDescription(
'Viewports expand in the scrolling direction to fill their container. '
'In this case, a vertical viewport was given an unlimited amount of '
'vertical space in which to expand. This situation typically happens '
'when a scrollable widget is nested inside another scrollable widget.',
),
ErrorHint(
'If this widget is always nested in a scrollable widget there '
'is no need to use a viewport because there will always be enough '
'vertical space for the children. In this case, consider using a '
'Column instead. Otherwise, consider using the "shrinkWrap" property '
'(or a ShrinkWrappingViewport) to size the height of the viewport '
'to the sum of the heights of its children.',
),
]);
}
if (!constraints.hasBoundedWidth) {
throw FlutterError(
'Vertical viewport was given unbounded width.\n'
'Viewports expand in the cross axis to fill their container and '
'constrain their children to match their extent in the cross axis. '
'In this case, a vertical viewport was given an unlimited amount of '
'horizontal space in which to expand.',
);
}
break;
case Axis.horizontal:
if (!constraints.hasBoundedWidth) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Horizontal viewport was given unbounded width.'),
ErrorDescription(
'Viewports expand in the scrolling direction to fill their container. '
'In this case, a horizontal viewport was given an unlimited amount of '
'horizontal space in which to expand. This situation typically happens '
'when a scrollable widget is nested inside another scrollable widget.',
),
ErrorHint(
'If this widget is always nested in a scrollable widget there '
'is no need to use a viewport because there will always be enough '
'horizontal space for the children. In this case, consider using a '
'Row instead. Otherwise, consider using the "shrinkWrap" property '
'(or a ShrinkWrappingViewport) to size the width of the viewport '
'to the sum of the widths of its children.',
),
]);
}
if (!constraints.hasBoundedHeight) {
throw FlutterError(
'Horizontal viewport was given unbounded height.\n'
'Viewports expand in the cross axis to fill their container and '
'constrain their children to match their extent in the cross axis. '
'In this case, a horizontal viewport was given an unlimited amount of '
'vertical space in which to expand.',
);
}
break;
}
}
return true;
}());
return constraints.biggest;
}
static const int _maxLayoutCycles = 10;
// Out-of-band data computed during layout.
late double _minScrollExtent;
late double _maxScrollExtent;
bool _hasVisualOverflow = false;
我永遠無法理解這個問題。我該如何解決?
uj5u.com熱心網友回復:
您正在列內創建 Listview.builder 而不指定串列視圖的高度。
查看來自顫振團隊的視頻來解釋這一點。
https://www.youtube.com/watch?v=jckqXR5CrPI
短篇小說:您應該使用 SizedBox 給 Listview.build 一個高度。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/427701.html
