This commit is contained in:
Hamza-Ayed
2025-08-06 01:10:52 +03:00
parent 57b7574657
commit 441385069c
49 changed files with 2577 additions and 1822 deletions

View File

@@ -0,0 +1,248 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:fl_chart/fl_chart.dart';
import '../../../../controller/functions/device_analyzer.dart';
// --- CompatibilityDetailCard Widget (Updated to use 'max_score') ---
class CompatibilityDetailCard extends StatelessWidget {
final Map<String, dynamic> detail;
const CompatibilityDetailCard({super.key, required this.detail});
Color _getStatusColor(bool status, int achieved, int max) {
if (!status) return Colors.red.shade400;
if (achieved < max) return Colors.orange.shade600;
return Colors.teal;
}
IconData _getIconForLabel(String label) {
if (label.contains('رام')) return Icons.memory;
if (label.contains('معالج') || label.contains('CPU')) {
return Icons.developer_board;
}
if (label.contains('تخزين') || label.contains('كتابة')) {
return Icons.sd_storage_outlined;
}
if (label.contains('أندرويد')) return Icons.android;
if (label.contains('خدمات')) return Icons.g_mobiledata;
if (label.contains('حساسات') || label.contains('Gyroscope')) {
return Icons.sensors;
}
return Icons.smartphone;
}
@override
Widget build(BuildContext context) {
final bool status = detail['status'] ?? false;
final String label = detail['label'] ?? "";
final int achievedScore = detail['achieved_score'] ?? 0;
// Corrected to use 'max_score' from the analyzer
final int maxScore = detail['max_score'] ?? 1;
final Color color = _getStatusColor(status, achievedScore, maxScore);
final double progress =
(maxScore > 0) ? (achievedScore / maxScore).clamp(0.0, 1.0) : 0.0;
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 7),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.08),
blurRadius: 15,
offset: const Offset(0, 5),
)
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(_getIconForLabel(label),
color: Colors.grey.shade600, size: 20),
const SizedBox(width: 8),
Expanded(
child: Text(
label,
style: TextStyle(
fontSize: 15,
color: Colors.grey.shade800,
fontWeight: FontWeight.w600),
),
),
// Corrected to display points out of max_score
Text(
"$achievedScore/$maxScore نقطة",
style: TextStyle(
color: color, fontWeight: FontWeight.bold, fontSize: 14),
),
],
),
const SizedBox(height: 12),
LinearProgressIndicator(
value: progress,
backgroundColor: Colors.grey.shade200,
color: color,
minHeight: 6,
borderRadius: BorderRadius.circular(3),
),
],
),
);
}
}
// --- Main Page Widget ---
class DeviceCompatibilityPage extends StatefulWidget {
const DeviceCompatibilityPage({super.key});
@override
State<DeviceCompatibilityPage> createState() =>
_DeviceCompatibilityPageState();
}
class _DeviceCompatibilityPageState extends State<DeviceCompatibilityPage> {
int score = 0;
List<Map<String, dynamic>> details = [];
bool isLoading = true;
@override
void initState() {
super.initState();
_initializePage();
}
Future<void> _initializePage() async {
// await BatteryNotifier.checkBatteryAndNotify();
final result = await DeviceAnalyzer().analyzeDevice();
if (mounted) {
setState(() {
score = result['score'];
details = List<Map<String, dynamic>>.from(result['details']);
isLoading = false;
});
}
}
Color _getColorForScore(int value) {
if (value >= 80) return Colors.teal;
if (value >= 60) return Colors.orange.shade700;
return Colors.red.shade600;
}
String _getScoreMessage(int value) {
if (value >= 80) return "جهازك يقدم أداءً ممتازاً";
if (value >= 60) return "جهازك جيد ومناسب جداً";
if (value >= 40) return "متوافق، قد تلاحظ بعض البطء";
return "قد لا يعمل التطبيق بالشكل الأمثل";
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF7F8FC),
appBar: AppBar(
title: const Text("توافق الجهاز",
style:
TextStyle(color: Colors.black87, fontWeight: FontWeight.bold)),
centerTitle: true,
backgroundColor: Colors.transparent,
elevation: 0,
iconTheme: const IconThemeData(color: Colors.black87),
),
body: isLoading
? const Center(child: CircularProgressIndicator(color: Colors.teal))
: Column(
children: [
_buildScoreHeader(),
Expanded(
child: ListView.builder(
padding: const EdgeInsets.only(top: 10, bottom: 20),
itemCount: details.length,
itemBuilder: (context, i) =>
CompatibilityDetailCard(detail: details[i]),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
minimumSize: const Size(double.infinity, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12)),
elevation: 0,
),
onPressed: () => Get.back(),
child: const Text("المتابعة إلى التطبيق",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.white)),
),
),
],
),
);
}
/// ## Corrected Score Header Widget
/// This widget now uses a `Stack` to correctly place the text over the `PieChart`.
Widget _buildScoreHeader() {
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
height: 220, // Give the container a fixed height
child: Stack(
alignment: Alignment.center,
children: [
// Layer 1: The Pie Chart
PieChart(
PieChartData(
sectionsSpace: 4,
// This creates the "hole" in the middle.
centerSpaceRadius: 80,
startDegreeOffset: -90,
sections: [
PieChartSectionData(
color: _getColorForScore(score),
value: score.toDouble(),
title: '',
radius: 25,
),
PieChartSectionData(
color: Colors.grey.shade200,
value: (100 - score).toDouble().clamp(0, 100),
title: '',
radius: 25,
),
],
),
),
// Layer 2: The text and message, centered on top of the chart
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"$score%",
style: TextStyle(
fontSize: 52,
fontWeight: FontWeight.bold,
color: _getColorForScore(score)),
),
const SizedBox(height: 4),
Text(
_getScoreMessage(score),
style: TextStyle(
color: Colors.grey.shade700,
fontSize: 16,
fontWeight: FontWeight.w500),
),
],
),
],
),
);
}
}

