Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to add rows dynamically from database(in PDF Web) #9

Closed
rockstarvibu opened this issue Oct 6, 2020 · 1 comment
Closed

I want to add rows dynamically from database(in PDF Web) #9

rockstarvibu opened this issue Oct 6, 2020 · 1 comment

Comments

@rockstarvibu
Copy link

rockstarvibu commented Oct 6, 2020

im using syncfusion_flutter_pdf: ^18.3.35-beta
plz help me to fix this... I want to add DataRows from my getBIlls.bill list. Help me to fix this...

my code

DataTable dataTable = DataTable(
                          columns: const <DataColumn>[
                            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>[
                              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())),
                            ]),
                          ));
                      DataTable invoiceDetails = dataTable;

getting error

Error: Expected a value of type 'List<DataRow>', but got one of type 'MappedListIterable<Bill, DataRow>'
    at Object.throw_ [as throw] (http://localhost:62775/dart_sdk.js:4328:11)
    at Object.castError (http://localhost:62775/dart_sdk.js:4299:15)
    at Object.cast [as as] (http://localhost:62775/dart_sdk.js:4615:17)
    at dart.LegacyType.new.as (http://localhost:62775/dart_sdk.js:6159:60)
    at GenerateBill.ShowBill.new.<anonymous> (http://localhost:62775/packages/lotto_pos/GenerateBill.dart.lib.js:3060:121)
    at Generator.next (<anonymous>)
    at runBody (http://localhost:62775/dart_sdk.js:37613:34)
    at Object._async [as async] (http://localhost:62775/dart_sdk.js:37644:7)
    at ink_well._InkResponseStateWidget.new.<anonymous> (http://localhost:62775/packages/lotto_pos/GenerateBill.dart.lib.js:3032:7173)
    at ink_well._InkResponseState.new.[_handleTap] (http://localhost:62775/packages/flutter/src/material/icon_button.dart.lib.js:47433:21)
    at http://localhost:62775/packages/flutter/src/material/icon_button.dart.lib.js:47535:668
    at tap.TapGestureRecognizer.new.invokeCallback (http://localhost:62775/packages/flutter/src/gestures/recognizer.dart.lib.js:189:18)
    at tap.TapGestureRecognizer.new.handleTapUp (http://localhost:62775/packages/flutter/src/gestures/tap.dart.lib.js:395:40)
    at tap.TapGestureRecognizer.new.[_checkUp] (http://localhost:62775/packages/flutter/src/gestures/tap.dart.lib.js:201:12)
    at tap.TapGestureRecognizer.new.handlePrimaryPointer (http://localhost:62775/packages/flutter/src/gestures/tap.dart.lib.js:148:23)
    at tap.TapGestureRecognizer.new.handleEvent (http://localhost:62775/packages/flutter/src/gestures/recognizer.dart.lib.js:448:16)
    at pointer_router.PointerRouter.new.[_dispatch] (http://localhost:62775/packages/flutter/src/gestures/pointer_router.dart.lib.js:74:9)
    at http://localhost:62775/packages/flutter/src/gestures/pointer_router.dart.lib.js:109:26
    at LinkedMap.new.forEach (http://localhost:62775/dart_sdk.js:24743:11)
    at pointer_router.PointerRouter.new.[_dispatchEventToRoutes] (http://localhost:62775/packages/flutter/src/gestures/pointer_router.dart.lib.js:106:29)
    at pointer_router.PointerRouter.new.route (http://localhost:62775/packages/flutter/src/gestures/pointer_router.dart.lib.js:98:37)
    at binding$5.WidgetsFlutterBinding.new.handleEvent (http://localhost:62775/packages/flutter/src/gestures/binding.dart.lib.js:303:26)
    at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:62775/packages/flutter/src/gestures/binding.dart.lib.js:286:24)
    at binding$5.WidgetsFlutterBinding.new.dispatchEvent (http://localhost:62775/packages/flutter/src/rendering/layer.dart.lib.js:5949:13)
    at binding$5.WidgetsFlutterBinding.new.[_handlePointerEvent] (http://localhost:62775/packages/flutter/src/gestures/binding.dart.lib.js:257:14)
    at binding$5.WidgetsFlutterBinding.new.[_flushPointerEventQueue] (http://localhost:62775/packages/flutter/src/gestures/binding.dart.lib.js:229:35)
    at binding$5.WidgetsFlutterBinding.new.[_handlePointerDataPacket] (http://localhost:62775/packages/flutter/src/gestures/binding.dart.lib.js:213:65)
    at Object._invoke1 (http://localhost:62775/dart_sdk.js:175453:7)
    at _engine.EngineWindow.new.invokeOnPointerDataPacket (http://localhost:62775/dart_sdk.js:171307:15)
    at _engine.PointerBinding.__.[_onPointerData] (http://localhost:62775/dart_sdk.js:158211:24)
    at http://localhost:62775/dart_sdk.js:158598:26
    at http://localhost:62775/dart_sdk.js:158557:16
    at http://localhost:62775/dart_sdk.js:158310:11
@rockstarvibu rockstarvibu changed the title I want to add rows dynamically from database(in Web) I want to add rows dynamically from database(in PDF Web) Oct 6, 2020
@Anand3595
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants