Initial commit for Intaleq Driver

This commit is contained in:
Hamza-Ayed
2025-09-01 19:04:50 +03:00
parent 889c67a691
commit 8c7f3e3a75
46 changed files with 4300 additions and 6192 deletions

View File

@@ -1,12 +1,9 @@
import 'package:sefer_driver/views/widgets/mydialoug.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import '../../../../controller/auth/captin/history_captain.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import '../../../../controller/functions/encrypt_decrypt.dart';
import 'package:sefer_driver/views/widgets/mydialoug.dart';
class HistoryCaptain extends StatelessWidget {
const HistoryCaptain({super.key});
@@ -14,136 +11,221 @@ class HistoryCaptain extends StatelessWidget {
@override
Widget build(BuildContext context) {
Get.put(HistoryCaptainController());
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('History Page'.tr),
leading: CupertinoNavigationBarBackButton(
onPressed: () => Get.back(),
),
return Scaffold(
backgroundColor: Colors.grey[100], // A softer background color
appBar: AppBar(
title: Text('Ride History'.tr),
backgroundColor: Colors.white,
foregroundColor: Colors.black,
elevation: 1,
),
child: SafeArea(
child: GetBuilder<HistoryCaptainController>(
builder: (historyCaptainController) => historyCaptainController
.isloading
? const Center(child: CupertinoActivityIndicator())
: historyCaptainController.historyData['message'].length < 1
? Center(
child: Text(
'No ride Yet.'.tr,
style: CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle,
body: GetBuilder<HistoryCaptainController>(
builder: (controller) {
if (controller.isloading) {
return const Center(child: CircularProgressIndicator());
}
if (controller.historyData['message'].isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.history_toggle_off,
size: 80, color: Colors.grey[400]),
const SizedBox(height: 16),
Text(
'No Rides Yet'.tr,
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(color: Colors.grey[600]),
),
],
),
);
}
// 动画: Wrap ListView with AnimationLimiter for staggered animations
return AnimationLimiter(
child: ListView.builder(
padding: const EdgeInsets.all(16.0),
itemCount: controller.historyData['message'].length,
itemBuilder: (BuildContext context, int index) {
var trip = controller.historyData['message'][index];
// 动画: Apply animation to each list item
return AnimationConfiguration.staggeredList(
position: index,
duration: const Duration(milliseconds: 375),
child: SlideAnimation(
verticalOffset: 50.0,
child: FadeInAnimation(
child: _AnimatedHistoryCard(
trip: trip,
onTap: () {
// Your original logic is preserved here
if (trip['status'] != 'Cancel') {
controller.getHistoryDetails(trip['order_id']);
} else {
MyDialog().getDialog(
'This Trip Was Cancelled'.tr,
'This Trip Was Cancelled'.tr,
() => Get.back(),
);
}
},
),
)
: ListView.builder(
itemCount: historyCaptainController
.historyData['message'].length,
itemBuilder: (BuildContext context, int index) {
var list = historyCaptainController
.historyData['message'][index];
return Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: CupertinoColors.systemGrey, width: 1),
borderRadius:
const BorderRadius.all(Radius.circular(8.0)),
),
child: CupertinoButton(
onPressed: () {
if (list['status'] != 'Cancel') {
historyCaptainController
.getHistoryDetails(list['order_id']);
} else {
MyDialog().getDialog(
'This Trip Cancelled'.tr,
'This Trip Cancelled'.tr,
() => Get.back(),
);
}
},
child: Container(
margin: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'OrderId'.tr,
style: CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle,
),
Text(
EncryptionHelper.instance
.decryptData(list['order_id']),
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
],
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'created time'.tr,
style: CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle,
),
Text(
list['created_at'],
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
],
),
Text(
list['status'],
style: EncryptionHelper.instance
.decryptData(
list['status']) ==
'Apply'
? CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle
.copyWith(
color: CupertinoColors
.systemGreen)
: EncryptionHelper.instance.decryptData(
list['status']) ==
'Refused'
? CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle
.copyWith(
color: CupertinoColors
.systemRed)
: CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle
.copyWith(
color: CupertinoColors
.systemYellow),
),
],
),
),
),
),
);
},
),
),
);
},
),
);
},
),
);
}
}
// 动画: A new stateful widget to handle the tap animation
class _AnimatedHistoryCard extends StatefulWidget {
final Map<String, dynamic> trip;
final VoidCallback onTap;
const _AnimatedHistoryCard({required this.trip, required this.onTap});
@override
__AnimatedHistoryCardState createState() => __AnimatedHistoryCardState();
}
class __AnimatedHistoryCardState extends State<_AnimatedHistoryCard>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _scaleAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 150),
);
_scaleAnimation = Tween<double>(begin: 1.0, end: 0.95).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
void _onTapDown(TapDownDetails details) {
_controller.forward();
}
void _onTapUp(TapUpDetails details) {
_controller.reverse();
widget.onTap();
}
void _onTapCancel() {
_controller.reverse();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
onTapCancel: _onTapCancel,
child: ScaleTransition(
scale: _scaleAnimation,
child: Card(
elevation: 4,
shadowColor: Colors.black.withOpacity(0.1),
margin: const EdgeInsets.only(bottom: 16.0),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Icon(Icons.receipt_long,
color: Theme.of(context).primaryColor, size: 40),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${'OrderId'.tr}: ${widget.trip['order_id']}',
style:
Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
widget.trip['created_at'],
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey[600],
),
),
],
),
),
const SizedBox(width: 16),
_buildStatusChip(widget.trip['status']),
],
),
),
),
),
);
}
}
// 🎨 A separate function for the status chip, slightly restyled for Material
Widget _buildStatusChip(String status) {
Color chipColor;
Color textColor;
String statusText = status;
IconData iconData;
switch (status) {
case 'Apply':
chipColor = Colors.green.shade50;
textColor = Colors.green.shade800;
iconData = Icons.check_circle;
break;
case 'Refused':
chipColor = Colors.red.shade50;
textColor = Colors.red.shade800;
iconData = Icons.cancel;
break;
case 'Cancel':
chipColor = Colors.orange.shade50;
textColor = Colors.orange.shade800;
iconData = Icons.info;
statusText = 'Cancelled';
break;
default:
chipColor = Colors.grey.shade200;
textColor = Colors.grey.shade800;
iconData = Icons.hourglass_empty;
}
return Chip(
avatar: Icon(iconData, color: textColor, size: 16),
label: Text(
statusText.tr,
style: TextStyle(color: textColor, fontWeight: FontWeight.w600),
),
backgroundColor: chipColor,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
side: BorderSide.none,
);
}

