I Have issue in flutter slider - flutter

image 1
i want to build image slider like this from the left start of phone
but i have getting issue in slider my slider is starting from center of the page in flutter
image 2
here is my code.
CarouselSlider.builder(
itemCount: serviceDataList?.length,
options: CarouselOptions(
height: 100.0,
enlargeCenterPage: false,
aspectRatio: 16 / 9,
autoPlayAnimationDuration: Duration(
milliseconds: 800),
),
itemBuilder: (context, i, id){
return Container(
width: 100,
margin: EdgeInsets.all(8.0),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
sliderDataList.isEmpty ? '' : sliderDataList[i]['mslider_img']),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(10.0),
),
// child:
// Image(
// image: NetworkImage(
// sliderDataList[i]['mslider_img']),
// fit: BoxFit.cover,
// ),
);
}
),
I Just Want help In This Code

Change viewportFraction in CarouselOptions to smaller number that match container fixed width viewportFraction: 0.2 for example & add padEnds: false

Related

Flutter Container reduced it width when I added a child property .Why?

I wanted to make a carousel with some images along with some texts.So I put the images inside a container .But when I added a Text widget as the child of the container, the container shrinks to minimum width . Why ?
CarouselSlider(
items: [
//1st Image of Slider
Container(
child: Text("Diverse stories you'll love"),
margin: EdgeInsets.all(6.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
image: DecorationImage(
image: AssetImage("images/welcomepage1.jpg"),
fit: BoxFit.cover,
),
),
),
//2nd Image of Slider
Container(
child: Text("Make friends and share your voice"),
margin: EdgeInsets.all(6.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.0),
image: DecorationImage(
image: AssetImage("images/welcomepage2.jpg"),
fit: BoxFit.cover,
),
),
),
],
//Slider Container properties
options: CarouselOptions(
height: 300.0,
enlargeCenterPage: true,
autoPlay: true,
aspectRatio: 16 / 9,
autoPlayCurve: Curves.fastOutSlowIn,
enableInfiniteScroll: true,
autoPlayAnimationDuration: Duration(milliseconds: 800),
viewportFraction: 0.8,
),
),
Containers with no children try to be as big as possible unless the incoming constraints are unbounded, in which case they try to be as small as possible. Containers with children size themselves to their children. The width, height, and constraints arguments to the constructor override this.
From the Flutter documentation.

flutter swiper when only have 1 item

using flutter swipper package, how to remove side image (my marked red) if have 1 item only?
I already try change to viewportFraction: 1 but it's change width to full width, I wan't change size width, only hide side image
this part of my code
Swiper(
autoplay: true,
itemBuilder: (BuildContext context,
int index) {
return InkWell(
child: Card(
margin: new EdgeInsets.only(
bottom: 30
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius
.circular(20)
),
child: (
ClipRRect(
child: (
CachedNetworkImage(
imageUrl: dataPromo[index].bannerPath,
fit: BoxFit.fill,
)
)
)
)
),
);
},
itemCount: dataPromo.length,
viewportFraction: 0.8,
scale: 0.9,
),
Have you tried change the viewportFraction to viewportFraction: 1.0?

How to change the items from carousel_slider with some trigger / action in Flutter?

I'm having trouble replacing a set of images in the carousel_slider with an action / trigger like onAccept() in my code
I currently using a draggable the slider, and my goal is I want to change the set of images when I'm dragging the image into the dragTarget by onAccept
how can I achieve that? I appreciate for your help
this is the carousel_slider code:
CarouselSlider _pilihanMakanan = CarouselSlider(
items: _listMakanan.map((makanan) {
return Row(children: [
Expanded(
flex: 1,
child: LongPressDraggable<Makanan>(
data: makanan,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 2),
child: Image(
image: AssetImage(makanan.image),
fit: BoxFit.contain,
// width: 50,
),
),
feedback: Tooltip(
message: makanan.nama,
child: Image(
image: AssetImage(makanan.image),
fit: BoxFit.contain,
width: 100,
),
),
childWhenDragging: Container(),
),
),
]);
}).toList(),
options: CarouselOptions(
height: 70,
autoPlay: false,
enlargeCenterPage: true,
enableInfiniteScroll: false,
viewportFraction: 0.15,
),
);
and this is the slider implementation :
Container(
margin: EdgeInsets.fromLTRB(0, 45, 119, 19),
alignment: Alignment.center,
child: DragTarget<Makanan>(
onAccept: (makanan) {
setState(() {
_pokok = makanan.image;
_targetImageUrl = makanan.image;
_totalKalori += makanan.kalori;
_listMakanan = _listLauk; <--- this code seems not working
});
},
builder: (simulation, candidateData, rejectedData) {
return Container(
alignment: Alignment.center,
child: _targetImageUrl != ''
? Image(
image: AssetImage(_targetImageUrl),
width: 50,
)
: Container(
child: Image(
image: AssetImage("assets/images/pokok.png"),
width: 120,
),
),
);
},
)),
this code seems doesn't work as i thought
onAccept: (makanan) {
setState(() {
_listMakanan = _listLauk; });
Thank you for your attention, I really appreciate for your help

Image glitch in Image.network or NetworkImage

Hi I'm loading my profile pics from my server in Image.network and showing it in a pageview to show next pictures. But when my image load from the internet it become a glitch as shown in the picture.
But when i open the same link in google chrome there is no glitch in my profile pic
This is the code is what i used to list
photos.forEach((photo) {
profileImages.add(
Container(
child: Stack(
fit: StackFit.expand,
children: <Widget>[
Image(
image: NetworkImage(
APis().imageApi(
photo.photoName,
),
),
filterQuality: FilterQuality.low,
fit: BoxFit.cover,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
gradient: LinearGradient(colors: [
Colors.black12,
Colors.transparent,
Colors.black,
], stops: [
0.25,
0.75,
1.0
], begin: FractionalOffset.topCenter, end: FractionalOffset.bottomCenter)),
),
],
),
),
);
});
print("profileImages :${photos.length} ${profileImages.length}");
}
And this is what i displaying in pageview
PageView.builder(
controller: pageController,
onPageChanged: onPageChanged,
itemCount: profileImages.length,
itemBuilder: (context, position) {
return profileImages[position];
})
So my question is do i have to change anything or do i have to put placeholder?
The way I've handled it is by using a placeholder, so I use a Stack, i put the placeholder image underneath it and then once it loads, it just shows on top.
See the before and after:
And the code just pretty much looks like this:
ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Image.asset('assets/placeholder.jpg',
fit: BoxFit.cover,
width: 600.0,
height: 900.0
),
Image.network(imgPath,
fit: BoxFit.cover,
width: 600.0,
height: 900.0
)]))

