Home > Net >  Dart Flutter throw FlutterError.fromParts(<DiagnosticsNode>[ error
Dart Flutter throw FlutterError.fromParts(<DiagnosticsNode>[ error

Time:02-19

I'm trying to make an application that shows recent financial transactions.

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);
}

I run the code and it throws me into a file called viewport.dart. It also redirects to this line:

      throw FlutterError.fromParts(<DiagnosticsNode>[

The entire code block in the file it redirects, on the line it redirects:

  @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;

I could never understand the problem. How can I solve it?

CodePudding user response:

You are creating a Listview.builder inside a column without specifying the height for the listview.

Check this video from flutter team explaining this.

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

short story: you should use a SizedBox to give Listview.build a height.

  • Related