25-7-28-2
This commit is contained in:
154
lib/models/ai_query.sql
Executable file
154
lib/models/ai_query.sql
Executable file
@@ -0,0 +1,154 @@
|
||||
-- Retrieving data for a specific passenger complaint:
|
||||
SELECT
|
||||
c.id AS complaint_id,
|
||||
r.id AS ride_id,
|
||||
p.id AS passenger_id,
|
||||
p.first_name,
|
||||
p.last_name,
|
||||
p.phone,
|
||||
p.email,
|
||||
c.complaint_type,
|
||||
c.description,
|
||||
c.date_filed,
|
||||
c.statusComplaint AS complaint_status,
|
||||
c.resolution,
|
||||
c.date_resolved
|
||||
FROM
|
||||
complaint c
|
||||
JOIN ride r ON
|
||||
c.ride_id = r.id
|
||||
JOIN `passengers` p ON
|
||||
c.passenger_id = p.id
|
||||
WHERE
|
||||
c.complaint_type = 'Passenger' AND c.passenger_id = '100393163265770158312';
|
||||
|
||||
-- Admin panel dashboard
|
||||
SELECT
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`email`)
|
||||
FROM
|
||||
`passengers`
|
||||
), 0) AS countPassengers,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`email`)
|
||||
FROM
|
||||
`driver`
|
||||
), 0) AS countDriver,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`ride`
|
||||
), 0) AS countRide,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`passengers`
|
||||
WHERE
|
||||
`passengers`.`created_at` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS countPassengersThisMonth,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`ride`
|
||||
WHERE
|
||||
`ride`.`created_at` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS countRideThisMonth,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`driver`
|
||||
WHERE
|
||||
`driver`.`created_at` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS countDriverThisMonth,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`CarRegistration`
|
||||
WHERE
|
||||
`CarRegistration`.`created_at` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS countCarRegistrationThisMonth,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`complaint`
|
||||
WHERE
|
||||
`complaint`.`date_filed` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS countComplaintThisMonth,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`complaint`
|
||||
WHERE
|
||||
`complaint`.`date_filed` BETWEEN DATE_FORMAT(
|
||||
DATE_SUB(
|
||||
CURRENT_DATE,
|
||||
INTERVAL WEEKDAY(CURRENT_DATE) DAY
|
||||
),
|
||||
'%Y-%m-%d'
|
||||
) AND DATE_FORMAT(
|
||||
DATE_ADD(
|
||||
DATE_SUB(
|
||||
CURRENT_DATE,
|
||||
INTERVAL WEEKDAY(CURRENT_DATE) DAY
|
||||
),
|
||||
INTERVAL 6 DAY
|
||||
),
|
||||
'%Y-%m-%d'
|
||||
)
|
||||
), 0) AS countComplaintThisWeek,
|
||||
COALESCE((
|
||||
SELECT
|
||||
COUNT(`id`)
|
||||
FROM
|
||||
`complaint`
|
||||
WHERE
|
||||
`complaint`.`date_filed` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-%d') AND DATE_FORMAT(CURRENT_DATE, '%Y-%m-%d')
|
||||
), 0) AS countComplaintToday,
|
||||
COALESCE((
|
||||
SELECT
|
||||
SUM(`payments`.`amount`)
|
||||
FROM
|
||||
`payments`
|
||||
WHERE
|
||||
`payments`.`created_at` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
AND
|
||||
`payments`.`payment_method` IN('visa-in', 'visa', 'visaRide', 'TransferFrom', 'payout', 'TransferTo')
|
||||
), 0) AS payments,
|
||||
COALESCE((
|
||||
SELECT
|
||||
SUM(`driverWallet`.`amount`)
|
||||
FROM
|
||||
`driverWallet`
|
||||
WHERE
|
||||
`driverWallet`.`dateCreated` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
AND
|
||||
`driverWallet`.`paymentMethod` IN('visa', '')
|
||||
), 0) AS driverWallet,
|
||||
COALESCE((
|
||||
SELECT
|
||||
SUM(`passengerWallet`.`balance`)
|
||||
FROM
|
||||
`passengerWallet`
|
||||
WHERE
|
||||
`passengerWallet`.`created_at` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS passengerWallet,
|
||||
COALESCE((
|
||||
SELECT
|
||||
SUM(`seferWallet`.`amount`)
|
||||
FROM
|
||||
`seferWallet`
|
||||
WHERE
|
||||
`seferWallet`.`createdAt` BETWEEN DATE_FORMAT(CURRENT_DATE, '%Y-%m-01') AND LAST_DAY(CURRENT_DATE)
|
||||
), 0) AS seferWallet
|
||||
FROM
|
||||
`passengers`
|
||||
LIMIT 1;
|
||||
171
lib/models/db_sql.dart
Executable file
171
lib/models/db_sql.dart
Executable file
@@ -0,0 +1,171 @@
|
||||
import 'package:sefer_driver/constant/table_names.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path/path.dart';
|
||||
|
||||
class DbSql {
|
||||
static final DbSql instance = DbSql._();
|
||||
|
||||
static Database? _database;
|
||||
|
||||
DbSql._();
|
||||
|
||||
Future<Database> get database async {
|
||||
if (_database != null) return _database!;
|
||||
_database = await _initDatabase();
|
||||
return _database!;
|
||||
}
|
||||
|
||||
Future<Database> _initDatabase() async {
|
||||
String path = join(await getDatabasesPath(), 'my_database.db');
|
||||
return await openDatabase(
|
||||
path,
|
||||
version: 3,
|
||||
onCreate: (db, version) async => await _createTables(db),
|
||||
onUpgrade: (db, oldVersion, newVersion) async => await _createTables(db),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _createTables(Database db) async {
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.carLocations}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
driver_id TEXT,
|
||||
latitude REAL,
|
||||
longitude REAL,
|
||||
created_at TEXT,
|
||||
updated_at TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.placesFavorite}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
latitude REAL,
|
||||
longitude REAL,
|
||||
name TEXT UNIQUE,
|
||||
rate TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.recentLocations}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
latitude REAL,
|
||||
longitude REAL,
|
||||
name TEXT ,
|
||||
rate TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.driverOrdersRefuse}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
order_id TEXT UNIQUE,
|
||||
created_at TEXT,
|
||||
driver_id TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.rideLocation}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
order_id TEXT ,
|
||||
created_at TEXT,
|
||||
lat TEXT,
|
||||
lng TEXT
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.faceDetectTimes}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
faceDetectTimes INTEGER
|
||||
)
|
||||
''');
|
||||
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.behavior} (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
driver_id TEXT,
|
||||
latitude REAL,
|
||||
longitude REAL,
|
||||
acceleration REAL,
|
||||
created_at TEXT,
|
||||
updated_at TEXT
|
||||
);
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.captainNotification}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
faceDetectTimes INTEGER
|
||||
)
|
||||
''');
|
||||
await db.execute('''
|
||||
CREATE TABLE IF NOT EXISTS ${TableName.applyRideFromOverLay}(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
start_location_lat TEXT,
|
||||
start_location_lng TEXT,
|
||||
end_location_lat TEXT,
|
||||
end_location_lng TEXT,
|
||||
total_passenger TEXT,
|
||||
total_driver TEXT,
|
||||
duration_to_ride TEXT,
|
||||
distance TEXT,
|
||||
driver_id TEXT,
|
||||
passenger_id TEXT,
|
||||
passenger_name TEXT,
|
||||
passenger_token_fcm TEXT,
|
||||
passenger_phone TEXT,
|
||||
duration_by_passenger TEXT,
|
||||
distance_by_passenger TEXT,
|
||||
is_wallet_checked TEXT,
|
||||
driver_token TEXT,
|
||||
duration_to_passenger TEXT,
|
||||
ride_id TEXT,
|
||||
ride_timer_begin TEXT,
|
||||
driver_id_duplicate TEXT,
|
||||
duration_to_ride_duplicate TEXT,
|
||||
way_points TEXT,
|
||||
place_coordinate_0 TEXT,
|
||||
place_coordinate_1 TEXT,
|
||||
place_coordinate_2 TEXT,
|
||||
place_coordinate_3 TEXT,
|
||||
place_coordinate_4 TEXT,
|
||||
cost_for_driver TEXT,
|
||||
passenger_wallet_total TEXT,
|
||||
passenger_email TEXT,
|
||||
start_name_address TEXT,
|
||||
end_name_address TEXT,
|
||||
car_type TEXT,
|
||||
kazan TEXT,
|
||||
passenger_rate TEXT
|
||||
)
|
||||
''');
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getAllData(String table) async {
|
||||
Database db = await instance.database;
|
||||
return await db.query(table);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getCustomQuery(String query) async {
|
||||
Database db = await instance.database;
|
||||
return await db.rawQuery(query);
|
||||
}
|
||||
|
||||
Future<int> insertData(Map<String, dynamic> map, String table) async {
|
||||
Database db = await instance.database;
|
||||
return await db.insert(table, map);
|
||||
}
|
||||
|
||||
Future<int> updateData(Map<String, dynamic> map, String table, int id) async {
|
||||
Database db = await instance.database;
|
||||
|
||||
return await db.update(table, map, where: 'id = ?', whereArgs: [id]);
|
||||
}
|
||||
|
||||
Future<int> deleteData(String table, int id) async {
|
||||
Database db = await instance.database;
|
||||
return await db.delete(table, where: 'id = ?', whereArgs: [id]);
|
||||
}
|
||||
|
||||
Future<int> deleteAllData(String table) async {
|
||||
Database db = await instance.database;
|
||||
return await db.delete(table);
|
||||
}
|
||||
}
|
||||
21
lib/models/model/admin/monthly_ride.dart
Executable file
21
lib/models/model/admin/monthly_ride.dart
Executable file
@@ -0,0 +1,21 @@
|
||||
class MonthlyDataModel {
|
||||
final int year;
|
||||
final int month;
|
||||
final int day;
|
||||
final int ridesCount;
|
||||
|
||||
MonthlyDataModel({
|
||||
required this.year,
|
||||
required this.month,
|
||||
required this.day,
|
||||
required this.ridesCount,
|
||||
});
|
||||
|
||||
factory MonthlyDataModel.fromJson(Map<String, dynamic> json) =>
|
||||
MonthlyDataModel(
|
||||
year: json['year'] as int,
|
||||
month: json['month'] as int,
|
||||
day: json['day'] as int,
|
||||
ridesCount: json['rides_count'] as int,
|
||||
);
|
||||
}
|
||||
79
lib/models/model/admin/passenger_model.dart
Executable file
79
lib/models/model/admin/passenger_model.dart
Executable file
@@ -0,0 +1,79 @@
|
||||
class Passenger {
|
||||
String id;
|
||||
String phone;
|
||||
String email;
|
||||
String gender;
|
||||
String status;
|
||||
String birthdate;
|
||||
String site;
|
||||
String firstName;
|
||||
String lastName;
|
||||
String sosPhone;
|
||||
String education;
|
||||
String employmentType;
|
||||
String maritalStatus;
|
||||
String createdAt;
|
||||
String updatedAt;
|
||||
int countPassenger;
|
||||
int countFeedback;
|
||||
double ratingPassenger;
|
||||
int countDriverRate;
|
||||
int countPassengerCancel;
|
||||
double passengerAverageRating;
|
||||
int countPassengerRate;
|
||||
int countPassengerRide;
|
||||
|
||||
Passenger({
|
||||
required this.id,
|
||||
required this.phone,
|
||||
required this.email,
|
||||
required this.gender,
|
||||
required this.status,
|
||||
required this.birthdate,
|
||||
required this.site,
|
||||
required this.firstName,
|
||||
required this.lastName,
|
||||
required this.sosPhone,
|
||||
required this.education,
|
||||
required this.employmentType,
|
||||
required this.maritalStatus,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.countPassenger,
|
||||
required this.countFeedback,
|
||||
required this.ratingPassenger,
|
||||
required this.countDriverRate,
|
||||
required this.countPassengerCancel,
|
||||
required this.passengerAverageRating,
|
||||
required this.countPassengerRate,
|
||||
required this.countPassengerRide,
|
||||
});
|
||||
|
||||
factory Passenger.fromJson(Map<String, dynamic> json) {
|
||||
return Passenger(
|
||||
id: json['id'],
|
||||
phone: json['phone'],
|
||||
email: json['email'],
|
||||
gender: json['gender'],
|
||||
status: json['status'],
|
||||
birthdate: json['birthdate'],
|
||||
site: json['site'],
|
||||
firstName: json['first_name'],
|
||||
lastName: json['last_name'],
|
||||
sosPhone: json['sosPhone'],
|
||||
education: json['education'],
|
||||
employmentType: json['employmentType'],
|
||||
maritalStatus: json['maritalStatus'],
|
||||
createdAt: json['created_at'],
|
||||
updatedAt: json['updated_at'],
|
||||
countPassenger: json['countPassenger'],
|
||||
countFeedback: json['countFeedback'],
|
||||
ratingPassenger: json['ratingPassenger'].toDouble(),
|
||||
countDriverRate: json['countDriverRate'],
|
||||
countPassengerCancel: json['countPassengerCancel'],
|
||||
passengerAverageRating: json['passengerAverageRating'].toDouble(),
|
||||
countPassengerRate: json['countPassengerRate'],
|
||||
countPassengerRide: json['countPassengerRide'],
|
||||
);
|
||||
}
|
||||
}
|
||||
43
lib/models/model/driver/rides_summary_model.dart
Executable file
43
lib/models/model/driver/rides_summary_model.dart
Executable file
@@ -0,0 +1,43 @@
|
||||
class MonthlyDataModel {
|
||||
int day;
|
||||
int totalDuration;
|
||||
|
||||
MonthlyDataModel({required this.day, required this.totalDuration});
|
||||
|
||||
factory MonthlyDataModel.fromJson(Map<String, dynamic> json) =>
|
||||
MonthlyDataModel(
|
||||
day: int.parse(json['day'].toString().split('-')[2]),
|
||||
totalDuration:
|
||||
int.parse(json['total_duration'].toString().split(':')[0]));
|
||||
}
|
||||
|
||||
class MonthlyRideModel {
|
||||
int day;
|
||||
int countRide;
|
||||
int totalCount;
|
||||
|
||||
MonthlyRideModel(
|
||||
{required this.day, required this.countRide, required this.totalCount});
|
||||
|
||||
factory MonthlyRideModel.fromJson(Map<String, dynamic> json) =>
|
||||
MonthlyRideModel(
|
||||
day: int.parse(json['day'].toString().split('-')[2]),
|
||||
countRide: int.parse(json['countRide'].toString()),
|
||||
totalCount: int.parse(json['totalCount'].toString()),
|
||||
);
|
||||
}
|
||||
|
||||
class MonthlyPriceDriverModel {
|
||||
int day;
|
||||
// int price;
|
||||
double pricePerDay;
|
||||
|
||||
MonthlyPriceDriverModel({required this.day, required this.pricePerDay});
|
||||
|
||||
factory MonthlyPriceDriverModel.fromJson(Map<String, dynamic> json) =>
|
||||
MonthlyPriceDriverModel(
|
||||
day: int.parse(json['day'].toString().split('-')[2]),
|
||||
// price: int.parse(json['price'].toString()),
|
||||
pricePerDay: double.parse(json['pricePerDay'].toString()),
|
||||
);
|
||||
}
|
||||
34
lib/models/model/locations.dart
Executable file
34
lib/models/model/locations.dart
Executable file
@@ -0,0 +1,34 @@
|
||||
class CarLocationModel {
|
||||
String id;
|
||||
String driverId;
|
||||
double latitude;
|
||||
double heading;
|
||||
double speed;
|
||||
double longitude;
|
||||
DateTime createdAt;
|
||||
DateTime updatedAt;
|
||||
|
||||
CarLocationModel({
|
||||
required this.id,
|
||||
required this.driverId,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
required this.heading,
|
||||
required this.speed,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
});
|
||||
|
||||
factory CarLocationModel.fromJson(Map<String, dynamic> json) {
|
||||
return CarLocationModel(
|
||||
id: json['id'],
|
||||
driverId: json['driver_id'],
|
||||
latitude: double.parse(json['latitude'].toString()),
|
||||
longitude: double.parse(json['longitude'].toString()),
|
||||
heading: double.parse(json['heading'].toString()),
|
||||
speed: double.parse(json['speed'].toString()),
|
||||
createdAt: DateTime.parse(json['created_at']),
|
||||
updatedAt: DateTime.parse(json['updated_at']),
|
||||
);
|
||||
}
|
||||
}
|
||||
30
lib/models/model/onboarding_model.dart
Executable file
30
lib/models/model/onboarding_model.dart
Executable file
@@ -0,0 +1,30 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
List<OnBoardingModel> onBoardingList = [
|
||||
OnBoardingModel(
|
||||
title: 'Welcome to Intaleq!'.tr,
|
||||
image: 'assets/images/on1.png',
|
||||
body:
|
||||
'Intaleq is the ride-hailing app that is safe, reliable, and accessible.'
|
||||
.tr,
|
||||
),
|
||||
OnBoardingModel(
|
||||
title: 'Get to your destination quickly and easily.'.tr,
|
||||
image: 'assets/images/on2.png',
|
||||
body: 'With Intaleq, you can get a ride to your destination in minutes.'.tr,
|
||||
),
|
||||
OnBoardingModel(
|
||||
title: 'Enjoy a safe and comfortable ride.'.tr,
|
||||
image: 'assets/images/on3.png',
|
||||
body:
|
||||
'Intaleq is committed to safety, and all of our captains are carefully screened and background checked.'
|
||||
.tr,
|
||||
),
|
||||
];
|
||||
|
||||
class OnBoardingModel {
|
||||
final String? title;
|
||||
final String? image;
|
||||
final String? body;
|
||||
OnBoardingModel({this.body, this.title, this.image});
|
||||
}
|
||||
185
lib/models/model/order_data.dart
Executable file
185
lib/models/model/order_data.dart
Executable file
@@ -0,0 +1,185 @@
|
||||
// lib/models/model/order_data.dart
|
||||
|
||||
class OrderData {
|
||||
final String customerName;
|
||||
final String customerToken;
|
||||
final double tripDistanceKm; // The total trip distance in kilometers
|
||||
final String price;
|
||||
final String startLocationAddress;
|
||||
final String endLocationAddress;
|
||||
|
||||
final double
|
||||
distanceToPassengerKm; // The distance to the passenger in kilometers
|
||||
final int tripDurationMinutes; // Total trip duration in minutes (rounded up)
|
||||
final int
|
||||
durationToPassengerMinutes; // Duration to reach the passenger in minutes (rounded up)
|
||||
|
||||
final String rideType;
|
||||
final String orderId;
|
||||
final String passengerId;
|
||||
final String passengerRate;
|
||||
|
||||
final String? rawStartCoordinates;
|
||||
final String? rawEndCoordinates;
|
||||
|
||||
OrderData({
|
||||
required this.customerName,
|
||||
required this.customerToken,
|
||||
required this.tripDistanceKm,
|
||||
required this.price,
|
||||
required this.startLocationAddress,
|
||||
required this.endLocationAddress,
|
||||
required this.distanceToPassengerKm,
|
||||
required this.tripDurationMinutes,
|
||||
required this.durationToPassengerMinutes,
|
||||
required this.rideType,
|
||||
required this.orderId,
|
||||
required this.passengerId,
|
||||
required this.passengerRate,
|
||||
this.rawStartCoordinates,
|
||||
this.rawEndCoordinates,
|
||||
});
|
||||
|
||||
// --- NEW: Factory constructor to create an instance from a Map ---
|
||||
// This is the missing method that was causing the error.
|
||||
factory OrderData.fromMap(Map<String, dynamic> map) {
|
||||
return OrderData(
|
||||
// For strings, provide a default value in case the map key is null
|
||||
customerName: map['customerName']?.toString() ?? 'Unknown Customer',
|
||||
customerToken: map['customerToken']?.toString() ?? 'Unknown token',
|
||||
|
||||
// For numbers, cast from 'num' to handle both int and double, with a default value
|
||||
tripDistanceKm: (map['tripDistanceKm'] as num?)?.toDouble() ?? 0.0,
|
||||
|
||||
price: map['price']?.toString() ?? '0',
|
||||
startLocationAddress:
|
||||
map['startLocationAddress']?.toString() ?? 'Unknown Address',
|
||||
endLocationAddress:
|
||||
map['endLocationAddress']?.toString() ?? 'Unknown Address',
|
||||
|
||||
distanceToPassengerKm:
|
||||
(map['distanceToPassengerKm'] as num?)?.toDouble() ?? 0.0,
|
||||
|
||||
tripDurationMinutes: (map['tripDurationMinutes'] as num?)?.toInt() ?? 0,
|
||||
durationToPassengerMinutes:
|
||||
(map['durationToPassengerMinutes'] as num?)?.toInt() ?? 0,
|
||||
|
||||
rideType: map['rideType']?.toString() ?? 'Unknown',
|
||||
orderId: map['orderId']?.toString() ?? 'N/A',
|
||||
passengerId: map['passengerId']?.toString() ?? 'N/A',
|
||||
passengerRate: map['passengerRate']?.toString() ?? 'N/A',
|
||||
|
||||
// For nullable strings, direct access is fine as it returns null if the key doesn't exist
|
||||
rawStartCoordinates: map['rawStartCoordinates'],
|
||||
rawEndCoordinates: map['rawEndCoordinates'],
|
||||
);
|
||||
}
|
||||
|
||||
// A helper function to convert seconds to rounded-up minutes
|
||||
static int _secondsToRoundedUpMinutes(String secondsString) {
|
||||
final seconds = double.tryParse(secondsString) ?? 0.0;
|
||||
if (seconds <= 0) return 0;
|
||||
return (seconds / 60)
|
||||
.ceil(); // .ceil() rounds up (e.g., 0.1 minutes becomes 1 minute)
|
||||
}
|
||||
|
||||
// Your existing factory for creating an instance from a List
|
||||
factory OrderData.fromList(List<dynamic> list) {
|
||||
double distanceToPassengerMeters =
|
||||
list.length > 12 ? (double.tryParse(list[12].toString()) ?? 0.0) : 0.0;
|
||||
|
||||
return OrderData(
|
||||
customerName: list.length > 8 ? list[8].toString() : 'Unknown Customer',
|
||||
customerToken: list.length > 9 ? list[9].toString() : 'Unknown token',
|
||||
tripDistanceKm:
|
||||
list.length > 5 ? (double.tryParse(list[5].toString()) ?? 0.0) : 0.0,
|
||||
price: list.length > 2 ? list[2].toString().split('.')[0] : '0',
|
||||
startLocationAddress:
|
||||
list.length > 29 ? list[29].toString() : 'Unknown Address',
|
||||
endLocationAddress:
|
||||
list.length > 30 ? list[30].toString() : 'Unknown Address',
|
||||
|
||||
distanceToPassengerKm:
|
||||
distanceToPassengerMeters / 1000.0, // Convert meters to kilometers
|
||||
|
||||
tripDurationMinutes:
|
||||
list.length > 4 ? _secondsToRoundedUpMinutes(list[4].toString()) : 0,
|
||||
durationToPassengerMinutes: list.length > 15
|
||||
? _secondsToRoundedUpMinutes(list[15].toString())
|
||||
: 0,
|
||||
|
||||
rideType:
|
||||
list.length > 31 ? _getRideType(list[31].toString()) : 'Unknown',
|
||||
orderId: list.length > 16 ? list[16].toString() : 'N/A',
|
||||
passengerId: list.length > 7 ? list[7].toString() : 'N/A',
|
||||
passengerRate: list.length > 33 ? list[33].toString() : 'N/A',
|
||||
|
||||
rawStartCoordinates: list.isNotEmpty ? list[0].toString() : null,
|
||||
rawEndCoordinates: list.length > 1 ? list[1].toString() : null,
|
||||
);
|
||||
}
|
||||
|
||||
static String _getRideType(String type) {
|
||||
switch (type) {
|
||||
case 'Comfort':
|
||||
return 'كمفورت ❄️';
|
||||
case 'Lady':
|
||||
return 'ليدي 👩';
|
||||
case 'Speed':
|
||||
return 'سبيد 🔻';
|
||||
case 'Mashwari':
|
||||
return 'مشواري';
|
||||
case 'Rayeh Gai':
|
||||
return 'رايح جاي';
|
||||
default:
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
// Getter to parse start coordinates
|
||||
Map<String, double?>? get startCoordinates {
|
||||
if (rawStartCoordinates == null) return null;
|
||||
final parts = rawStartCoordinates!.split(',');
|
||||
if (parts.length == 2) {
|
||||
return {
|
||||
'lat': double.tryParse(parts[0].trim()),
|
||||
'lng': double.tryParse(parts[1].trim())
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Getter to parse end coordinates
|
||||
Map<String, double?>? get endCoordinates {
|
||||
if (rawEndCoordinates == null) return null;
|
||||
final parts = rawEndCoordinates!.split(',');
|
||||
if (parts.length == 2) {
|
||||
return {
|
||||
'lat': double.tryParse(parts[0].trim()),
|
||||
'lng': double.tryParse(parts[1].trim())
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Your existing method to convert the object TO a Map.
|
||||
// This is used to pass the data from the overlay to the main app.
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'customerName': customerName,
|
||||
'tripDistanceKm': tripDistanceKm,
|
||||
'price': price,
|
||||
'startLocationAddress': startLocationAddress,
|
||||
'endLocationAddress': endLocationAddress,
|
||||
'distanceToPassengerKm': distanceToPassengerKm,
|
||||
'tripDurationMinutes': tripDurationMinutes,
|
||||
'durationToPassengerMinutes': durationToPassengerMinutes,
|
||||
'rideType': rideType,
|
||||
'orderId': orderId,
|
||||
'passengerId': passengerId,
|
||||
'passengerRate': passengerRate,
|
||||
'rawStartCoordinates': rawStartCoordinates,
|
||||
'rawEndCoordinates': rawEndCoordinates,
|
||||
};
|
||||
}
|
||||
}
|
||||
13
lib/models/overlay_service.dart
Normal file
13
lib/models/overlay_service.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class OverlayMethodChannel {
|
||||
static const _channel = MethodChannel('com.sefer_driver/app_control');
|
||||
|
||||
static Future<void> bringToForeground() async {
|
||||
try {
|
||||
await _channel.invokeMethod('bringToForeground');
|
||||
} on PlatformException catch (e) {
|
||||
print('Error bringing app to foreground: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user