I have a Image Slider in Clip react widget, and there is a grid view of images in the bottom of it,like gallery. But when i slide image it change its index in the grid section but when i tap on grid and change from there it cannot change the picture
Here's my code can anyone knows the issue?
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:osticket_app/ticket_details/attachments/attachement_preview.dart';
import 'package:osticket_app/utils/colors.dart';
import '../../utils/responsive_layout.dart';
class MyCustomMobileContent extends StatelessWidget {
const MyCustomMobileContent({super.key});
@override
Widget build(BuildContext context) {
return const Scaffold(
body: ResposiveLayout(
mobileBody: ImageSlider(),
),
);
}
}
List<String> imgList = [
'assets/images/attachment.png',
'assets/images/school.png',
'assets/images/medic.png',
'assets/images/attachment.png',
'assets/images/medic.png',
'assets/images/school.png',
'assets/images/attachment.png',
'assets/images/medic.png',
];
class ImageSlider extends StatefulWidget {
const ImageSlider({super.key});
@override
State<ImageSlider> createState() => _ImageSliderState();
}
class _ImageSliderState extends State<ImageSlider> {
late List<Widget> imageSliders;
int _current = 0;
int selected = 0;
final CarouselController _controller = CarouselController();
@override
Widget build(BuildContext context) {
imageSliders = imgList
.map(
(item) => ClipRRect(
borderRadius: BorderRadius.circular(
10.r,
),
child: Stack(
children: <Widget>[
Center(
child: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (ctx) => AttachementPreview(
image: item,
),
),
);
},
child: Image.asset(
fit: BoxFit.fill,
item,
),
),
),
],
),
),
)
.toList();
return Scaffold(
appBar: AppBar(
actions: [
Padding(
padding: EdgeInsets.only(right: 10.w),
child: TextButton(
onPressed: () {},
child: Text(
'Download',
style: TextStyle(
fontSize: 14.sp,
color: buttonColor,
fontWeight: FontWeight.w500),
),
),
),
],
bottom: PreferredSize(
preferredSize: Size.fromHeight(
1.h,
),
child: Divider(
color: textFieldBg,
height: 2.h,
),
),
),
body: Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.w,
color: textFieldBg,
)),
child: CarouselSlider(
items: imageSliders,
carouselController: _controller,
options: CarouselOptions(
height: 500.h,
viewportFraction: 1,
autoPlay: false,
// enlargeCenterPage: true,
aspectRatio: 2.0,
onPageChanged: (index, reason) {
setState(() {
_current = index;
});
}),
),
),
SizedBox(
height: 20.h,
),
Text(
'Medical-claim-cardiologist.png',
style: TextStyle(fontSize: 14.sp, fontWeight: FontWeight.w700),
),
SizedBox(
height: 20.h,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: imgList.asMap().entries.map((entry) {
return GestureDetector(
onTap: () => _controller.animateToPage(entry.key),
child: Container(
width: 8.w,
height: 8.h,
margin: EdgeInsets.symmetric(vertical: 8.h, horizontal: 4.w),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: (Theme.of(context).brightness == Brightness.dark
? backgroundColor
: buttonColor)
.withOpacity(_current == entry.key ? 0.9 : 0.2),
),
),
);
}).toList(),
),
SizedBox(
height: 20.h,
),
SizedBox(
height: 85.h,
// width: 350.w,
child: ListView.builder(
scrollDirection:
Axis.horizontal, // Set the scroll direction to horizontal
itemCount: imgList.length,
itemBuilder: (context, index) {
return Padding(
padding:
EdgeInsets.symmetric(horizontal: 10.h, vertical: 10.w),
child: GestureDetector(
onTap: () {
setState(() {
_current = index;
});
},
child: Container(
padding: EdgeInsets.all(1.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6.r),
border: Border.all(
width: 1.6.w,
color: _current == index
? buttonColor
: Colors.transparent),
),
child: Image.asset(
imgList[index],
width: 50.w, // Set the width of the image
height: 150.h, // Set the height of the image
fit: BoxFit
.fitHeight, // You can adjust the fit as needed
),
),
),
);
},
),
),
// ListView.builder(itemBuilder: itemBuilder)
],
),
);
}
}
as you can see the code, i hope you understand my issue and try to fix this as soon as possible,Thanks in advance