flutter - Dart Flutter 抛出 FlutterError.fromParts(<DiagnosticsNode>[ 错误

标签 flutter dart

我正在尝试制作一个显示最近金融交易的应用程序。

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;

我永远无法理解这个问题。怎么解决呢?

最佳答案

您正在列内创建 Listview.builder,但未指定 ListView 的高度。

观看 flutter 团队解释这一点的视频。

https://www.youtube.com/watch?v=jckqXR5CrPI

简短的故事:您应该使用 SizedBox 为 Listview.build 指定高度。

关于flutter - Dart Flutter 抛出 FlutterError.fromParts(<DiagnosticsNode>[ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71165512/

相关文章:

flutter - 将输入字段和按钮放在屏幕中央

flutter - 视频播放器在 flutter 2.0 中崩溃(空安全)

macos - 请问如何在 flutter 桌面中使用谷歌地图?

dart - 奇怪的运行时类型异常

dart - 如何只渲染一个 Widget setState

flutter - 如何更改下拉列表中所选选项的颜色?

flutter - 如何在 DART 中获取两个字符串之间的子字符串?

android - flutter_bloc 中的 context.watch 和 context.read 有什么区别?

android - flutter DraggableScrollableSheet 与粘性标题

Flutter-如何在一行中的特定位置对齐按钮?