View File

@@ -1,3 +1,5 @@
import 'dart:io';
import 'package:sefer_driver/constant/links.dart';
import 'package:sefer_driver/constant/style.dart';
import 'package:sefer_driver/controller/home/captin/home_captain_controller.dart';
@@ -25,6 +27,8 @@ import '../assurance_health_page.dart';
import '../maintain_center_page.dart';
import 'package:flutter/cupertino.dart';
import 'device_compatibility_page.dart';
// class CupertinoDrawerCaptain extends StatelessWidget {
// final ImageController imageController = Get.put(ImageController());
@@ -363,10 +367,17 @@ class CupertinoDrawerCaptain extends StatelessWidget {
onTap: () => Get.to(() => RatingScreen()),
),
_buildDrawerItem(
icon: CupertinoIcons.settings_solid,
text: 'Settings'.tr,
onTap: () => Get.to(() => const SettingsCaptain()),
icon: Icons.memory,
text: 'Is device compatible'.tr,
onTap: () => Get.to(() => const DeviceCompatibilityPage()),
),
Platform.isAndroid
? _buildDrawerItem(
icon: CupertinoIcons.settings_solid,
text: 'Settings'.tr,
onTap: () => Get.to(() => const SettingsCaptain()),
)
: SizedBox(),
_buildDrawerItem(
icon: CupertinoIcons.square_arrow_right,
text: 'Sign Out'.tr,

View File

@@ -26,6 +26,86 @@ import 'widget/connect.dart';
import 'widget/left_menu_map_captain.dart';
import '../../../../main.dart';
// =================================================================
// STEP 1: Modify your LocationController
// =================================================================
/*
In your `location_controller.dart` file, change `myLocation` and `heading`
to be observable by adding `.obs`. This will allow other parts of your app,
like the map, to automatically react to changes.
// BEFORE:
// LatLng myLocation = LatLng(....);
// double heading = 0.0;
// AFTER:
final myLocation = const LatLng(30.0444, 31.2357).obs; // Default to Cairo or a sensible default
final heading = 0.0.obs;
// When you update these values elsewhere in your controller,
// make sure to update their `.value` property.
// e.g., myLocation.value = newLatLng;
// e.g., heading.value = newHeading;
*/
// =================================================================
// STEP 2: Modify your HomeCaptainController
// =================================================================
/*
In your `home_captain_controller.dart` file, you need to add logic to
listen for changes from the LocationController and animate the camera.
class HomeCaptainController extends GetxController {
// ... your existing variables (mapController, carIcon, etc.)
// Make sure you have a reference to the GoogleMapController
GoogleMapController? mapHomeCaptainController;
@override
void onInit() {
super.onInit();
_setupLocationListener();
}
void onMapCreated(GoogleMapController controller) {
mapHomeCaptainController = controller;
// Any other map setup logic
}
// THIS IS THE NEW LOGIC TO ADD
void _setupLocationListener() {
final locationController = Get.find<LocationController>();
// The 'ever' worker from GetX listens for changes to an observable variable.
// Whenever `heading` or `myLocation` changes, it will call our method.
ever(locationController.heading, (_) => _updateCameraPosition());
ever(locationController.myLocation, (_) => _updateCameraPosition());
}
void _updateCameraPosition() {
final locationController = Get.find<LocationController>();
if (mapHomeCaptainController != null) {
final newPosition = CameraPosition(
target: locationController.myLocation.value,
zoom: 17.5, // A bit closer for a navigation feel
tilt: 50.0, // A nice 3D perspective
bearing: locationController.heading.value, // This rotates the map
);
// Animate the camera smoothly to the new position and rotation
mapHomeCaptainController!.animateCamera(
CameraUpdate.newCameraPosition(newPosition),
);
}
}
// ... rest of your controller code
}
*/
// =================================================================
// STEP 3: Update the HomeCaptain Widget
// =================================================================
class HomeCaptain extends StatelessWidget {
HomeCaptain({super.key});
final LocationController locationController = Get.put(LocationController());
@@ -34,16 +114,12 @@ class HomeCaptain extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Get.put(OrderRequestController());
Get.put(HomeCaptainController());
// Get.put(CaptainWalletController());
WidgetsBinding.instance.addPostFrameCallback((_) async {
closeOverlayIfFound();
checkForUpdate(context);
getPermissionOverlay();
showDriverGiftClaim(context);
// getPermissionLocation1();
// await showFirstTimeOfferNotification(context);
});
return Scaffold(
appBar: AppBar(
@@ -118,14 +194,18 @@ class HomeCaptain extends StatelessWidget {
onPressed: homeCaptainController.changeMapTraffic,
),
_MapControlButton(
icon: Icons.location_on,
tooltip: 'My Location'.tr,
icon: Icons.my_location, // Changed for clarity
tooltip: 'Center on Me'.tr,
onPressed: () {
homeCaptainController.mapHomeCaptainController!
.animateCamera(CameraUpdate.newLatLng(LatLng(
Get.find<LocationController>().myLocation.latitude,
Get.find<LocationController>().myLocation.longitude,
)));
// This button now just re-centers without changing rotation
if (homeCaptainController.mapHomeCaptainController !=
null) {
homeCaptainController.mapHomeCaptainController!
.animateCamera(CameraUpdate.newLatLngZoom(
Get.find<LocationController>().myLocation,
17.5,
));
}
},
),
],
@@ -134,47 +214,57 @@ class HomeCaptain extends StatelessWidget {
const SizedBox(width: 8),
],
),
drawer:
CupertinoDrawerCaptain(), // Add this widget at the bottom of the file
drawer: CupertinoDrawerCaptain(),
body: Stack(
children: [
GetBuilder<HomeCaptainController>(builder: (homeCaptainController) {
return homeCaptainController.isLoading
// FIX: Replaced nested GetBuilder/Obx with a single GetX widget.
// GetX handles both observable (.obs) variables and standard controller updates.
GetBuilder<HomeCaptainController>(builder: (controller) {
return controller.isLoading
? const MyCircularProgressIndicator()
: GoogleMap(
onMapCreated: homeCaptainController.onMapCreated,
// cameraTargetBounds: CameraTargetBounds(controller.boundsdata),
onMapCreated: controller.onMapCreated,
minMaxZoomPreference: const MinMaxZoomPreference(6, 18),
initialCameraPosition: CameraPosition(
// Use .value to get the latest location from the reactive variable
target: locationController.myLocation,
zoom: 15,
),
onCameraMove: (position) {
CameraPosition(
target: locationController.myLocation,
zoom: 17.5, // A bit closer for a navigation feel
tilt: 50.0, // A nice 3D perspective
bearing:
locationController.heading, // This rotates the map
);
},
markers: {
Marker(
markerId: MarkerId('MyLocation'.tr),
position: locationController.myLocation,
draggable: false,
icon: homeCaptainController.carIcon,
rotation: locationController.heading)
markerId: MarkerId('MyLocation'.tr),
// Use .value for position and rotation from the reactive variable
position: locationController.myLocation,
rotation: locationController.heading,
// IMPORTANT: These two properties make the marker look
// correct when the map is tilted and rotating.
flat: true,
anchor: const Offset(0.5, 0.5),
icon: controller.carIcon,
)
},
mapType: homeCaptainController.mapType
mapType: controller.mapType
? MapType.satellite
: MapType.terrain,
myLocationButtonEnabled: true,
// liteModeEnabled: true, tiltGesturesEnabled: false,
// indoorViewEnabled: true,
trafficEnabled: homeCaptainController.mapTrafficON,
myLocationButtonEnabled: false, // Disable default button
myLocationEnabled: false, // We use our custom marker
trafficEnabled: controller.mapTrafficON,
buildingsEnabled: true,
mapToolbarEnabled: true,
myLocationEnabled: false,
// liteModeEnabled: true,
zoomControlsEnabled: false, // Cleaner UI for navigation
);
}),
// The rest of your UI remains the same...
Positioned(
bottom: 10,
right: Get.width * .1,
@@ -384,45 +474,7 @@ class HomeCaptain extends StatelessWidget {
),
),
),
), // Positioned(
// bottom: Get.height * .17,
// right: Get.width * .01,
// child: AnimatedContainer(
// duration: const Duration(microseconds: 200),
// width: Get.width * .12,
// decoration: BoxDecoration(
// color: AppColor.secondaryColor,
// border: Border.all(),
// borderRadius: BorderRadius.circular(15)),
// child: IconButton(
// onPressed: () async {
// CRUD().sendEmail(AppLink.sendEmailToPassengerForTripDetails, {
// 'startLocation': Get.find<MapDriverController>()
// .passengerLocation
// .toString(),
// 'endLocation': Get.find<MapDriverController>()
// .passengerDestination
// .toString(),
// 'name': Get.find<MapDriverController>().name.toString(),
// 'timeOfTrip':
// Get.find<MapDriverController>().timeOfOrder.toString(),
// 'fee': Get.find<MapDriverController>()
// .totalPassenger
// .toString(),
// 'duration':
// Get.find<MapDriverController>().duration.toString(),
// 'phone': Get.find<MapDriverController>().phone.toString(),
// 'email': Get.find<MapDriverController>().email.toString(),
// });
// },
// icon: const Icon(
// MaterialCommunityIcons.map_marker_radius,
// size: 45,
// color: AppColor.blueColor,
// ),
// ),
// ),
// ),
),
Positioned(
bottom: Get.height * .2,
right: 6,
@@ -438,14 +490,6 @@ class HomeCaptain extends StatelessWidget {
borderRadius: BorderRadius.circular(15)),
child: IconButton(
onPressed: () async {
// final Bubble _bubble = Bubble(showCloseButton: false);
// try {
// await _bubble.startBubbleHead(
// sendAppToBackground: false);
// } on PlatformException {
// print('Failed to call startBubbleHead');
// }
Bubble().startBubbleHead(sendAppToBackground: true);
},
icon: Image.asset(
@@ -483,8 +527,6 @@ class HomeCaptain extends StatelessWidget {
),
GetBuilder<HomeCaptainController>(
builder: (homeCaptainController) {
Log.print(
'rideStatus from home 486 : ${box.read(BoxName.rideStatus)}');
return box.read(BoxName.rideStatus) == 'Applied' ||
box.read(BoxName.rideStatus) == 'Begin'
? Positioned(
@@ -537,27 +579,13 @@ class HomeCaptain extends StatelessWidget {
),
),
leftMainMenuCaptainIcons(),
// callPage(),
// Positioned(
// top: Get.height * .2,
// // left: 20,
// // right: 20,
// bottom: Get.height * .4,
// child: IconButton(
// onPressed: () {
// homeCaptainController.getCountRideToday();
// },
// icon: const Icon(Icons.call),
// ),
// ),
],
),
);
}
}
// These helper widgets and functions remain unchanged
showFirstTimeOfferNotification(BuildContext context) async {
bool isFirstTime = _checkIfFirstTime();

View File

@@ -1,6 +1,7 @@
import 'package:sefer_driver/constant/box_name.dart';
import 'package:sefer_driver/controller/firebase/local_notification.dart';
import 'package:sefer_driver/main.dart';
import 'package:sefer_driver/views/auth/login_page.dart';
import 'package:sefer_driver/views/home/Captin/driver_map_page.dart';
import 'package:sefer_driver/views/home/Captin/orderCaptin/vip_order_page.dart';
import 'package:flutter/material.dart';
@@ -148,6 +149,9 @@ GetBuilder<HomeCaptainController> leftMainMenuCaptainIcons() {
// child: Builder(builder: (context) {
// return IconButton(
// onPressed: () async {
// Get.to(
// () => LoginPage(),
// );
// },
// icon: const Icon(
// FontAwesome5.grin_tears,

View File

@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import '../../../../constant/colors.dart';
import '../../../../controller/functions/location_controller.dart';
import '../../../../controller/home/captin/map_driver_controller.dart';
@@ -36,6 +35,12 @@ class GoogleDriverMap extends StatelessWidget {
cameraTargetBounds:
CameraTargetBounds.unbounded, // Allow unrestricted movement
onCameraMove: (position) {
CameraPosition(
target: locationController.myLocation,
zoom: 13,
bearing: locationController.heading,
tilt: 40,
);
//todo
// locationController.myLocation = position.target;
//