简体   繁体   中英

Display more than a ListView in a flutter widget

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.

Exapned widgets helps or you can wrap your widgets with fixed size SizedBox the problem is all about the list has no limitation of size so when you wrap it with fixed sized widget you can use it whenever you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM