Update: 2026-07-13 18:23:52
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import '../../constant/style.dart';
|
||||
import '../../controller/transit/transit_driver_controller.dart';
|
||||
import '../widgets/elevated_btn.dart';
|
||||
import '../widgets/error_snakbar.dart';
|
||||
|
||||
class ManualBoardingPage extends StatefulWidget {
|
||||
final int stopId;
|
||||
final String stopName;
|
||||
const ManualBoardingPage({super.key, required this.stopId, required this.stopName});
|
||||
|
||||
@override
|
||||
State<ManualBoardingPage> createState() => _ManualBoardingPageState();
|
||||
}
|
||||
|
||||
class _ManualBoardingPageState extends State<ManualBoardingPage> {
|
||||
bool isLoading = true;
|
||||
List<Map<String, dynamic>> passengers = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadPassengers();
|
||||
}
|
||||
|
||||
Future<void> _loadPassengers() async {
|
||||
final c = Get.find<TransitDriverController>();
|
||||
// For now, this is a placeholder. You'll need to add getStopPassengers in the controller.
|
||||
final result = await c.getStopPassengers(widget.stopId);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
passengers = result;
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _markBoarded(int index) async {
|
||||
final c = Get.find<TransitDriverController>();
|
||||
final pId = passengers[index]['passenger_id']?.toString() ?? '';
|
||||
if (pId.isEmpty) return;
|
||||
|
||||
final success = await c.boardPassenger(widget.stopId, pId);
|
||||
if (success && mounted) {
|
||||
setState(() {
|
||||
passengers[index]['is_boarded'] = true;
|
||||
});
|
||||
mySnackbarSuccess('تم تسجيل حضور الراكب'.tr);
|
||||
} else {
|
||||
mySnackbarError('فشل تسجيل الحضور'.tr);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.secondaryColor,
|
||||
appBar: AppBar(
|
||||
title: Text('${'Manual List'.tr} - ${widget.stopName}', style: AppStyle.headTitle2.copyWith(color: AppColor.writeColor)),
|
||||
backgroundColor: AppColor.secondaryColor,
|
||||
elevation: 0,
|
||||
iconTheme: IconThemeData(color: AppColor.writeColor),
|
||||
),
|
||||
body: isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: passengers.isEmpty
|
||||
? Center(child: Text('لا يوجد ركاب مسجلين في هذه المحطة'.tr))
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: passengers.length,
|
||||
itemBuilder: (context, index) {
|
||||
final p = passengers[index];
|
||||
final isBoarded = p['is_boarded'] == true;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.cardColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 10, offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: isBoarded ? AppColor.greenColor.withOpacity(0.2) : AppColor.grayColor.withOpacity(0.2),
|
||||
child: Icon(Icons.person, color: isBoarded ? AppColor.greenColor : AppColor.grayColor),
|
||||
),
|
||||
title: Text(p['name'] ?? 'Unknown', style: AppStyle.title.copyWith(fontWeight: FontWeight.bold)),
|
||||
subtitle: Text('ID: ${p['student_id'] ?? p['passenger_id']}', style: AppStyle.subtitle.copyWith(color: AppColor.grayColor)),
|
||||
trailing: isBoarded
|
||||
? const Icon(Icons.check_circle, color: AppColor.greenColor, size: 28)
|
||||
: SizedBox(
|
||||
width: 80,
|
||||
height: 35,
|
||||
child: MyElevatedButton(
|
||||
title: 'حاضر'.tr,
|
||||
kolor: AppColor.accentColor,
|
||||
onPressed: () => _markBoarded(index),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
|
||||
import '../../constant/colors.dart';
|
||||
import '../../constant/style.dart';
|
||||
import '../../controller/transit/transit_driver_controller.dart';
|
||||
import '../widgets/elevated_btn.dart';
|
||||
import 'manual_boarding_page.dart';
|
||||
|
||||
class QRScannerPage extends StatefulWidget {
|
||||
final int stopId;
|
||||
final String stopName;
|
||||
const QRScannerPage({super.key, required this.stopId, required this.stopName});
|
||||
|
||||
@override
|
||||
State<QRScannerPage> createState() => _QRScannerPageState();
|
||||
}
|
||||
|
||||
class _QRScannerPageState extends State<QRScannerPage> {
|
||||
final MobileScannerController _scannerController = MobileScannerController();
|
||||
final AudioPlayer _audioPlayer = AudioPlayer();
|
||||
|
||||
bool _isProcessing = false;
|
||||
String _successMessage = '';
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scannerController.dispose();
|
||||
_audioPlayer.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onDetect(BarcodeCapture capture) async {
|
||||
if (_isProcessing) return;
|
||||
|
||||
final List<Barcode> barcodes = capture.barcodes;
|
||||
if (barcodes.isEmpty) return;
|
||||
|
||||
final String? code = barcodes.first.rawValue;
|
||||
if (code == null || !code.startsWith('transit_board:')) return;
|
||||
|
||||
setState(() {
|
||||
_isProcessing = true;
|
||||
});
|
||||
|
||||
final passengerId = code.replaceAll('transit_board:', '');
|
||||
|
||||
// Play beep sound
|
||||
try {
|
||||
// Assuming you might add a beep sound asset later, or just visual feedback for now.
|
||||
// await _audioPlayer.play(AssetSource('sounds/beep.mp3'));
|
||||
} catch (_) {}
|
||||
|
||||
// Send API Request
|
||||
final c = Get.find<TransitDriverController>();
|
||||
final success = await c.boardPassenger(widget.stopId, passengerId);
|
||||
|
||||
if (success) {
|
||||
setState(() {
|
||||
_successMessage = 'تم صعود الراكب بنجاح ✅'.tr;
|
||||
});
|
||||
// Clear message after 1.5s
|
||||
Future.delayed(const Duration(milliseconds: 1500), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_successMessage = '';
|
||||
_isProcessing = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
_successMessage = 'فشل التحقق ❌'.tr;
|
||||
});
|
||||
Future.delayed(const Duration(milliseconds: 2000), () {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_successMessage = '';
|
||||
_isProcessing = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
title: Text('${'Scan Passengers'.tr} - ${widget.stopName}', style: AppStyle.headTitle2.copyWith(color: Colors.white)),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
iconTheme: const IconThemeData(color: Colors.white),
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
MobileScanner(
|
||||
controller: _scannerController,
|
||||
onDetect: _onDetect,
|
||||
),
|
||||
|
||||
// Overlay for scanner target
|
||||
Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
height: 250,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColor.accentColor, width: 3),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Processing Overlay
|
||||
if (_isProcessing && _successMessage.isEmpty)
|
||||
Container(
|
||||
color: Colors.black54,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: AppColor.accentColor),
|
||||
),
|
||||
),
|
||||
|
||||
// Success / Error Message Overlay
|
||||
if (_successMessage.isNotEmpty)
|
||||
Container(
|
||||
color: _successMessage.contains('✅') ? Colors.green.withValues(alpha: 0.8) : Colors.red.withValues(alpha: 0.8),
|
||||
child: Center(
|
||||
child: Text(
|
||||
_successMessage,
|
||||
style: AppStyle.headTitle2.copyWith(color: Colors.white),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Fallback manual list button
|
||||
Positioned(
|
||||
bottom: 40,
|
||||
left: 20,
|
||||
right: 20,
|
||||
child: SizedBox(
|
||||
height: 55,
|
||||
child: MyElevatedButton(
|
||||
onPressed: () {
|
||||
Get.to(() => ManualBoardingPage(stopId: widget.stopId, stopName: widget.stopName));
|
||||
},
|
||||
kolor: AppColor.cardColor,
|
||||
title: 'Manual Passenger List'.tr,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import '../../controller/transit/transit_driver_controller.dart';
|
||||
import '../../controller/transit/transit_driver_models.dart';
|
||||
import '../widgets/elevated_btn.dart';
|
||||
import '../widgets/my_scafold.dart';
|
||||
import 'qr_scanner_page.dart';
|
||||
|
||||
class TransitDriverHomePage extends StatelessWidget {
|
||||
const TransitDriverHomePage({super.key});
|
||||
@@ -194,7 +195,7 @@ class _ActivationPage extends StatelessWidget {
|
||||
width: 88,
|
||||
height: 88,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.accentColor.withOpacity(0.12),
|
||||
color: AppColor.accentColor.withValues(alpha: 0.12),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.directions_bus_rounded,
|
||||
@@ -236,24 +237,14 @@ class _ActivationPage extends StatelessWidget {
|
||||
const SizedBox(height: 20),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 55,
|
||||
child: controller.isActivating
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColor.accentColor,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
: MyElevatedButton(
|
||||
kolor: AppColor.accentColor,
|
||||
onPressed: () =>
|
||||
controller.activateWithToken(tokenCtrl.text),
|
||||
child: Text(
|
||||
'Activate'.tr,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
title: 'Activate'.tr,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -284,15 +275,28 @@ class _CurrentStopBanner extends StatelessWidget {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
color: AppColor.greenColor.withOpacity(0.12),
|
||||
color: AppColor.greenColor.withValues(alpha: 0.12),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.location_on_rounded, color: AppColor.greenColor, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${'Now at'.tr}: ${stop.nameAr}',
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.greenColor, fontWeight: FontWeight.bold),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${'Now at'.tr}: ${stop.nameAr}',
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.greenColor, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 35,
|
||||
width: 80,
|
||||
child: MyElevatedButton(
|
||||
onPressed: () {
|
||||
Get.to(() => QRScannerPage(stopId: stop.id, stopName: stop.nameAr));
|
||||
},
|
||||
kolor: AppColor.accentColor,
|
||||
title: 'Scan'.tr,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user