rickypid / flutter_expandable_table

A Flutter widget for create an expandable table with header and first column fixed.
https://pub.dev/packages/flutter_expandable_table
BSD 3-Clause "New" or "Revised" License
40 stars 28 forks source link

The flutter_expandable_table 2.0.0-beta.1 won't refresh the view/state #15

Closed vardinava closed 1 year ago

vardinava commented 1 year ago

Sorry but doing setState() on the data I used to be displayed in the table didn't make the table refresh. However, the data do refresh with new values when I download them to excel file.

How to refresh the view of this table? I'm still new to Flutter so I hope you don't mind answering. This package has been a huge help, but I'm troubled on how to refresh the table with new values.

Best regards, Vardina

rickypid commented 1 year ago

Hi @vardinava,

Try upgrading to version 2.0.0-beta.2 and using this example which uses the controller to dynamically manage the data within the table.

    //... Inside Widget State
    late ExpandableTableController controller;
    //....
    @override
    void initState() {
      controller = ExpandableTableController(
        firstHeaderCell: ExpandableTableCell(child: Container()),
        headers: [],
        rows: [],
        headerHeight: 263,
        defaultsColumnWidth: 200,
        firstColumnWidth: 300,
        scrollShadowColor: AppColors.black,
      );
      super.initState();
    }
    void _onEvent(){    
      controller.rows.add(...your code...);
    }
    @override
    Widget build(BuildContext context) {
      return ExpandableTable(
        controller: controller,
      );
    }
//....

let me know if it solves your problem.

vardinava commented 1 year ago

Hello @rickypid ! Thank you for your reply, I've upgraded the package and implemented the controller. The table appeared nicely, no issue in headers and rows, and I called _onEvent via button. Sadly the table is still empty when I pressed the button. However, the print function I put inside _onEvent got called succesfully.

void _onEvent(picaKota, picaDealer){ //controller.rows.addAll(_generateRows(picaKota.length, picaKota, picaDealer)); controller.rows.add(ExpandableTableRow( firstCell: _buildFirstRowCell("data"), //sub row cells: List.generate(12, (colIndex) => _buildCell("data $colIndex", rowStyle)), ) ); }

I tried inputting list of rows or just 1 row and with dummy data but it still won't appear inside the table. The actual data I used is retrieved via future builder so I tried dummy data as well. I'm sorry if there's any mistakes in my side though.

vardinava commented 1 year ago

Oh, I tried "=" instead of add and addAll and it worked like a charm. Thank you for your help!

controller.rows = _generateRows(picaKota.length, picaKota, picaDealer);