I am working on my first flutter application and I have been facing a problem. I have a riverpod StreamProvider giving back a stream of objects that I return in a ConsumerWidget:
return currentEntries.when(
data: (entries) {
return ListView.separated(
itemCount: entries.length,
itemBuilder: (context, index) {
return MyListItem(item: entries[index]);
},
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
);
},
error: (error, stackTrace) => Center(child: Text(error.toString())),
loading: () => const Center(child: CircularProgressIndicator()),
);
Now I want to have other Widgets in my page than just the ListView. I have tried putting the ListView within a Columns just for test:
return Column(
children: const [
Text('Another widget comes here.'),
Expanded(child: MyListViewWidget()),
],
);
It works when I wrap MyListViewWidget
into an Expanded. As I side effect it scrolls beneath the text, what I don't want. The Text widget it just a placeholder.
If I remove Expanded, I then get an error.
How can I have the list view and other widgets within a parent widget? The list view is built based upon a riverpod StreamProvider. In fact I intend to put a horizontal ListView with fixed number of items above the vertical ListView generated based upon the StreamProvider.