View File

@@ -1,252 +1,369 @@
import 'package:sefer_driver/controller/functions/location_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:sefer_driver/controller/auth/captin/history_captain.dart';
import 'package:sefer_driver/controller/functions/launch.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:flutter/cupertino.dart';
class HistoryDetailsPage extends StatefulWidget {
const HistoryDetailsPage({super.key});
import '../../../../controller/functions/encrypt_decrypt.dart';
@override
State<HistoryDetailsPage> createState() => _HistoryDetailsPageState();
}
class HistoryDetailsPage extends StatelessWidget {
HistoryDetailsPage({super.key});
HistoryCaptainController historyCaptainController =
Get.put(HistoryCaptainController());
class _HistoryDetailsPageState extends State<HistoryDetailsPage> {
// Get the controller instance
final HistoryCaptainController controller =
Get.find<HistoryCaptainController>();
// Helper method to safely parse LatLng from a string 'lat,lng'
LatLng? _parseLatLng(String? latLngString) {
if (latLngString == null) return null;
final parts = latLngString.split(',');
if (parts.length != 2) return null;
final lat = double.tryParse(parts[0]);
final lng = double.tryParse(parts[1]);
if (lat == null || lng == null) return null;
return LatLng(lat, lng);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Trip Detail'.tr),
leading: CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.back),
onPressed: () => Navigator.pop(context),
),
return Scaffold(
backgroundColor: Colors.grey[50],
appBar: AppBar(
title: Text('Trip Details'.tr),
backgroundColor: Colors.white,
elevation: 1,
),
child: GetBuilder<HistoryCaptainController>(
builder: (historyCaptainController) {
var res = historyCaptainController.historyDetailsData['data'];
return historyCaptainController.isloading
? const Center(
child: CupertinoActivityIndicator(),
)
: CupertinoScrollbar(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
height: 20,
),
CupertinoButton(
onPressed: () {
String mapUrl =
'https://www.google.com/maps/dir/${EncryptionHelper.instance.decryptData(res['start_location'])}/${EncryptionHelper.instance.decryptData(res['end_location'])}/';
showInBrowser(mapUrl);
},
child: Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: CupertinoColors.activeBlue,
width: 2),
),
child: Column(
children: [
const SizedBox(
height: 20,
),
SizedBox(
height: MediaQuery.of(context).size.height *
0.3,
child: GoogleMap(
initialCameraPosition: CameraPosition(
target: Get.find<LocationController>()
.myLocation,
tilt: 80,
zoom: 13,
),
zoomControlsEnabled: true,
polylines: {
Polyline(
polylineId: const PolylineId('route'),
points: [
LatLng(
double.parse(EncryptionHelper
.instance
.decryptData(
res['start_location'])
.toString()
.split(',')[0]),
double.parse(EncryptionHelper
.instance
.decryptData(
res['start_location'])
.toString()
.split(',')[1]),
),
LatLng(
double.parse(EncryptionHelper
.instance
.decryptData(
res['end_location'])
.toString()
.split(',')[0]),
double.parse(EncryptionHelper
.instance
.decryptData(
res['end_location'])
.toString()
.split(',')[1]),
)
],
color: CupertinoColors.activeGreen,
width: 5,
),
},
),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'${'Order ID'.tr} ${EncryptionHelper.instance.decryptData(res['id'])}',
style: CupertinoTheme.of(context)
.textTheme
.navActionTextStyle,
),
Text(
res['date'].toString(),
style: CupertinoTheme.of(context)
.textTheme
.navActionTextStyle,
),
],
),
],
),
),
),
const SizedBox(height: 20),
Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: CupertinoColors.activeGreen, width: 2),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'${'Price is'.tr} ${EncryptionHelper.instance.decryptData(res['price_for_driver'])}',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
Text(
'${'Distance is'.tr} ${EncryptionHelper.instance.decryptData(res['distance'])} KM',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
],
),
),
const SizedBox(height: 20),
Text(
'Times of Trip'.tr,
style: CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle,
),
const SizedBox(height: 10),
Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: CupertinoColors.destructiveRed,
width: 2),
),
child: Column(
children: [
Text(
'${'Time to Passenger is'.tr} ${res['DriverIsGoingToPassenger']}',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
Text(
'${'TimeStart is'.tr} ${res['rideTimeStart']}',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
Text(
'${'Time Finish is'.tr} ${res['rideTimeFinish']}',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
],
),
),
const SizedBox(height: 20),
Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: CupertinoColors.systemGreen, width: 2),
),
child: Center(
child: Text(
'${'Passenger Name is'.tr} ${EncryptionHelper.instance.decryptData(res['first_name'])} ${EncryptionHelper.instance.decryptData(res['last_name'])}',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
),
),
const SizedBox(height: 20),
Container(
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
border: Border.all(
color: CupertinoColors.systemYellow,
width: 2),
),
child: Center(
child: Text(
'${'Status is'.tr} ${EncryptionHelper.instance.decryptData(res['status'])}',
style: CupertinoTheme.of(context)
.textTheme
.textStyle,
),
),
),
],
),
body: GetBuilder<HistoryCaptainController>(
builder: (controller) {
if (controller.isloading) {
return const Center(child: CircularProgressIndicator());
}
final res = controller.historyDetailsData['data'];
if (res == null) {
return Center(child: Text('Could not load trip details.'.tr));
}
final startLocation = _parseLatLng(res['start_location']);
final endLocation = _parseLatLng(res['end_location']);
// Create markers for the map
final Set<Marker> markers = {};
if (startLocation != null) {
markers.add(Marker(
markerId: const MarkerId('start'),
position: startLocation,
infoWindow: InfoWindow(title: 'Start'.tr)));
}
if (endLocation != null) {
markers.add(Marker(
markerId: const MarkerId('end'),
position: endLocation,
infoWindow: InfoWindow(title: 'End'.tr)));
}
return AnimationLimiter(
child: ListView(
padding: const EdgeInsets.all(16.0),
children: AnimationConfiguration.toStaggeredList(
duration: const Duration(milliseconds: 375),
childAnimationBuilder: (widget) => SlideAnimation(
verticalOffset: 50.0,
child: FadeInAnimation(child: widget),
),
children: [
// --- Map Card ---
_buildMapCard(context, startLocation, endLocation, markers),
const SizedBox(height: 16),
// --- Trip Info Card ---
_DetailCard(
icon: Icons.receipt_long,
title: 'Trip Info'.tr,
child: Column(
children: [
_InfoTile(
label: 'Order ID'.tr,
value: res['id']?.toString() ?? 'N/A'),
_InfoTile(
label: 'Date'.tr,
value: res['date']?.toString() ?? 'N/A'),
],
),
),
);
// --- Earnings Card ---
_DetailCard(
icon: Icons.account_balance_wallet,
title: 'Earnings & Distance'.tr,
child: Column(
children: [
_InfoTile(
label: 'Your Earnings'.tr,
value: '${res['price_for_driver']}'),
_InfoTile(
label: 'Distance'.tr,
value: '${res['distance']} KM'),
],
),
),
// --- Timeline Card ---
_DetailCard(
icon: Icons.timeline,
title: 'Trip Timeline'.tr,
child: Column(
children: [
_InfoTile(
label: 'Time to Passenger'.tr,
value: res['DriverIsGoingToPassenger'] ?? 'N/A'),
_InfoTile(
label: 'Trip Started'.tr,
value: res['rideTimeStart'] ?? 'N/A'),
_InfoTile(
label: 'Trip Finished'.tr,
value: res['rideTimeFinish'] ?? 'N/A'),
],
),
),
// --- Passenger & Status Card ---
_DetailCard(
icon: Icons.person,
title: 'Passenger & Status'.tr,
child: Column(
children: [
_InfoTile(
label: 'Passenger Name'.tr,
value:
'${res['passengerName']} ${res['last_name']}'),
_InfoTile(
label: 'Status'.tr,
value: res['status'] ?? 'N/A',
isStatus: true),
],
),
),
],
),
),
);
},
),
);
}
Widget _buildMapCard(BuildContext context, LatLng? startLocation,
LatLng? endLocation, Set<Marker> markers) {
// A fallback position if locations are not available
final initialCameraPosition = (startLocation != null)
? CameraPosition(target: startLocation, zoom: 14)
: const CameraPosition(
target: LatLng(31.96, 35.92), zoom: 12); // Fallback to Amman
return Card(
elevation: 4,
shadowColor: Colors.black.withOpacity(0.1),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
clipBehavior:
Clip.antiAlias, // Ensures the map respects the border radius
child: Stack(
children: [
SizedBox(
height: 250,
child: GoogleMap(
initialCameraPosition: initialCameraPosition,
markers: markers,
polylines: {
if (startLocation != null && endLocation != null)
Polyline(
polylineId: const PolylineId('route'),
points: [startLocation, endLocation],
color: Colors.deepPurple,
width: 5,
),
},
onMapCreated: (GoogleMapController mapController) {
// Animate camera to fit the route
if (startLocation != null && endLocation != null) {
LatLngBounds bounds = LatLngBounds(
southwest: LatLng(
startLocation.latitude < endLocation.latitude
? startLocation.latitude
: endLocation.latitude,
startLocation.longitude < endLocation.longitude
? startLocation.longitude
: endLocation.longitude,
),
northeast: LatLng(
startLocation.latitude > endLocation.latitude
? startLocation.latitude
: endLocation.latitude,
startLocation.longitude > endLocation.longitude
? startLocation.longitude
: endLocation.longitude,
),
);
mapController.animateCamera(
CameraUpdate.newLatLngBounds(bounds, 60.0));
}
},
),
),
Positioned(
top: 10,
right: 10,
child: FloatingActionButton.small(
heroTag: 'open_maps',
onPressed: () {
if (startLocation != null && endLocation != null) {
String mapUrl =
'https://www.google.com/maps/dir/${startLocation.latitude},${startLocation.longitude}/${endLocation.latitude},${endLocation.longitude}/';
showInBrowser(mapUrl);
}
},
child: const Icon(Icons.directions),
),
),
],
),
);
}
}
// A reusable widget for the main detail cards
class _DetailCard extends StatelessWidget {
final IconData icon;
final String title;
final Widget child;
const _DetailCard({
required this.icon,
required this.title,
required this.child,
});
@override
Widget build(BuildContext context) {
return Card(
elevation: 2,
shadowColor: Colors.black.withOpacity(0.05),
margin: const EdgeInsets.only(bottom: 16.0),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, color: Theme.of(context).primaryColor),
const SizedBox(width: 8),
Text(
title,
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(fontWeight: FontWeight.bold),
),
],
),
const Divider(height: 24),
child,
],
),
),
);
}
}
// A reusable widget for a label-value pair inside a card
class _InfoTile extends StatelessWidget {
final String label;
final String value;
final bool isStatus;
const _InfoTile({
required this.label,
required this.value,
this.isStatus = false,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label,
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(color: Colors.grey[700])),
if (isStatus)
_buildStatusChip(value)
else
Flexible(
child: Text(
value,
style: Theme.of(context)
.textTheme
.titleMedium
?.copyWith(fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
],
),
);
}
}
// Reusing the status chip from the previous page for consistency
Widget _buildStatusChip(String status) {
Color chipColor;
Color textColor;
IconData iconData;
switch (status.toLowerCase()) {
case 'apply':
case 'completed': // Assuming 'Apply' means completed
chipColor = Colors.green.shade50;
textColor = Colors.green.shade800;
iconData = Icons.check_circle;
status = 'Completed';
break;
case 'refused':
chipColor = Colors.red.shade50;
textColor = Colors.red.shade800;
iconData = Icons.cancel;
break;
case 'cancel':
chipColor = Colors.orange.shade50;
textColor = Colors.orange.shade800;
iconData = Icons.info;
status = 'Cancelled';
break;
default:
chipColor = Colors.grey.shade200;
textColor = Colors.grey.shade800;
iconData = Icons.hourglass_empty;
}
return Chip(
avatar: Icon(iconData, color: textColor, size: 16),
label: Text(
status.tr,
style: TextStyle(color: textColor, fontWeight: FontWeight.w600),
),
backgroundColor: chipColor,
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
side: BorderSide.none,
);
}