Create a page view with 2 different scrollable list with different index - flutter

I want to create a screen that can display a scrollable list.
Based on a condition, I want to be able to display another list.
My program works however the index is the same for the 2 lists so when I scroll a list, the second list is scroll too
My code :
return PageView.builder(
scrollDirection: Axis.vertical,
itemCount: category[state.indexView].length,
itemBuilder: category[state.indexView][0].containsKey('video')
? (context2, index2) {
return Stack(
children: [
VideoWidget(
videoUrl: category[state.indexView][index2]['video'],
asset: true,
videoFile: File(''),
),
if (category[state.indexView][index2].containsKey('image'))
Center(child: Image(image: AssetImage(category[state.indexView][index2]['image']))),
_postContent(d_height)
],
);
}
: (context, index) {
return Stack(
children: [
if (category[state.indexView][index].containsKey('image'))
Center(child: Image(image: AssetImage(category[state.indexView][index]['image']))),
_postContent(d_height)
],
);
});

You can create second page in pageview similar to first page when you want to jump on second page then pass that index to another page and use it as current index in listview.

Related

Flutter ListView entries cut off when scrolled down

A screen in my app displays a list of "listings" the user has made. In the event there is not enough listings to fill the whole screen, and the user scrolls down, the listing they are scrolling will get cut off instead of being scrolled down.
example before scrolling
example after scrolling
As the user scrolls the list entry downwards I would like it not to disappear. I've tried wrapping the listview.builder in containers / sized boxes to define their size, although this behavior persists. I thought I could also put in some blank entries into the list that wouldn't respond to user clicks but that seems like an inefficient solution. Here is my code:
return Scaffold(
key: listing_home_scaffold_key,
resizeToAvoidBottomInset: false,
backgroundColor: BODY_BACKGROUND_COLOR,
appBar: returnAppBarForHomePages(context, "Listings", widget.local_user, updateUserState,
widget.local_user.usingDefaultImage, widget.local_user.getProfilePicURL, listing_home_scaffold_key),
drawer: settingsDrawer(widget.local_user),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
returnScrollableListView()
]),
);
Widget returnScrollableListView() {
return RefreshIndicator(
child: ListView.builder(
physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
itemCount: user_listings.length,
shrinkWrap: true,
padding: const EdgeInsets.only(top: 0),
itemBuilder: (context, index) {
return UserListing(listing: user_listings[index]);
}),
onRefresh: () async {
var cancel_loading_indicator = showLoadingIndicatorAllowClick();
await reQueryData();
cancel_loading_indicator();
},
);
}
Edit: Having the refresh indicator be the direct parent to the listview caused this problem. Moving it up a level so it's instead the parent of the Column fixed this.
Having the refresh indicator be the direct parent to the listview caused this problem. Moving it up a level so it's instead the parent of the Column fixed this.

ListView.builder inside SliverList SliverChildBuilderDelegate not rendering Images on first load

my images (from api) don't render at first load unless I scroll down and back to top again
here is my code structure
CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(_, index) {
return Column(children:
[
// SLIVERBUILDER INDEX
Text(somedata[_index]),
// MY IMAGE BUILDER
Container(child: ListView.builder(itemBuilder: (_, int index){
return Image.network(arrayOfImages[index]);
}))
]
);
}),
]
)
Try these:
Wrap a column with a container or any parent that could give its child constraints.
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return Container( // warp with container
height: 450,
child: Column(children: [
// SLIVERBUILDER INDEX
Text('title'),
Wrap ListView.builder with Expanded and add itemCount Property. (In your case 'arrayOfImage.length')
// MY IMAGE BUILDER
Expanded( // add this widget
child: ListView.builder(
itemCount: arrayOfImage.length, // add this line

Message box doesnt expand according to the message length

I am making a chat application where the message box should expand according to the message length. This works fine for only text but i am listing a series of small images also on the message box but on this case the message box doesn't expand.
This is the code:
Column(
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
width:100,
height:40,
child: ListView.builder(
//physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.horizontal,
//shrinkWrap: true,
itemCount: checkregexpression(argument['message'])
.length,
itemBuilder: (context, index) {
return checkregexpression(
argument['message'])[index] ==
'†'
? Image.asset('assets/emojis/' +
currentemoji[i++] +
'.png')
: Text(checkregexpression(
argument['message'])[index]
.toString());
},
),
),
],
)
I have used box constraint for this but listing a series of image displays the text and images on a horizontal scroll view rather than expanding accordingly. if possible an example of how to include box constraint onto a list view will also help.

Flutter: How does one generate Raisedbuttons from a list horizontally?

I'm having this issue where I have a list of options that I want to display within the same row. This piece of code generates the buttons I want, but each button takes up the entire row. This makes it so that the buttons are stacked vertically instead of horizontally. Help?
Container(child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Row(children: <Widget>[
Flexible(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: this.item.sizes.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return _sizeButton(index);
},
),
),
],
/* SOME OTHER WIDGETS */
],
),
);
Try to replace Row+Flexible with Expanded.
As mentioned, use scrollDirection: Axis.horizontal too.
https://dartpad.dartlang.org/ec28750de6310c2b4d397250aa9e22d1
The default behavior for a ListView is to put its items in a vertical list, whereby each item takes up one row. Use scrollDirection: Axis.horizontal, to put the items next to another horizontally.
Have you tried to add
scrollDirection = Axis.horizontal
in ListView.builder

How to show the listview in a listview

I got a problem when I am trying to show the listview in a listview. Right now it shows me the error "Vertical viewport was given unbounded height.". I try to add a container and set up the height to the second listview and it works. But I don't want to restrict the height of the second listview.
return new Scaffold(
body: new Column(
children: <Widget> [
new Expanded(
child: ListView(
children: <Widget> [
new Container(), // something else
new ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => new MenuCard(menuStore[index]),
itemCount: menuStore.length,
padding: new EdgeInsets.symmetric(vertical: 16.0)
)
]
)
)
]
)
);
You may want to set the ListView property shrinkWrap to true:
/// Whether the extent of the scroll view in the [scrollDirection] should be
/// determined by the contents being viewed.
///
/// If the scroll view does not shrink wrap, then the scroll view will expand
/// to the maximum allowed size in the [scrollDirection]. If the scroll view
/// has unbounded constraints in the [scrollDirection], then [shrinkWrap] must
/// be true.
...
/// Defaults to false.
final bool shrinkWrap;
In order to fix the Given Error in your code you need to shrinkWrap: true, in ListView.builder and ListView.
return new Scaffold(
body: new Column(
children: <Widget> [
new Expanded(
child: ListView(
shrinkWrap:ture,
children: <Widget> [
new Container(), // something else
new ListView.builder(
shrinkWrap:ture,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index) => new MenuCard(menuStore[index]),
itemCount: menuStore.length,
padding: new EdgeInsets.symmetric(vertical: 16.0)
)
]
)
)
]
)
);
Try out this answer here, Instead of GridView you can use ListView, also remove the crossAxisCount property from GridView.
https://stackoverflow.com/a/53852317/3811162