143 lines
4.0 KiB
Dart
143 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:tm_app/core/theme/colors.dart';
|
|
import 'package:tm_app/data/services/model/home/tender/tender_model.dart';
|
|
|
|
import '../../../core/constants/assets.dart';
|
|
import '../../../core/utils/size_config.dart';
|
|
import 'tender_card.dart';
|
|
|
|
class MainTendersSlider extends StatefulWidget {
|
|
const MainTendersSlider({
|
|
required this.tenders,
|
|
super.key,
|
|
this.isDesktop = false,
|
|
});
|
|
final bool isDesktop;
|
|
final List<TenderModel> tenders;
|
|
|
|
@override
|
|
State<MainTendersSlider> createState() => _MainTendersSliderState();
|
|
}
|
|
|
|
class _MainTendersSliderState extends State<MainTendersSlider> {
|
|
final PageController pageController = PageController(initialPage: 0);
|
|
|
|
int currentPage = 1;
|
|
|
|
void _goToPreviousPage() {
|
|
pageController.previousPage(
|
|
duration: Duration(milliseconds: 300),
|
|
curve: Curves.easeInOutCubic,
|
|
);
|
|
setState(() {
|
|
if (currentPage == 1) {
|
|
return;
|
|
}
|
|
currentPage = currentPage - 1;
|
|
});
|
|
}
|
|
|
|
void _goToNextPage() {
|
|
pageController.nextPage(
|
|
duration: Duration(milliseconds: 300),
|
|
curve: Curves.easeInOutCubic,
|
|
);
|
|
setState(() {
|
|
if (currentPage == widget.tenders.length) {
|
|
return;
|
|
}
|
|
currentPage = currentPage + 1;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
pageController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 717.0.h(),
|
|
child: PageView.builder(
|
|
controller: pageController,
|
|
scrollDirection: Axis.horizontal,
|
|
itemCount: widget.tenders.length,
|
|
onPageChanged: (index) {
|
|
setState(() {
|
|
currentPage = index + 1;
|
|
});
|
|
},
|
|
itemBuilder: (context, index) {
|
|
final tender = widget.tenders[index];
|
|
return TenderCard(tender: tender, isDesktop: widget.isDesktop);
|
|
},
|
|
),
|
|
),
|
|
Positioned(
|
|
top: 607.0.h(),
|
|
bottom: 52.0.h(),
|
|
left: 9.0.w(),
|
|
right: 9.0.w(),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: _goToPreviousPage,
|
|
child: Container(
|
|
width: 32.0.w(),
|
|
height: 32.0.w(),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: AppColors.iconColor, width: 1.5),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: SvgPicture.asset(
|
|
AssetsManager.arrowLeftSmall,
|
|
colorFilter: ColorFilter.mode(
|
|
AppColors.iconColor,
|
|
BlendMode.srcATop,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
'$currentPage/${widget.tenders.length}',
|
|
style: TextStyle(
|
|
fontSize: 14.0.sp(),
|
|
fontWeight: FontWeight.w500,
|
|
color: AppColors.grey,
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: _goToNextPage,
|
|
child: Container(
|
|
width: 32.0.w(),
|
|
height: 32.0.w(),
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: AppColors.iconColor, width: 1.5),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: SvgPicture.asset(
|
|
AssetsManager.arrowRightSmall,
|
|
colorFilter: ColorFilter.mode(
|
|
AppColors.iconColor,
|
|
BlendMode.srcATop,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|