'Is There a way to scroll to a specific cell on a Table?

I am using a Table to represent my CSV data, but I have not found any way to scroll programmatically to the searched cell.

  • If the cell text content is 123, I would like to be able to scroll to the cell programmatically.
  • I can not use a Listview or Listview.builder because I want to display the data on a Table.
  • I have seen many examples on the internet but they all use the Listview because its contents have a fixed width and height, but I wonder if it's possible to scroll on Tables.

this is a code example I am using:

It loads the csv data into the Table and while it fills its content it checks if the content is in a list I provide and will change its cell formatting.

class InventoryMap extends StatelessWidget {
  final Map singleOrMulti;
  const InventoryMap({Key key, this.singleOrMulti}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final bool _isMapLoaded =
        context.watch<InventoryMapDataProvider>().getIsMapLoaded;

    final List<List<dynamic>> _csvMapList =
        context.watch<InventoryMapDataProvider>().getCsvMapList;

    List itemsToLook = [];

    bool isSingleItem = false;

    List<CartItem> currentItemList = [];

    if (singleOrMulti['single'] != null) {
      itemsToLook.add(singleOrMulti['single']);
      isSingleItem = true;
    } else if (singleOrMulti['multi'] != null) {
      isSingleItem = false;

      UploadedInvoice invoice = singleOrMulti['multi'];

      invoice.invoice.forEach((e) {
        final item = CartItem.fromJson(e);
        currentItemList.add(item);
        itemsToLook.add(item.code);
      });
    }

    switch (_isMapLoaded) {
      case true:
        return SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Table(
                defaultColumnWidth: FixedColumnWidth(80.0),
                border: TableBorder.all(width: 1.0, color: Colors.black12),
                children: _csvMapList.map((item) {
                  return TableRow(
                      children: item.map((row) {
                    final itemCode = row.toString();
                    final hasCode = itemsToLook.contains(itemCode);
                    String itemCodeDisplay = itemCode;

                    if (hasCode && !isSingleItem) {
                      final itemQty = currentItemList
                          .singleWhere((e) => e.code == itemCode)
                          .qty;
                      itemCodeDisplay = "$itemCode ($itemQty)";
                    }
                    return Container(
                      color: hasCode ? Colors.red : null,
                      child: Text(
                        itemCodeDisplay,
                        style: TextStyle(
                            fontSize: 8.0,
                            color: hasCode ? Colors.white : null),
                      ),
                    );
                  }).toList());
                }).toList(),
              ),
            ),
          ),
        );
      case false:
        return CircularProgressIndicator();
        break;
      default:
        return Container();
    }
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source