I am using this plugin flutter_swiper:
Swiper(
index: currentIndex,
itemCount: 12,
itemBuilder: (BuildContext context,int index){
return PhotoView(
imageProvider: AssetImage("images/c"+(index+1).toString()+".jpg"),
);
},
),
I need the swiper to not swipe from last index to first index and not from first to last only swipe between indexes.
what I have is a list of images to swipe between
Is it possible to do this using this plugin or I should use another one ?
if so please provide another solution
It seems to be that Swiper has a property for that, called loop:
/// Set to false to disable continuous loop mode.
final bool loop;
So you could try:
Swiper(
loop: false,
...
Related
[
Can I get a logic/code for highlighting just the selected value from this list view which is inside a container and it is scrollable also that the axis is set to Horizontal.
I have used a list view builder to align the same and also generated the list of numbers.
Please check the sample image of the widget attached.
Blockquote
]1
It's hard to tell you exactly how to do it without any code examples, and I'm also not sure what you mean by selected. Is that already decided before building the list, or is it decided when the user selects from the list?
If it is already decided, you can pass a value from the parent component that tells the list to highlight a certain value.
If a user is selecting the value to highlight, you can use a combination of setState and onTap with GestureDetector. Here's a potential rough skeleton:
int selectedIndex?;
ListView.builder(
itemCount: litems.length,
itemBuilder: (BuildContext ctx, int index) {
return GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Container(
backgroundColor: selectedIndex == index ? highlightedColor : undefined;
child: {{child content}}
),
);
}
)
I want to create a function that automatically moves to the next page when a certain condition is met using 'pageview'.
For example, if a=0 becomes a=1, it should automatically advance to the next page.
Instead of going to the next page by clicking a button in the pageview, is it possible to automatically go to the next page using a conditional statement?
Expanded(
child:
PageView.builder(
physics: NeverScrollableScrollPhysics(),
controller: _questionController.pageController,
onPageChanged: _questionController.updateTheQnNum,
itemCount: _questionController.questions.length,
itemBuilder: (context, index) => QuestionCard(
question: _questionController.questions[index],
myanswer: testtext,
),
)
),
This is part of my code. When a=1, it should advance to the next page, otherwise it should keep the current page.
There are two methods that can help you achieve it.
animateToPage
_questionController.pageController.animateToPage(pageIndex);
or
jumpToPage
_questionController.pageController.jumpToPage(pageIndex);
As the name suggests animateToPage will animate the transition from Page A to Page B where jumpToPage won't animate.
Make sure pageIndex is within the range.
When Swiper (flutter_swiper: ^1.1.6) has loop false and layout stack it has one more widget during swipe.
Did someone face the same problem?
What could be done with this?
I will appreciate any help you provide.
To reproduce my issue use the code below and add an itembuilder
Swiper(
loop: false,
layout: SwiperLayout.STACK)
I used the example from the package and added the two configuration properties you mentioned. The only error I received was requiring to set the itemWidth property required when setting the SwiperLayout.STACK layout value. After doing that, I have found no issues:
Swiper(
itemBuilder: (BuildContext context,int index){
return new Image.network("http://via.placeholder.com/350x150",fit: BoxFit.fill,);
},
itemWidth: 350,
itemCount: 3,
pagination: new SwiperPagination(),
control: new SwiperControl(),
loop: false,
layout: SwiperLayout.STACK
),
Your issue might be with your itemBuilder. You should share that part of the code.
I am making a grid like instagram where every seventh element is of 2X1. The problem is i want to show a different widget at seventh index but my code splits the gridTile widget rather than showing a different widget.
CODE:-
return StaggeredGridView.countBuilder(
shrinkWrap: true,
crossAxisCount: 3,
itemCount: gridTile.length,
itemBuilder: (context,index)=>gridTile[index],
staggeredTileBuilder: (index)=>StaggeredTile.count(
1,(index%7==0)?2:1,
),
);
Just Change your itemBuilder line of code as follow instead of "yourWidget" please write widget name you want to return.
itemBuilder : (context, index) {
return index % 7 == 0 ? yourWidget : gridTile[index];
},
I want to put google ads after specific number of items list or in between the items list in ListView.separated.
I have attached an image to make it clear how I want to do it:
Source of the image is: this article
First, I believe, you need to install a library to display Google AdMob ads. For instance - admob_flutter lib.
Then you only need to set up the separatorBuilder property of your ListView.separated widget.
e.g.
ListView.separated(
itemCount: 25,
separatorBuilder: (BuildContext context, int index) {
if (index % 5 == 0) { // Display `AdmobBanner` every 5 'separators'.
return AdmobBanner(
adUnitId: /* AdMob Unit ID */,
adSize: AdmobBannerSize.BANNER,
);
}
return Divider();
},
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('item $index'),
);
},
)
This code is only an example, you might encounter Infinite Height layout errors as I am not aware of how admob_flutter widgets operate.
However, this should be enough to get you started with your idea.
Let me know if this helped.