Skip to content

Getting Null check operator used on a null value when trying to run from initState() ? #291

Open
@ElixirMike

Description

@ElixirMike

In my scenario, When the widget loads, I want it to automatically jump/scroll to a specific selected index in the list.
If I do this with a button trigger, it correctly scrolls to the spot in the list.

However, when I try to to do this from initState, It throws the error "Null check operator used on a null value".

final ItemScrollController itemScrollController = ItemScrollController();
final ItemPositionsListener itemPositionsListener =  ItemPositionsListener.create();

initState

    @override
    initState(){
    itemScrollController.jumpTo(index: 5);
    super.initState();
    }

In my widget tree?

ScrollablePositionedList.builder(
                itemCount: widget.tables.length,
                itemBuilder: (context, index) => ListTile(
                    leading: GBIcon(
                        hexColor: widget.tables[index].tableId == widget.currentTable.tableId
                            ? '#FFFFFF'
                            : widget.block.color,
                        icon: widget.tables[index].icon,
                        size: 24),
                    title: Text(widget.tables[index].name),
                    selected: widget.tables[index].tableId == widget.currentTable.tableId,
                    selectedTileColor: hexStringToColor(widget.block.color),
                    onTap: () async {
                      widget.loadTable(widget.tables[index].tableId.toString());
                    },
                  ),
                itemScrollController: itemScrollController,
                itemPositionsListener: itemPositionsListener,
              ) 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions