This commit is contained in:
Hamza-Ayed
2024-07-08 00:27:01 +03:00
parent 0a71a194b9
commit a40c1e05e3
13 changed files with 367 additions and 75 deletions

View File

@@ -222,4 +222,8 @@ class AppLink {
static String getRidesPerMonth =
"$server/Admin/AdminRide/getRidesPerMonth.php";
static String getRidesDetails = "$server/Admin/AdminRide/get.php";
static String getPassengersStatic =
"https://api.sefer.live/sefer/serviceApp/getPassengersStatic.php";
static String getdriverstotalMonthly =
"https://api.sefer.live/sefer/serviceApp/getdriverstotalMonthly.php";
}

View File

@@ -10,6 +10,7 @@ class DashboardController extends GetxController {
bool isLoading = false;
List dashbord = [];
int creditSMS = 0;
Future getDashBoard() async {
isLoading = true;
update();
@@ -31,8 +32,9 @@ class DashboardController extends GetxController {
}
@override
void onInit() {
void onInit() async {
getDashBoard();
super.onInit();
}
}

View File

@@ -0,0 +1,79 @@
import 'dart:convert';
import 'package:fl_chart/fl_chart.dart';
import 'package:get/get.dart';
import '../../constant/links.dart';
import '../../models/model/passengers_model.dart';
import '../functions/crud.dart';
class StaticController extends GetxController {
Map<String, dynamic> jsonData1 = {};
Map<String, dynamic> jsonData2 = {};
var chartDataPassengers;
var chartDataDrivers;
bool isLoading = false;
String totalMonthlyPassengers = '';
String totalMonthlyDrivers = '';
late List<MonthlyPassengerInstall> passengersData;
late List<MonthlyDriverInstall> driversData;
Future<void> fetch() async {
isLoading = true;
update(); // Notify the observers about the loading state change
var res = await CRUD().get(
link: AppLink.getPassengersStatic,
payload: {},
);
jsonData1 = jsonDecode(res);
var jsonResponse = jsonDecode(res) as Map<String, dynamic>;
isLoading = false;
final List<dynamic> jsonData = jsonResponse['message'];
totalMonthlyPassengers = jsonData[0]['totalMonthly'].toString();
passengersData = jsonData.map<MonthlyPassengerInstall>((item) {
return MonthlyPassengerInstall.fromJson(item);
}).toList();
final List<FlSpot> spots = passengersData
.map((data) => FlSpot(
data.day.toDouble(),
data.totalPassengers.toDouble(),
))
.toList();
chartDataPassengers = spots;
update(); // Notify the observers about the data and loading state change
}
Future<void> fetchDrivers() async {
isLoading = true;
update(); // Notify the observers about the loading state change
var res = await CRUD().get(
link: AppLink.getdriverstotalMonthly,
payload: {},
);
jsonData2 = jsonDecode(res);
var jsonResponse = jsonDecode(res) as Map<String, dynamic>;
isLoading = false;
final List<dynamic> jsonData = jsonResponse['message'];
totalMonthlyDrivers = jsonData[0]['totalMonthly'].toString();
driversData = jsonData.map<MonthlyDriverInstall>((item) {
return MonthlyDriverInstall.fromJson(item);
}).toList();
final List<FlSpot> spots = driversData
.map((data) => FlSpot(
data.day.toDouble(),
data.totalDrivers.toDouble(),
))
.toList();
chartDataDrivers = spots;
update(); // Notify the observers about the data and loading state change
}
Future getAll() async {
await fetch();
await fetchDrivers();
}
}

View File

@@ -4,6 +4,7 @@ import 'package:get/get.dart';
import 'package:http/http.dart' as http;
import '../../../constant/links.dart';
import '../../constant/api_key.dart';
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
import '../../main.dart';
@@ -21,15 +22,13 @@ class PaymobPayout extends GetxController {
};
var body = {
'grant_type': 'password',
'username': 'sefer_api_checker',
'password': '#c3pSwbUxOKpQnr5hHZAgpkSW',
'client_id': 'kmNWU5gKsL8LKVhsJFbOGTEb3YQ5sQhvBoB8pqoW',
'client_secret':
'htV6nFANLDd658ueTEuMrIqwjcXsocMXmBLAYof7FuutBcSxdTdoNqFl3EAvO6zrOgGPLdiMrofNp2V9ASVRpjoSlFjDNRzY7hfPunAJEgf2N5ZUuknN4QniaqIZvaNt'
'username': AK.payMobOutUserName,
'password': AK.payMobOutPassword,
'client_id': AK.payMobOutClient_id,
'client_secret': AK.payMobOutClientSecrret
};
var res = await http.post(
Uri.parse(
'https://stagingpayouts.paymobsolutions.com/api/secure/o/token/'),
Uri.parse('https://payouts.paymobsolutions.com/api/secure/o/token/'),
headers: headers,
body: body,
);
@@ -53,8 +52,7 @@ class PaymobPayout extends GetxController {
"msisdn": msisdn, // "01023456789"
});
var res = await http.post(
Uri.parse(
'https://stagingpayouts.paymobsolutions.com/api/secure/disburse/'),
Uri.parse('https://payouts.paymobsolutions.com/api/secure/disburse/'),
headers: headers,
body: body,
);
@@ -64,7 +62,7 @@ class PaymobPayout extends GetxController {
'rideId': DateTime.now().toIso8601String(),
'amount': ((-1) * (double.parse(dec['amount'])) + 5).toStringAsFixed(0),
'payment_method': 'payout',
'passengerID': 'myself',
'passengerID': 'admin',
'driverID': box.read(BoxName.driverID).toString(),
});
Get.snackbar('Transaction successful'.tr,
@@ -94,8 +92,7 @@ class PaymobPayout extends GetxController {
};
var res = await http
.post(
Uri.parse(
'https://stagingpayouts.paymobsolutions.com/api/secure/disburse/'),
Uri.parse('https://payouts.paymobsolutions.com/api/secure/disburse/'),
headers: headers,
body: body,
)

View File

@@ -0,0 +1,25 @@
class MonthlyPassengerInstall {
int day;
int totalPassengers;
MonthlyPassengerInstall({required this.day, required this.totalPassengers});
factory MonthlyPassengerInstall.fromJson(Map<String, dynamic> json) =>
MonthlyPassengerInstall(
day: int.parse(json['day'].toString().split('-')[2]),
totalPassengers:
int.parse(json['totalPassengers'].toString().split(':')[0]));
}
class MonthlyDriverInstall {
int day;
int totalDrivers;
MonthlyDriverInstall({required this.day, required this.totalDrivers});
factory MonthlyDriverInstall.fromJson(Map<String, dynamic> json) =>
MonthlyDriverInstall(
day: int.parse(json['day'].toString().split('-')[2]),
totalDrivers:
int.parse(json['totalDrivers'].toString().split(':')[0]));
}

View File

@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/src/rx_typedefs/rx_typedefs.dart';
import 'package:sefer_admin1/constant/colors.dart';
import 'package:sefer_admin1/controller/admin/dashboard_controller.dart';
import 'package:sefer_admin1/controller/admin/static_controller.dart';
import 'package:sefer_admin1/controller/notification_controller.dart';
import 'package:sefer_admin1/views/widgets/mycircular.dart';
@@ -25,6 +27,15 @@ class AdminHomePage extends StatelessWidget {
return MyScafolld(
title: 'Admin Home Page',
action: IconButton(
onPressed: () async {
await Get.find<DashboardController>().getDashBoard();
},
icon: const Icon(
Icons.refresh,
color: AppColor.greenColor,
),
),
body: [
GetBuilder<DashboardController>(builder: (dashboardController) {
return dashboardController.dashbord.isEmpty
@@ -318,8 +329,13 @@ class AdminHomePage extends StatelessWidget {
onPressed: () => Get.to(() => Rides(),
transition: Transition.downToUp)),
AdminWidgetsDashBoard(
title: 'Static',
onPressed: () => Get.to(() => const StaticDash())),
title: 'Static',
onPressed: () async {
await Get.put(StaticController()).getAll();
Get.to(() => const StaticDash());
},
),
AdminWidgetsDashBoard(
title: 'send notification Drivers',
onPressed: () async {

View File

@@ -1,6 +1,10 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sefer_admin1/constant/style.dart';
import 'package:sefer_admin1/controller/admin/static_controller.dart';
import '../../../constant/colors.dart';
import '../../widgets/my_scafold.dart';
class StaticDash extends StatelessWidget {
@@ -8,6 +12,193 @@ class StaticDash extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MyScafolld(title: 'Static Dash'.tr, body: [], isleading: true);
Get.put(StaticController());
return MyScafolld(
title: 'Static Dash'.tr,
body: [
GetBuilder<StaticController>(builder: (staticController) {
return Column(
children: [
Container(
height: Get.height * .3,
width: double.maxFinite,
// decoration: AppStyle.boxDecoration1,
child: Padding(
padding: const EdgeInsets.all(6),
child: Container(
decoration: AppStyle.boxDecoration1,
height: MediaQuery.of(context).size.height * 0.4,
child: LineChart(
LineChartData(
lineBarsData: [
LineChartBarData(
isStepLineChart: true,
spots: staticController.chartDataPassengers,
isCurved: true,
color: Colors.deepPurpleAccent, // Custom color
barWidth: 3, // Thinner line
dotData: const FlDotData(
show: true), // Show dots on each point
belowBarData: BarAreaData(
show: true,
color: Colors.deepPurpleAccent.withOpacity(
0.3), // Custom gradient color
),
isStrokeJoinRound: true,
shadow: const BoxShadow(
color: Colors.yellow,
blurRadius: 4,
offset: Offset(2, 2),
),
),
],
showingTooltipIndicators: const [],
titlesData: FlTitlesData(
show: true,
topTitles: AxisTitles(
axisNameWidget: Text(
'Days'.tr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
axisNameSize: 30,
),
bottomTitles: AxisTitles(
axisNameWidget: Text(
'Total passengers on month ${staticController.totalMonthlyPassengers}'
.tr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
axisNameSize: 30,
sideTitles: const SideTitles(
reservedSize: 30,
showTitles: true,
),
),
leftTitles: AxisTitles(
axisNameWidget: Text(
'Counts of Passengers on days'.tr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
axisNameSize: 30,
sideTitles: const SideTitles(
reservedSize: 30,
showTitles: true,
),
),
),
gridData: const FlGridData(show: true),
borderData: FlBorderData(
show: true,
border: const Border(
bottom: BorderSide(color: Colors.blueAccent),
left: BorderSide(color: Colors.blueAccent),
),
),
),
),
),
)),
const SizedBox(
height: 5,
),
Container(
height: Get.height * .3,
width: double.maxFinite,
// decoration: AppStyle.boxDecoration1,
child: Padding(
padding: const EdgeInsets.all(6),
child: Container(
decoration: AppStyle.boxDecoration1,
height: MediaQuery.of(context).size.height * 0.4,
child: LineChart(
LineChartData(
lineBarsData: [
LineChartBarData(
isStepLineChart: true,
spots: staticController.chartDataDrivers,
isCurved: true,
color: Colors.deepPurpleAccent, // Custom color
barWidth: 3, // Thinner line
dotData: const FlDotData(
show: true), // Show dots on each point
belowBarData: BarAreaData(
show: true,
color: Colors.deepPurpleAccent.withOpacity(
0.3), // Custom gradient color
),
isStrokeJoinRound: true,
shadow: const BoxShadow(
color: Colors.yellow,
blurRadius: 4,
offset: Offset(2, 2),
),
),
],
showingTooltipIndicators: const [],
titlesData: FlTitlesData(
show: true,
topTitles: AxisTitles(
axisNameWidget: Text(
'Days'.tr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
axisNameSize: 30,
),
bottomTitles: AxisTitles(
axisNameWidget: Text(
'Total Drivers on month ${staticController.totalMonthlyDrivers}'
.tr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
axisNameSize: 30,
sideTitles: const SideTitles(
reservedSize: 30,
showTitles: true,
),
),
leftTitles: AxisTitles(
axisNameWidget: Text(
'Counts of Drivers on days'.tr,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold),
),
axisNameSize: 30,
sideTitles: const SideTitles(
reservedSize: 30,
showTitles: true,
),
),
),
gridData: const FlGridData(show: true),
borderData: FlBorderData(
show: true,
border: const Border(
bottom: BorderSide(color: Colors.blueAccent),
left: BorderSide(color: Colors.blueAccent),
),
),
),
),
),
)),
const SizedBox(
height: 5,
),
],
);
})
],
isleading: true);
}
}