How to give the carousel image the full screen width?

I am learning about carousel in flutter. I want to give the carousel image the full screen width. But the width is automatically taken by the carousel itself. Is there any way to give the image the full screen width inside carousel?
Here I have used both carousel_pro and carousel_slider, neither works as I expected. Please help.
List _images = [
Image.network(
"https://stimg.cardekho.com/images/carexteriorimages/630x420/Lamborghini/Lamborghini-Huracan-EVO/6731/1546932239757/front-left-side-47.jpg?tr=w-456,e-sharpen"),
Image.network(
"https://auto.ndtvimg.com/car-images/big/lamborghini/aventador/lamborghini-aventador.jpg?v=5"),
Image.network(
"https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/gateway-family/few-off/sian/car_sian.png"),
Image.network(
"https://www.topgear.com/sites/default/files/styles/16x9_1280w/public/images/news-article/2018/01/38eba6282581b285055465bd651a2a32/2bc8e460427441.5a4cdc300deb9.jpg?itok=emRGRkaa"),
Image.network(
"https://blog.dupontregistry.com/wp-content/uploads/2013/05/lamborghini-egoista.jpg"),
];
List _images2 = [
"https://stimg.cardekho.com/images/carexteriorimages/630x420/Lamborghini/Lamborghini-Huracan-EVO/6731/1546932239757/front-left-side-47.jpg?tr=w-456,e-sharpen",
"https://auto.ndtvimg.com/car-images/big/lamborghini/aventador/lamborghini-aventador.jpg?v=5",
"https://www.lamborghini.com/sites/it-en/files/DAM/lamborghini/gateway-family/few-off/sian/car_sian.png",
"https://www.topgear.com/sites/default/files/styles/16x9_1280w/public/images/news-article/2018/01/38eba6282581b285055465bd651a2a32/2bc8e460427441.5a4cdc300deb9.jpg?itok=emRGRkaa",
"https://blog.dupontregistry.com/wp-content/uploads/2013/05/lamborghini-egoista.jpg",
];
Carousel(
images: _images,
autoplay: true,
boxFit: BoxFit.fitWidth,
dotBgColor: Colors.transparent,
dotSize: 3,
dotColor: Colors.red,
dotIncreasedColor: Colors.red,
autoplayDuration: Duration(seconds: 3),
animationCurve: Curves.fastOutSlowIn,
),
),
SizedBox(height: 20),
CarouselSlider(
items: _images2
.map(
(x) => Container(
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(x, scale: 1),
),
),
),
)
.toList(),
autoPlay: true,
height: 200.0,
),
CarouselSlider(
options: CarouselOptions(
viewportFraction: 1,
This is example, hope it works for you
List<String> imgList;
CarouselSlider(
items: map<Widget>(
imgList,
(index, i) {
return Container(
margin: EdgeInsets.all(5.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
child: Stack(children: <Widget>[
InkResponse(
child: Image.network(i,
fit: BoxFit.cover, width: 1000.0),
onTap: //....
this simple example from me
CarouselSlider(
items: _products
.map(
(p) => Image.network(
p.foto,
width: MediaQuery.of(context).size.width,
fit: BoxFit.cover,
),
)
.toList(),
options: CarouselOptions(
viewportFraction: 1.0,
enlargeCenterPage: false,
initialPage: 0,
onPageChanged: (index, reason) {
setState(() {
currentIndex = index;
_product = _products[index];
});
},
),
),
use padEnds Property of CarouselSlider,
also assign full width for image
CarouselSlider(
items: photoList
.map(
(e) => SizedBox(
width: double.maxFinite,
child: Image.network(
e,
fit: BoxFit.fitWidth,
),
),
)
.toList(),
options: CarouselOptions(
autoPlay: false,
initialPage: 0,
enableInfiniteScroll: false,
padEnds: false, // take full width, remove padding from all size
),
)