import 'package:wanisclient/config/custom_text.dart'; import 'package:wanisclient/utils/colors.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import '../config/constants/app_constant.dart'; import '../config/language/language_enum.dart'; import '../providers/language_provider.dart'; import 'custom_button.dart'; class DriverInfoCard extends StatelessWidget { final String driverName; final String driverImage; final String estimatedArrival; final String tripCost; final String distance; final String carModel; final String licensePlate; final String starLocation; final String endLocation; final String paymentmethode; final int rating; final VoidCallback onCall; final VoidCallback onCancel; final VoidCallback? onCollapse; final bool isExpanded; final double systembottompadding; const DriverInfoCard({ Key? key, required this.driverName, required this.driverImage, required this.estimatedArrival, required this.starLocation, required this.tripCost, required this.distance, required this.carModel, required this.licensePlate, required this.endLocation, required this.paymentmethode, required this.rating, required this.onCall, required this.systembottompadding, required this.onCancel, this.onCollapse, this.isExpanded = false, }) : super(key: key); @override Widget build(BuildContext context) { final languageProvider = context.watch(); bool isArabic = languageProvider.currentLangCode == Language.ar; // Calculate available height more intelligently final screenHeight = MediaQuery.of(context).size.height; final maxHeight = screenHeight * 0.6; // Max 60% of screen height final minHeight = 250.h; // Minimum height to ensure content fits return Container( width: MediaQuery.of(context).size.width, decoration: const BoxDecoration( color: AppNewColors.primaryBtnColor, borderRadius: BorderRadius.only( topLeft: Radius.circular(25), topRight: Radius.circular(25), ), boxShadow: [ BoxShadow( color: Colors.black12, blurRadius: 10, offset: Offset(0, -2), ), ], ), child: Stack( children: [ // OPTION 1: Use flexible sizing with constraints ConstrainedBox( constraints: BoxConstraints( minHeight: minHeight, maxHeight: maxHeight, ), child: IntrinsicHeight( child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ // Header with arrival time and purple background Container( width: double.infinity, padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 12.h), decoration: const BoxDecoration( color: AppNewColors.primaryBtnColor, borderRadius: BorderRadius.only( topLeft: Radius.circular(25), topRight: Radius.circular(25), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Flexible( flex: 3, child: Row( children: [ Container( padding: EdgeInsets.all(8.w), decoration: const BoxDecoration( color: Colors.white, shape: BoxShape.circle, ), child: Icon( Icons.arrow_upward, color: Colors.black, size: 20.sp, ), ), SizedBox(width: 8.w), Flexible( child: Txt( text: "Your driver will be arrive", style: GoogleFonts.poppins( fontSize: 14.sp, fontWeight: FontWeight.w500, color: Colors.white, ), overflow: TextOverflow.ellipsis, maxLines: 1, ), ), ], ), ), Flexible( flex: 2, child: Row( mainAxisSize: MainAxisSize.min, children: [ Container( padding: EdgeInsets.symmetric( horizontal: 16.w, vertical: 8.h), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20.r), ), child: Txt( text: estimatedArrival, style: GoogleFonts.poppins( fontSize: 14.sp, fontWeight: FontWeight.w500, color: Colors.black, ), ), ), SizedBox(width: 8.w), GestureDetector( onTap: onCall, child: Container( padding: EdgeInsets.all(8.w), decoration: const BoxDecoration( color: Colors.white, shape: BoxShape.circle, ), child: Icon( Icons.call, color: Colors.black, size: 16.sp, ), ), ), ], ), ), ], ), ), // White content container - now flexible Flexible( child: Container( width: double.infinity, padding: EdgeInsets.only( top: 12.h, bottom: 80.h + systembottompadding, // Space for button left: 0, right: 0, ), decoration: const BoxDecoration( color: AppNewColors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(25), topRight: Radius.circular(25), ), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ // Driver info section Padding( padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 5), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ // Driver avatar Container( decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: const Color(0xffE3E3E3), width: 2), ), child: ClipOval( child: CachedNetworkImage( imageUrl: '$mediaUrl${driverImage}', width: 41.w, height: 41.w, fit: BoxFit.cover, placeholder: (_, __) => SizedBox( width: 41.w, height: 41.w, child: const CircularProgressIndicator( strokeWidth: 2), ), errorWidget: (_, __, ___) => Image.asset( 'assets/images/wanislogo.png', width: 41.w, height: 41.w, fit: BoxFit.cover, ), ), ), ), SizedBox(width: 16.w), // Driver details Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( driverName, style: GoogleFonts.poppins( fontSize: 16.sp, fontWeight: FontWeight.w600, color: Colors.black, ), ), Row( children: [ Text( licensePlate, style: GoogleFonts.poppins( fontSize: 15.sp, fontWeight: FontWeight.w500, color: Colors.black87, ), ), const Padding( padding: EdgeInsets.symmetric( horizontal: 8.0), child: Icon(Icons.circle, color: Colors.black, size: 6), ), Row( mainAxisSize: MainAxisSize.min, children: [ Text( rating.toStringAsFixed(1), style: GoogleFonts.poppins( fontSize: 15.sp, fontWeight: FontWeight.w500, color: Colors.black87, ), ), SizedBox(width: 2.w), SvgPicture.asset( 'assets/icons/rating_star.svg', width: 24, height: 24, colorFilter: const ColorFilter.mode( AppNewColors.yellowColor, BlendMode.srcIn, ), ), ], ), ], ), ], ), ), Image.asset( 'assets/images/wanis.png', width: 77.w, height: 49.w, ), ], ), ), SizedBox(height: 20.h), // Trip locations section Padding( padding: EdgeInsets.symmetric(horizontal: 20.w), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Section headers Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Txt( text: "PICK UP", style: GoogleFonts.poppins( fontSize: 15.sp, fontWeight: FontWeight.w600, color: const Color(0xff8D8D8D), letterSpacing: 1.2, ), ), Txt( text: "DROP OFF", style: GoogleFonts.poppins( fontSize: 15.sp, fontWeight: FontWeight.w600, color: const Color(0xff8D8D8D), letterSpacing: 1.2, ), ), ], ), SizedBox(height: 8.h), // Locations Row( children: [ // Start location Expanded( child: Text( starLocation, style: GoogleFonts.poppins( fontSize: 15.sp, fontWeight: FontWeight.w500, color: Colors.black, ), overflow: TextOverflow.ellipsis, ), ), // End location Expanded( child: Text( endLocation, style: GoogleFonts.poppins( fontSize: 15.sp, fontWeight: FontWeight.w500, color: Colors.black, ), overflow: TextOverflow.ellipsis, textAlign: TextAlign.end, ), ), ], ), ], ), ), SizedBox(height: 20.h), // Payment section Padding( padding: EdgeInsets.symmetric(horizontal: 20.w), child: Container( padding: EdgeInsets.symmetric(vertical: 12.h), decoration: const BoxDecoration( border: Border( top: BorderSide( color: Color(0xffE3E3E3), width: 1), ), ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Flexible( child: Row( children: [ SvgPicture.asset( 'assets/icons/wallet_payment_method.svg', width: 20.w, height: 20.w, ), SizedBox(width: 8.w), Flexible( child: Text( paymentmethode, style: GoogleFonts.poppins( fontSize: 14.sp, color: Colors.black, ), overflow: TextOverflow.ellipsis, ), ), SizedBox(width: 4.w), Icon( Icons.arrow_forward_ios, size: 12.sp, color: Colors.black, ), ], ), ), Row( children: [ Text( tripCost, style: GoogleFonts.poppins( fontSize: 14.sp, fontWeight: FontWeight.w500, color: AppNewColors.primaryBtnColor, ), ), Text( languageProvider.translate('+ tarif compteur'), style: TextStyle( fontFamily: isArabic ? "Readex_Pro" : 'Inter', fontSize: 12.sp, fontWeight: FontWeight.w500, color: AppNewColors.detailsSColors, ), ), ], ), ], ), ), ), ], ), ), ), ], ), ), ), _buildCancelButton(context), ], ), ); } Widget _buildCancelButton(BuildContext context) { return Positioned( left: 0, right: 0, bottom: 0, child: Container( padding: EdgeInsets.fromLTRB(20, 12, 20, systembottompadding + 12), decoration: BoxDecoration( color: Colors.white, boxShadow: const [ BoxShadow( color: Color(0x0F000000), blurRadius: 10, offset: Offset(0, 2), ), ], border: Border(top: BorderSide(color: Colors.grey.shade200, width: 1.0)), ), child: CustomButton( onClick: onCancel, width: double.infinity, fontSize: 18, height: 50, borderRadius: 12, txtColor: Colors.white, title: "Cancel Ride", backgroundColor: AppNewColors.primaryBtnColor, borderColor: AppNewColors.primaryBtnColor, loadercolor: Colors.white, ), ), ); } }