CarouselSlider(
options: CarouselOptions(
autoPlay: false,
enableInfiniteScroll: false,
height: MediaQuery.of(context).size.height,
enlargeCenterPage: false,
viewportFraction: 1,
initialPage: 0,
scrollDirection: Axis.vertical,
pageSnapping: false,
onPageChanged: (index, reason) {
setState(() {
_currentSlider = index;
});
}),
items: images.map((e) {
return Builder(
builder: (BuildContext context) {
return Center(
child: SingleChildScrollView(
child: Image.memory(
e,
fit: BoxFit.fitWidth,
),
),
);
},
);
}).toList(),
carouselController: _controller,
),
I combined SingleChildScrollView and CarouselSlider. But when I scroll down image, SingleChildScrollView intercept to move next image.
How can I solve this problem?
Related
I am using carousel slider package with smooth page indicator package to display the list of post items in Listview.builder.
I have successfully showing both the post and indicator in UI.
But my problem is while i swipe the images in first item, the dot indicator for all the items are moving along with it.
This is the code.
final CarouselController _controller = CarouselController();
CarouselSlider(
carouselController: _controller,
options: CarouselOptions(
height: 160.h,
enlargeCenterPage: false,
autoPlay: false,
aspectRatio: 16 / 9,
onPageChanged: (index, reason) {
setState(() {
_current = index;
});
},
autoPlayCurve: Curves.easeInBack,
enableInfiniteScroll:
dList[index].postUrl!.length == 1
? false
: true,
autoPlayAnimationDuration:
Duration(seconds: 10),
viewportFraction: 1.2,
),
items: name.map((item) {
return Padding(
padding: EdgeInsets.zero,
child: Container(
height: 200.h,
width: 350.w,
margin:
EdgeInsets.symmetric(vertical: 0),
child: InkWell(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder:
(BuildContext context) {
return Scaffold(
// backgroundColor: Colors.black,
extendBodyBehindAppBar: true,
appBar: AppBar(
backgroundColor:
Colors.transparent,
),
body: CarouselSlider(
carouselController:
_controller,
options: CarouselOptions(
height:
MediaQuery.of(context)
.size
.height,
enlargeCenterPage: true,
autoPlay: false,
aspectRatio: 16 / 9,
onPageChanged:
(index, reason) {
setState(() {
_current = index;
});
},
autoPlayCurve:
Curves.easeIn,
enableInfiniteScroll:
dList[index]
.postUrl!
.length ==
1
? false
: true,
viewportFraction: 1.0,
),
items: name.map((item) {
return Padding(
padding: EdgeInsets.zero,
child: Container(
height: MediaQuery.of(
context)
.size
.height,
width: MediaQuery.of(
context)
.size
.width,
margin: EdgeInsets
.symmetric(
vertical: 0),
child:
InteractiveViewer(
child: getRectangleImageForQRCode(
item.toString()),
),
),
);
}).toList(),
),
);
}));
},
child: getRectangleImageForQRCode(
item.toString()),
),
),
);
}).toList(),
),
dList[index].postUrl!.length == 1
? Container()
: Align(
alignment: Alignment.center,
child: AnimatedSmoothIndicator(
activeIndex: _current,
count:
dList[index].postUrl!.length <= 2
? 2
: 3,
effect: JumpingDotEffect(
dotHeight: 10.h,
dotWidth: 10.h,
jumpScale: .7,
verticalOffset: 20,
activeDotColor: Colors.red,
dotColor: Colors.grey),
),
)
What wrong in this code? Please help friends.
I want to know how to put the carousel items behind the center item, then when it slides there will be no spaces between items but it will stay behind
I have this:
And I want somethig like this:
This is my code:
CarouselSlider(
options: CarouselOptions(
height: Sizes.width,
enableInfiniteScroll: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
viewportFraction: 0.8,
onPageChanged: (index, reason) =>
setState(() => currentCard = index),
),
items: hardcore.map((i) {
return Builder(builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Image.asset(i, fit: BoxFit.cover)));
});
}).toList()),
Is there a way to find the index of a carousel item so I can use it to retrieve the related text and link associated with the items shown??
So I have 3 lists, a list for images, a list for text, and a list for urls.
Is there a way to find the associated index/key to reuse??
child: Container(
child: CarouselSlider(
options: CarouselOptions(
enlargeCenterPage: true,
enableInfiniteScroll: true,
autoPlay: true,
// pageSnapping: true,
),
items: listThumbs.map((e) => ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Stack(
//fit: StackFit.expand,
children: <Widget>[
Image.network(e,
width: 1050,
height: 350,
fit: BoxFit.cover,
),
Text(videObj.results[INDEX].name),
] ),
)).toList(),
)),
You can try using the builder method.
CarouselSlider example
CarouselSlider.builder(
itemCount: 15,
itemBuilder: (BuildContext context, int itemIndex, int pageViewIndex) =>
Container(
child: Text(itemIndex.toString()),
),
)
This method will give the index of every item.
You can call 'indexOf' in the map iteration area.
int idx = listThumbs.indexOf(e);
child: Container(
child: CarouselSlider(
options: CarouselOptions(
enlargeCenterPage: true,
enableInfiniteScroll: true,
autoPlay: true,
// pageSnapping: true,
),
items: listThumbs.map((e) {
// Here you can find item index.
int idx = listThumbs.indexOf(e);
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Stack(
//fit: StackFit.expand,
children: <Widget>[
Image.network(e,
width: 1050,
height: 350,
fit: BoxFit.cover,
),
Text(videObj.results[INDEX].name),
]),
);
}
)).toList(),
)),
body: RefreshIndicator(
onRefresh: _onRefresh,
child: ListView(
children:[
Stack(
children: [
BuildMainProfile(
screenHeight: screenHeight,
screenWidth: screenWidth,
uid: widget.uid,
callBack: widget.callBack,
),
DraggableScrollableSheet(
builder: (BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.blue[100],
child: ListView.builder(
controller: scrollController,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(title: Text('Item $index'));
},
),
);
},
)
],
),
] ),
),
The above codes give an error
These invalid constraints were provided to RenderFractionallySizedOverflowBox's layout() function by the following function, which probably computed the invalid constraints in question:
So How can we use DraggableScrollableSheet inside ListView
ListView is only used because of RefreshIndicator, it serves no other purpose. So is there an Alterntive
The glow acts like the entire screen is a list. There some way that I can put the glow below the appbar? (edit: without losing the floating effect of the appbar)
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Home Scree'),
floating: true,
leading: Icon(Icons.alarm),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, i) {
return Column(
children: <Widget>[
ProductCard(),
Divider(
height: 0,
thickness: 1,
),
],
);
},
childCount: 10,
),
),
],
),
Maybe you can try to use NestedScrollView,like this:
#override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [SliverAppBar(
leading: Icon(Icons.alarm),
title: Text('Home Scree'),
expandedHeight: kToolbarHeight,
floating: true,
)];
},
body: ListView.builder(
padding: EdgeInsets.zero,
itemCount: 10,
itemBuilder: (context, index) {
return Column(
children: <Widget>[
ProductCard(),
Divider(
height: 0,
thickness: 1,
),
],
);
}),
),
);
}