// import 'dart:async'; // import 'dart:developer'; // import 'package:wanisdriver/Provider/utils_singleton.dart'; // import 'package:wanisdriver/config/enum/ride_enum.dart'; // import 'package:flutter/material.dart'; // import 'package:get/get.dart'; // import 'package:google_maps_flutter/google_maps_flutter.dart' as gms; // import 'package:latlong2/latlong.dart' as ll; // import 'package:provider/provider.dart'; // import '../Provider/RideNotification.dart'; // import '../Provider/RideProvider.dart'; // import '../Provider/RideRequestProvider.dart'; // import '../Provider/RideStatusProvider.dart'; // import '../config/custom_loader.dart'; // import '../routes/app_routes.dart'; // import '../services/PubNubDriverManager.dart'; // import '../utils/colors.dart'; // import '../widgets/RideDetailColumn.dart'; // // ─── helper to jump between the two LatLng classes ───────────────────────── // extension L2Google on ll.LatLng { // gms.LatLng get g => gms.LatLng(latitude, longitude); // } // class RideRequestScreen extends StatefulWidget { // final int rideId; // const RideRequestScreen({ Key? key, required this.rideId }) : super(key: key); // // @override // _RideRequestScreenState createState() => _RideRequestScreenState(); // } // class _RideRequestScreenState extends State with WidgetsBindingObserver{ // @override // bool get wantKeepAlive => true; // late RideRequestProvider _rideNotifier; // late RideStatusProvider _rideStatusProvider; // late RideProvider _rideProvider; // // bool _mapReady = false; // late DriverPubNubManager _socketManager; // // // gms.GoogleMapController? _controller; // // @override // void initState() { // super.initState(); // WidgetsBinding.instance.addObserver(this); // WidgetsBinding.instance.addPostFrameCallback((_) async { // _rideProvider = context.read(); // _rideNotifier = context.read(); // _rideStatusProvider = context.read(); // _socketManager = context.read(); // _rideNotifier.initializeRide(_rideProvider, widget.rideId); // // }); // } // // // // @override // void dispose() { // WidgetsBinding.instance.removeObserver(this); // // _controller?.dispose(); // super.dispose(); // } // // // // @override // Widget build(BuildContext context) { // final rideProvider = context.watch(); // final rideNotifier = context.watch(); // final ridestatus = context.watch(); // // log('ride id : ${widget.rideId} -----------------------------------------------------------------------------------'); // if ( rideProvider.isLoadingById ) { // log("rideProvider.isLoadingById: ${rideProvider.isLoadingById}"); // // return const Scaffold( // body: Center(child: CustomLoader( // logoSize: 60.0, // dotSize: 10.0, // // ),), // ); // } // // final routePoints = rideProvider.getRoutePoints(); // if ( routePoints.isEmpty) { // // log("routePoints isEmpty: ${routePoints.isEmpty}"); // return const Scaffold( // body: Center(child: CustomLoader( // logoSize: 60.0, // dotSize: 10.0, // // )), // ); // } // // if (rideProvider.currentride == null) { // return const Scaffold( // body: Center(child: Text("No ride details available")), // ); // } // // // final end = routePoints.last; // // // final isRequestVisible = rideNotifier.isRequestVisible; // // // /* ---------------------------- google-maps collections ------------ */ // final first = routePoints.first.g; // final last = routePoints.last.g; // // final polyline = gms.Polyline( // polylineId: const gms.PolylineId('ride'), // width : 4, // color : Colors.blue, // points : routePoints.map((e) => e.g).toList(), // ); // // final markers = { // gms.Marker( // markerId : const gms.MarkerId('start'), // position : first, // icon : gms.BitmapDescriptor.defaultMarkerWithHue( // gms.BitmapDescriptor.hueGreen), // ), // gms.Marker( // markerId : const gms.MarkerId('end'), // position : last, // icon : gms.BitmapDescriptor.defaultMarkerWithHue( // gms.BitmapDescriptor.hueRed), // ), // }; // return Scaffold( // body: Stack( // children: [ // // MAP Section // /* ---------------- Google Map ---------------- */ // gms.GoogleMap( // initialCameraPosition: gms.CameraPosition(target: first, zoom: 13), // markers : markers, // polylines : {polyline}, // onMapCreated: (c) { // _controller = c; // _mapReady = true; // }, // zoomControlsEnabled: false, // myLocationEnabled : false, // ), // // // // Decline Button // if (isRequestVisible) // Positioned( // top: 50, // right: 16, // child: GestureDetector( // onTap: () async { // _socketManager.sendDeclineRide(rideId: widget.rideId); // context.read().removeRide(widget.rideId); // // }, // "Refuser" // child: Container( // padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), // decoration: BoxDecoration( // color: Colors.red.withOpacity(0.9), // borderRadius: BorderRadius.circular(30.0), // ), // child: Row( // mainAxisSize: MainAxisSize.min, // children: [ // Container( // width: 30, // height: 30, // decoration: const BoxDecoration( // color: Colors.white, // shape: BoxShape.circle, // ), // child: const Center( // child: Icon( // Icons.close_rounded, // color: Color(0xFFF44B00), // size: 18, // ), // ), // ), // const SizedBox(width: 8.0), // const Text( // "Refuse", // style: TextStyle( // color: Colors.white, // fontSize: 16, // fontFamily: 'Poppins', // fontWeight: FontWeight.bold, // ), // ), // ], // ), // ), // ), // ), // // // The Ride Request Card // if (isRequestVisible) // Positioned( // bottom: 0, // left: 0, // right: 0, // child: AnimatedContainer( // duration: const Duration(milliseconds: 300), // curve: Curves.easeInOut, // padding: const EdgeInsets.all(16.0), // child: Material( // elevation: 10, // shadowColor: Colors.black.withOpacity(0.078), // borderRadius: BorderRadius.circular(20), // child: Container( // padding: const EdgeInsets.all(16.0), // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(20.0), // ), // child: SingleChildScrollView( // child: Column( // mainAxisSize: MainAxisSize.min, // children: [ // Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // const Icon( // Icons.access_time_filled, // color: AppColors.primaryColor, // size: 24, // ), // SizedBox(width: 8.0), // Text( // "${rideProvider.currentride!.durationInMinutes?.toStringAsFixed(2)} Min", // style: const TextStyle( // fontSize: 18, // fontFamily: 'Poppins', // fontWeight: FontWeight.bold, // ), // ), // ], // ), // const SizedBox(height: 16), // SizedBox( // width: 250, // child: ElevatedButton( // onPressed: () async { // _socketManager.sendAcceptRide(rideId: widget.rideId,username: rideProvider.currentride!.riderusername); // Use singleton // _rideNotifier.acceptRide(); // _rideStatusProvider.updatestates(RideEnum.to_client); // context.read().clearAllPendingRides(); // await context.read().locationconnectionservice(); // // 1) Try to pop until we find a route named AppRoutes.main // bool foundMain = false; // Navigator.of(Get.context!).popUntil((route) { // if (route.settings.name == AppRoutes.main) { // foundMain = true; // return true; // stop popping // } // return false; // keep popping // }); // // // 2) If MainScreen was not already on the stack, push it exactly once. // if (!foundMain) { // // This will clear everything and then push a single MainScreen. // // Because the old one wasn’t on the stack, there is no key‐collision. // Get.offAllNamed(AppRoutes.main); // } // }, // style: ElevatedButton.styleFrom( // backgroundColor: AppColors.primaryColor, // shape: RoundedRectangleBorder( // borderRadius: BorderRadius.circular(50), // ), // padding: const EdgeInsets.symmetric(vertical: 5.0, horizontal: 5), // ), // child: const Row( // mainAxisAlignment: MainAxisAlignment.center, // children: [ // Expanded( // child: Text( // "Accept", // textAlign: TextAlign.center, // style: TextStyle( // fontSize: 13, // fontWeight: FontWeight.w600, // fontFamily: 'Poppins', // color: Colors.white, // ), // ), // ), // // ], // ), // ), // ), // const SizedBox(height: 16), // Row( // mainAxisAlignment: MainAxisAlignment.spaceEvenly, // children: [ // RideDetailColumn( // icon: Icons.monetization_on, // value: "${rideProvider.currentride?.totalPrice?.toStringAsFixed(2)??0} TND", // label: "Espèces", // color: Color(0xFFF74B01), // colordescription: Color(0xFFBFBFBF), // ), // RideDetailColumn( // icon: Icons.star, // value: rideProvider.currentride!.averagedriverrating.toStringAsFixed(2), // label: "Rating", // color: const Color(0xFFF74B01), // colordescription: const Color(0xFFBFBFBF), // ), // RideDetailColumn( // icon: Icons.route_rounded, // value: "${rideProvider.currentride!.distancekm.toStringAsFixed(2)} km", // label: "Ride", // color: const Color(0xFFF74B01), // colordescription: const Color(0xFFBFBFBF), // ), // ], // ), // const SizedBox(height: 16), // Column( // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // const Divider(thickness: 1.0), // const SizedBox(height: 8.0), // // /* --- start location --- */ // _placeRow( // icon: Icons.location_pin, // color: Colors.green, // displayName: rideProvider.currentride!.startLocationName, // <-- // startDots: true, // endDots: false, // ), // const SizedBox(height: 8.0), // /* --- end location --- */ // _placeRow( // icon: Icons.location_pin, // color: const Color(0xFFF74B01), // displayName: rideProvider.currentride!.endLocationName, // <-- // startDots: false, // endDots: true, // ), // // ], // ) // // // ], // ), // ), // ), // ), // ), // ), // ], // ), // ); // } // Map _splitDisplay(String full) { // final parts = full.split(','); // return { // 'title' : parts.first.trim(), // 'label' : (parts.length > 1 ? parts[1].trim() : '') // }; // } // Widget _placeRow({ // required IconData icon, // required Color color, // required String? displayName, // required bool startDots, // required bool endDots, // }) { // if (displayName == null) { // return const Text('…', style: TextStyle(color: Colors.grey)); // still loading // } // final split = _splitDisplay(displayName); // return RideLocationRow( // icon: icon, // color: color, // colordescription: const Color(0xFFBFBFBF), // title: split['title']!, // street (or first chunk) // label: split['label']!, // city (second chunk) // isBold: true, // isStartdots: startDots, // isEnddots: endDots, // ); // } // @override // void didChangeAppLifecycleState(AppLifecycleState state) { // if (state == AppLifecycleState.resumed) { // _socketManager.connect( // uuid: utils.user!.username!, // ); // } // } // // }