Code Monkey home page Code Monkey logo

Comments (1)

Anand3595 avatar Anand3595 commented on June 25, 2024

Hi rockstarvibu,

The DataTable allows only the type of List as a rows collection, but the provided code returns the MappedListIterable<Bill, DataRow>, due to this the exception occurs. So we have converted the map collection to list to overcome this issue.

Try the following solution in your side and let us know the details.

Solution 1: Convert the inerrable to list by using map().toList() method

//Create data table by using dynamic data from web.
DataTable dataTable = DataTable(
columns: const [
DataColumn(label: Text('Series From')),
DataColumn(label: Text('Series To')),
DataColumn(label: Text('No From')),
DataColumn(label: Text('No To')),
DataColumn(label: Text('QTY')),
DataColumn(label: Text('Price')),
],
rows: getBill.bill.map(
(value) => DataRow(cells: [
DataCell(Text(value.series_from.toString())),
DataCell(Text(value.series_to.toString())),
DataCell(Text(value.no_from.toString())),
DataCell(Text(value.no_to.toString())),
DataCell(Text(value.qty.toString())),
DataCell(Text(value.mrp.toString()))])).toList());
Note: MappedListIterable<K, V>.toList() used to get the List

Solution 2: Create List by iterating the bill entries by using forEach() function.

//Iterating bill object and adding the DataRow into List.
List rowCollection = [];
getBill.bill.forEach((value) => rowCollection.add(DataRow(cells: [
DataCell(Text(value.series_from.toString())),
DataCell(Text(value.series_to.toString())),
DataCell(Text(value.no_from.toString())),
DataCell(Text(value.no_to.toString())),
DataCell(Text(value.qty.toString())),
DataCell(Text(value.mrp.toString()))])));
//Create data table by using the list created.
DataTable dataTable = DataTable(
columns: const [
DataColumn(label: Text('Series From')),
DataColumn(label: Text('Series To')),
DataColumn(label: Text('No From')),
DataColumn(label: Text('No To')),
DataColumn(label: Text('QTY')),
DataColumn(label: Text('Price')),
], rows: rowCollection);
DataTable invoiceDetails = dataTable;

With Regards,
Anand Panchamoorthi

from flutter-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.