import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:SEFER/constant/style.dart'; import 'package:SEFER/views/widgets/my_scafold.dart'; import 'package:SEFER/views/widgets/mycircular.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import '../../../constant/colors.dart'; import '../../../controller/functions/launch.dart'; import '../../../controller/home/profile/order_history_controller.dart'; class OrderHistory extends StatelessWidget { const OrderHistory({super.key}); @override Widget build(BuildContext context) { // Instantiate the OrderHistoryController class Get.put(OrderHistoryController()); return MyScafolld( title: 'Order History'.tr, isleading: true, body: [ GetBuilder( builder: (orderHistoryController) => orderHistoryController.isloading ? const MyCircularProgressIndicator() : orderHistoryController.orderHistoryListPassenger.isEmpty ? Center( child: Text( 'No trip yet found'.tr, style: AppStyle.headTitle2, ), ) : ListView.builder( itemCount: orderHistoryController .orderHistoryListPassenger.length, itemBuilder: (BuildContext context, int index) { // Use integer index here final rides = orderHistoryController.orderHistoryListPassenger[ index]; // Access data using index return Padding( padding: const EdgeInsets.all(8.0), child: Container( decoration: AppStyle.boxDecoration1, child: InkWell( onTap: () { String mapUrl = 'https://www.google.com/maps/dir/${rides['start_location']}/${rides['end_location']}/'; showInBrowser(mapUrl); }, child: Padding( padding: const EdgeInsets.all(8.0), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SizedBox( height: Get.height * .2, width: Get.width * .75, child: GoogleMap( initialCameraPosition: CameraPosition( target: LatLng( (double.parse( rides['start_location'] .toString() .split(',')[0]) + double.parse( rides['end_location'] .toString() .split(',')[0])) / 2, (double.parse( rides['start_location'] .toString() .split(',')[1]) + double.parse( rides['end_location'] .toString() .split(',')[1])) / 2, ), zoom: 12, ), // Dynamically calculate the correct LatLngBounds onMapCreated: (GoogleMapController controller) { final LatLng startLocation = LatLng( double.parse(rides['start_location'] .toString() .split(',')[0]), double.parse(rides['start_location'] .toString() .split(',')[1]), ); final LatLng endLocation = LatLng( double.parse(rides['end_location'] .toString() .split(',')[0]), double.parse(rides['end_location'] .toString() .split(',')[1]), ); final LatLngBounds bounds = LatLngBounds( northeast: LatLng( startLocation.latitude > endLocation.latitude ? startLocation.latitude : endLocation.latitude, startLocation.longitude > endLocation.longitude ? startLocation.longitude : endLocation.longitude, ), southwest: LatLng( startLocation.latitude < endLocation.latitude ? startLocation.latitude : endLocation.latitude, startLocation.longitude < endLocation.longitude ? startLocation.longitude : endLocation.longitude, ), ); controller.animateCamera( CameraUpdate.newLatLngBounds( bounds, 50)); }, zoomControlsEnabled: true, polylines: { Polyline( zIndex: 2, consumeTapEvents: true, geodesic: true, endCap: Cap.buttCap, startCap: Cap.buttCap, visible: true, polylineId: const PolylineId('route'), points: [ LatLng( double.parse( rides['start_location'] .toString() .split(',')[0]), double.parse( rides['start_location'] .toString() .split(',')[1]), ), LatLng( double.parse( rides['end_location'] .toString() .split(',')[0]), double.parse( rides['end_location'] .toString() .split(',')[1]), ) ], color: AppColor.primaryColor, width: 5, ), }, mapType: MapType.normal, ), ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( rides['date'], style: AppStyle.subtitle, ), Text( rides['time'], style: AppStyle.subtitle, ), Text( rides['status'], style: rides['status'] == 'Canceled'.tr ? AppStyle.subtitle.copyWith( color: AppColor.redColor) : rides['status'] == 'Finished'.tr ? AppStyle.subtitle.copyWith( color: AppColor.greenColor) : AppStyle.subtitle.copyWith( color: AppColor.yellowColor), ), Text( '${'Price is'.tr} ${rides['price']}', style: AppStyle.subtitle, ), ], ), ], ), ), ), ), ); }, ), ) ], ); } }