import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; import '../Provider/RideProvider.dart'; import '../Provider/driver_provider.dart'; import '../utils/colors.dart'; import 'CustomLoadingWidget.dart'; import 'summary_item.dart'; class TopSection extends StatefulWidget { final DateTime currentDate; const TopSection({ super.key, required this.currentDate, }); @override _TopSectionState createState() => _TopSectionState(); } class _TopSectionState extends State { late DriverProvider driverProvider; bool isLoading = true; @override void initState() { super.initState(); driverProvider = Provider.of(context, listen: false); _fetchSummary(widget.currentDate); } @override void didUpdateWidget(covariant TopSection oldWidget) { super.didUpdateWidget(oldWidget); if (widget.currentDate != oldWidget.currentDate) { _fetchSummary(widget.currentDate); } } Future _fetchSummary(DateTime date) async { setState(() => isLoading = true); await driverProvider.summarydriver(date); if (!mounted) return; setState(() => isLoading = false); } @override Widget build(BuildContext context) { // if (isLoading) { // return const CustomLoadingWidget(); // } return Stack( clipBehavior: Clip.none, children: [ SvgPicture.asset( 'assets/images/topcurvehistoryscreen.svg', fit: BoxFit.cover, height: MediaQuery.of(context).size.height * 0.21, width: MediaQuery.of(context).size.width, color: Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor:AppColors.primaryColor, ), Positioned( top: MediaQuery.of(context).size.height * 0.072, left: MediaQuery.of(context).size.width * 0.05, right: MediaQuery.of(context).size.width * 0.05, child: Column( children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const Text( 'Courses', style: TextStyle( fontSize: 24, color: Colors.white, fontWeight: FontWeight.bold, ), ), InkWell( onTap: () { Provider.of(context, listen: false).refresh( date: DateFormat('yyyy-MM-dd') .format(widget.currentDate)); }, child: SvgPicture.asset( 'assets/images/iconsrefresh.svg', // height:30, color: Colors.white, width: 20, ), ), ], ), const SizedBox(height: 16), Container( height: 190, padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.5), blurRadius: 8, ), ], ), child: Column( children: [ const SizedBox(height: 3), Text( DateFormat('EEE, d MMM yyyy').format(widget.currentDate), style: const TextStyle( fontSize: 14, color: Colors.grey, ), ), const SizedBox(height: 8), Text( '${driverProvider.currentdriversummarydate?.totalEarnings.toStringAsFixed(2) ?? 0} TND', style: const TextStyle( fontSize: 24, fontWeight: FontWeight.bold), ), const SizedBox(height: 25), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ SummaryItem( value: driverProvider .currentdriversummarydate?.totalRidesCompleted .toString() ?? '10', label: 'Trips', ), SummaryItem( value: driverProvider.currentdriversummarydate?.totalDuration != null ? (driverProvider.currentdriversummarydate!.totalDuration / 60).toStringAsFixed(1) : '0', label: 'Online hrs', ), SummaryItem( value: driverProvider .currentdriversummarydate?.totalRidesCanceled .toString() ?? '0', label: 'Cancelled', ), ], ), ], ), ), ], ), ), ], ); } }