Files
tripz_admin/lib/views/admin/admin_home_page.dart
2026-01-21 17:31:10 +03:00

463 lines
21 KiB
Dart

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/register_captain_controller.dart';
import 'package:sefer_admin1/controller/admin/static_controller.dart';
import 'package:sefer_admin1/controller/notification_controller.dart';
import 'package:sefer_admin1/views/admin/captain/drivers_cant_registe.dart';
import 'package:sefer_admin1/views/admin/captain/register_captain.dart';
import 'package:sefer_admin1/views/admin/employee/employee_page.dart';
import 'package:sefer_admin1/views/widgets/elevated_btn.dart';
import 'package:sefer_admin1/views/widgets/my_textField.dart';
import 'package:sefer_admin1/views/widgets/mycircular.dart';
import '../../constant/links.dart';
import '../../constant/style.dart';
import '../../controller/functions/crud.dart';
import '../../controller/functions/gemeni.dart';
import '../../print.dart';
import '../widgets/my_scafold.dart';
import 'captain/captain.dart';
import 'dashboard_widget.dart';
import 'drivers/driver_the_best.dart';
import 'packages.dart';
import 'passenger/passenger.dart';
import 'rides/rides.dart';
import 'static/static.dart';
import 'wallet/wallet.dart';
class AdminHomePage extends StatelessWidget {
const AdminHomePage({super.key});
int _calculateCrossAxisCount(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
if (screenWidth > 1200) {
// Large desktops
return 5;
} else if (screenWidth > 900) {
// Desktops / Large Tablets
return 4;
} else if (screenWidth > 600) {
// Tablets
return 3;
} else {
// Phones
return 2;
}
}
// Helper to format currency (assuming '₵' is your currency symbol)
String _formatCurrency(dynamic value) {
final number = double.tryParse(value.toString());
if (number != null) {
return '${number.toStringAsFixed(2)}';
}
return value.toString(); // Fallback to original string if not a number
}
@override
Widget build(BuildContext context) {
Get.put(DashboardController());
return MyScafolld(
title: 'Admin Home Page',
action: IconButton(
onPressed: () async {
await Get.find<DashboardController>().getDashBoard();
},
icon: const Icon(
Icons.refresh,
color: AppColor.greenColor,
),
),
body: [
// This is a List<Widget> for MyScafolld
GetBuilder<DashboardController>(builder: (dashboardController) {
return dashboardController.dashbord.isEmpty
? const MyCircularProgressIndicator()
: Padding(
// This Padding wraps the entire content for this section
padding: const EdgeInsets.all(8.0),
child: ListView(
// Changed from a direct ListView for the whole page
// to a ListView that contains the stats grid and then other items.
children: [
// --- Statistics Grid Section ---
Container(
// width: Get.width, // Not needed in ListView
// height: Get.height * .6, // Let GridView determine its height
padding: const EdgeInsets.all(
8.0), // Padding for the grid container
decoration: AppStyle.boxDecoration1.copyWith(
// Optional: slightly different background for the grid area
// color: (AppStyle.boxDecoration1.color as Color?)?.withAlpha(200) ?? Theme.of(context).cardColor.withAlpha(200),
boxShadow: [] // Remove shadow if cards have them, or use a very subtle one
),
child: GridView.count(
crossAxisCount: _calculateCrossAxisCount(context),
shrinkWrap: true,
physics:
const NeverScrollableScrollPhysics(), // Grid shouldn't scroll independently
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
childAspectRatio:
1.7, // Adjust for desired card W/H ratio (e.g. 1.5 to 2.0)
children: [
DashboardStatCard(
title: 'SMS Credits',
value: dashboardController.creditSMS.toString(),
icon: Icons.sms_outlined,
iconColor: Colors.lightBlueAccent,
),
DashboardStatCard(
title: 'Passengers',
value: dashboardController.dashbord[0]
['countPassengers']
.toString(),
icon: Icons.people_alt_outlined,
iconColor: Colors.teal,
),
DashboardStatCard(
title: 'Drivers',
value: dashboardController.dashbord[0]
['countDriver']
.toString(),
icon: Icons.sports_motorsports_outlined,
iconColor: Colors.orangeAccent,
),
DashboardStatCard(
title: 'Rides (Month)',
value: dashboardController.dashbord[0]
['countRideThisMonth']
.toString(),
icon: Icons.calendar_month_outlined,
iconColor: Colors.purpleAccent,
),
DashboardStatCard(
title: 'Avg. Ride Cost',
value: _formatCurrency(dashboardController
.dashbord[0]['avg_passenger_price']),
icon: Icons.monetization_on_outlined,
iconColor: Colors.green,
valueColor: Colors.green.shade700,
),
DashboardStatCard(
title: 'Completed Rides',
value: dashboardController.dashbord[0]
['completed_rides']
.toString(),
icon: Icons.check_circle_outline,
iconColor: AppColor.greenColor,
),
DashboardStatCard(
title: 'Cancelled Rides',
value: dashboardController.dashbord[0]
['cancelled_rides']
.toString(),
icon: Icons.cancel_outlined,
iconColor: AppColor.redColor,
),
DashboardStatCard(
title: 'Driver Payments',
value: _formatCurrency(
dashboardController.dashbord[0]['payments']),
icon: Icons.payments_outlined,
iconColor: Colors.indigoAccent,
valueColor: Colors.indigo.shade700,
),
DashboardStatCard(
title: 'Tripz Wallet',
value: _formatCurrency(dashboardController
.dashbord[0]['seferWallet']),
icon: Icons.account_balance_wallet_outlined,
iconColor: Colors.deepOrangeAccent,
valueColor: Colors.deepOrange.shade700,
),
DashboardStatCard(
title: 'Transfers Count',
value: dashboardController.dashbord[0]
['transfer_from_count']
.toString(),
icon: Icons.swap_horiz_outlined,
iconColor: Colors.brown,
),
DashboardStatCard(
title: 'Morning Rides',
value: dashboardController.dashbord[0]
['morning_ride_count']
.toString(),
icon: Icons.wb_sunny_outlined,
iconColor: Colors.amberAccent,
),
DashboardStatCard(
title: 'Evening Rides',
value: dashboardController.dashbord[0]
['evening_ride_count']
.toString(),
icon: Icons.brightness_4_outlined,
iconColor: Colors.blueGrey,
),
DashboardStatCard(
title: 'Night Rides',
value: dashboardController.dashbord[0]
['night_ride_count']
.toString(),
icon: Icons.nightlight_round_outlined,
iconColor: Colors.black54,
),
DashboardStatCard(
title: 'Comfort Type',
value: dashboardController.dashbord[0]['comfort']
.toString(),
icon: Icons.event_seat_outlined,
iconColor: Colors.cyan,
),
DashboardStatCard(
title: 'Speed Type',
value: dashboardController.dashbord[0]['speed']
.toString(),
icon: Icons.speed_outlined,
iconColor: Colors.red,
),
DashboardStatCard(
title: 'Lady Type',
value: dashboardController.dashbord[0]['lady']
.toString(),
icon: Icons.woman_2_outlined,
iconColor: Colors.pinkAccent,
),
],
),
),
// --- End of Statistics Grid Section ---
// --- Your AdminWidgetsDashBoard items follow ---
AdminWidgetsDashBoard(
title: 'Passengers',
icon: Icons.people_outline,
onPressed: () => Get.to(() => Passengrs(),
transition: Transition.topLevel)),
AdminWidgetsDashBoard(
title: 'Captains',
icon: Icons.sports_motorsports_outlined,
onPressed: () => Get.to(() => Captain(),
transition: Transition.size)),
// ... (Add all your other AdminWidgetsDashBoard items here with icons)
AdminWidgetsDashBoard(
title: 'Wallet',
icon: Icons.account_balance_wallet_outlined,
onPressed: () => Get.to(() => Wallet(),
transition: Transition.fade)),
AdminWidgetsDashBoard(
title: 'Rides',
icon: Icons.directions_car_filled_outlined,
onPressed: () => Get.to(() => Rides(),
transition: Transition.downToUp)),
AdminWidgetsDashBoard(
title: 'Static',
icon: Icons.bar_chart_outlined,
onPressed: () async {
await Get.put(StaticController()).getAll();
Get.to(() => const StaticDash());
},
),
AdminWidgetsDashBoard(
title: 'send Whatsapp to Drivers',
icon: Icons.message_outlined,
iconColor: Colors.green,
onPressed: () async {
Get.defaultDialog(
title: 'Are you sure to send by WhatsApp ?',
middleText: '',
confirm: MyElevatedButton(
title: 'Ok',
kolor: AppColor.greenColor,
onPressed: () async {
Log.print(
'CRUD().phoneDriversTest.: ${CRUD().phoneDriversTest}');
for (var phoneNumber
in CRUD().phoneDrivers) {
await CRUD().sendWhatsAppAuth(
phoneNumber.toString());
}
}),
cancel: MyElevatedButton(
title: 'cancel',
kolor: AppColor.redColor,
onPressed: () => Get.back()));
}),
AdminWidgetsDashBoard(
title: 'send notification Drivers',
icon: Icons.notifications_active_outlined,
onPressed: () async {
await Get.put(NotificationController())
.getTokensDrivers();
}),
AdminWidgetsDashBoard(
title: 'send SMS Drivers',
icon: Icons.sms_outlined,
onPressed: () async {
Get.defaultDialog(
title: 'Are you sure to send SMS ?',
middleText: '',
content: Padding(
padding: const EdgeInsets.all(8.0),
child: Form(
key: dashboardController.formKey,
child: MyTextForm(
controller:
dashboardController.smsText,
label: 'label',
hint: 'hint',
type: TextInputType.name)),
),
confirm: MyElevatedButton(
title: 'Ok',
kolor: AppColor.greenColor,
onPressed: () async {
dashboardController.sendSMSMethod();
}),
cancel: MyElevatedButton(
title: 'cancel',
kolor: AppColor.redColor,
onPressed: () => Get.back()));
}),
AdminWidgetsDashBoard(
title: 'send notification Passengers',
icon: Icons.notification_important_outlined,
onPressed: () async {
await Get.put(NotificationController())
.getTokensPassengers();
}),
AdminWidgetsDashBoard(
title: 'register captain'.tr,
icon: Icons.person_add_alt_1_outlined,
onPressed: () async {
await Get.put(RegisterCaptainController())
.getDriverNotCompleteRegistration();
Get.to(() => const DriversCantRegister());
},
),
AdminWidgetsDashBoard(
title: 'update packages'.tr,
icon: Icons.inventory_2_outlined,
onPressed: () async {
Get.to(() => PackageUpdateScreen());
},
),
AdminWidgetsDashBoard(
title: 'Employee'.tr,
icon: Icons.badge_outlined,
onPressed: () async {
Get.to(() => EmployeePage());
},
),
AdminWidgetsDashBoard(
title: 'Drivers the best'.tr,
icon: Icons.star_outline,
onPressed: () async {
Get.to(() => DriverTheBest());
},
),
AdminWidgetsDashBoard(
title: 'Add device to be Admin',
icon: Icons.admin_panel_settings_outlined,
onPressed: () async {
await CRUD()
.post(link: AppLink.addAdminUser, payload: {
'name': 'b',
});
}),
],
),
);
})
],
isleading: false,
);
}
}
class AdminWidgetsDashBoard extends StatelessWidget {
const AdminWidgetsDashBoard({
super.key,
required this.title,
required this.onPressed,
this.icon, // Optional icon
this.iconColor,
this.backgroundColor,
});
final String title;
final Callback onPressed;
final IconData? icon;
final Color? iconColor;
final Color? backgroundColor;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6.0, horizontal: 12.0),
child: InkWell(
onTap: onPressed,
borderRadius:
BorderRadius.circular(12.0), // Rounded corners for tap effect
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0, vertical: 16.0), // Increased padding
decoration: BoxDecoration(
color: backgroundColor ??
Theme.of(context).cardColor, // Use provided or theme card color
borderRadius: BorderRadius.circular(12.0),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.15),
spreadRadius: 1,
blurRadius: 8,
offset: const Offset(0, 2), // changes position of shadow
),
],
// If you want to use AppStyle.boxDecoration as a base and modify it:
// ...AppStyle.boxDecoration.copyWith(
// color: backgroundColor ?? AppStyle.boxDecoration.color,
// // Potentially override other properties of AppStyle.boxDecoration if needed
// ),
),
child: Row(
children: [
if (icon != null) ...[
Icon(
icon,
size: 28, // Slightly larger icon
color: iconColor ??
AppColor.primaryColor, // Use primary color or provided
),
const SizedBox(width: 16),
],
Expanded(
child: Text(
title.tr,
style: AppStyle.title.copyWith(
fontSize: 16, // Adjust font size for better readability
fontWeight: FontWeight.w500, // Medium weight
color: Theme.of(context)
.textTheme
.bodyLarge
?.color, // Use theme text color
),
),
),
const Icon(
Icons.arrow_forward_ios,
size: 18,
color: Colors.grey, // Subtle indicator for navigation
),
],
),
),
),
);
}
}