How to use ReorderableListView.builder inside a StreamBuilder, with Objectbox?

84 views Asked by At

I have watched a tutorial on how to create a StreamBuilder for objectbox. In it, they used a ListView.builder. Im trying to make this list reorderable.

`class GameListByName extends StatefulWidget {
  const GameListByName({
    super.key,
  });
  @override
  State<GameListByName> createState() => _GameListByNameState();
}
`
`class _GameListByNameState extends State<GameListByName> {
  GameCard Function(BuildContext, int) _itemBuilder(List<Game> games) {
    return (BuildContext context, int index) => GameCard(game: games[index]);
  }

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<List<Game>>(
      key: UniqueKey(),
      stream: objectbox.getGamesByName(),
      builder: (context, snapshot) {
        if (snapshot.data?.isNotEmpty ?? false) {
          return ListView.builder(
            shrinkWrap: true,
            itemCount: snapshot.hasData ? snapshot.data!.length : 0,
            itemBuilder: _itemBuilder(snapshot.data ?? []),
          );
        } else {
          return const Center(
            child: Text('Press the + icon to add games'),
          );
        }
      },
    );
  }
}`

For this i have found the ReorderableListView class. Somehow i would have to swap the ListView.builder to the ReorderableListView.builder but it doesnt work. Not to mention that somehow i would have to change the order property in the objectbox after the reorder, so it is saved. Any help would be greatly appreciated. Thanks

0

There are 0 answers