diff --git a/lib/core/dependencies.dart b/lib/core/dependencies.dart index a1a04b5..45cd2a4 100644 --- a/lib/core/dependencies.dart +++ b/lib/core/dependencies.dart @@ -299,13 +299,13 @@ class AppDependencies { activePrescriptionsRepo: getIt() ), ); - getIt.registerFactory( - () => QrParkingViewModel( - qrParkingRepo: getIt(), - errorHandlerService: getIt(), - cacheService: getIt(), - ), - ); + // getIt.registerFactory( + // () => QrParkingViewModel( + // qrParkingRepo: getIt(), + // errorHandlerService: getIt(), + // cacheService: getIt(), + // ), + // ); } } diff --git a/lib/presentation/parking/paking_page.dart b/lib/presentation/parking/paking_page.dart index ca72c6e..d9cc1d8 100644 --- a/lib/presentation/parking/paking_page.dart +++ b/lib/presentation/parking/paking_page.dart @@ -14,6 +14,7 @@ import '../../widgets/buttons/custom_button.dart'; import '../../widgets/routes/custom_page_route.dart'; + class ParkingPage extends StatefulWidget { const ParkingPage({super.key}); @@ -22,11 +23,11 @@ class ParkingPage extends StatefulWidget { } class _ParkingPageState extends State { + + Future _readQR(BuildContext context) async { final vm = context.read(); - final model = await vm.scanAndGetParking(); - if (model == null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text(vm.error ?? "Invalid Qr Code")), @@ -36,15 +37,38 @@ class _ParkingPageState extends State { Navigator.of(context).push( CustomPageRoute( - page: ParkingSlot(model: model), + page: ChangeNotifierProvider.value( + value: vm, + child: ParkingSlot(model: model), + ), ), ); } @override - Widget build(BuildContext context) { - final vm = context.watch(); // عشان loading + void initState() { + super.initState(); + WidgetsBinding.instance.addPostFrameCallback((_) async { + final vm = context.read(); + await vm.getIsSaveParking(); + if (!mounted) return; + if (vm.isSavePark && vm.qrParkingModel != null) { + Navigator.of(context).push( + CustomPageRoute( + page: ChangeNotifierProvider.value( + value: vm, + child: ParkingSlot(model: vm.qrParkingModel!), + ), + ), + ); + } + }); + } + + @override + Widget build(BuildContext context) { + final vm = context.watch(); return Scaffold( backgroundColor: AppColors.scaffoldBgColor, appBar: CustomAppBar( @@ -98,7 +122,6 @@ class _ParkingPageState extends State { ), ), - /// Bottom button Container( decoration: RoundedRectangleBorder() .toSmoothCornerDecoration( @@ -113,40 +136,13 @@ class _ParkingPageState extends State { height: 56, child: CustomButton( text: "Read Barcodes".needTranslation, - onPressed: () => _readQR(context), // ALWAYS non-null - isDisabled: vm.isLoading, // control disabled state here + onPressed: () => _readQR(context), // always non-null + isDisabled: vm.isLoading, backgroundColor: AppColors.primaryRedColor, borderColor: AppColors.primaryRedColor, fontSize: 18, fontWeight: FontWeight.bold, - ) - - // ElevatedButton( - // style: ElevatedButton.styleFrom( - // backgroundColor: AppColors.primaryRedColor, - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10), - // ), - // ), - // onPressed: vm.isLoading ? null : () => _readQR(context), - // child: vm.isLoading - // ? const SizedBox( - // width: 22, - // height: 22, - // child: CircularProgressIndicator( - // strokeWidth: 2, - // color: Colors.white, - // ), - // ) - // : const Text( - // "Read Barcodes", - // style: TextStyle( - // fontSize: 18, - // fontWeight: FontWeight.bold, - // color: Colors.white, - // ), - // ), - // ), + ), ), ), ), @@ -156,3 +152,4 @@ class _ParkingPageState extends State { } } + diff --git a/lib/presentation/parking/parking_slot.dart b/lib/presentation/parking/parking_slot.dart index ce13dad..0eb3718 100644 --- a/lib/presentation/parking/parking_slot.dart +++ b/lib/presentation/parking/parking_slot.dart @@ -5,7 +5,6 @@ import 'package:hmg_patient_app_new/core/app_export.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/qr_parking/models/qr_parking_response_model.dart'; - import '../../features/qr_parking/qr_parking_view_model.dart'; import '../../theme/colors.dart'; import '../../widgets/appbar/app_bar_widget.dart'; @@ -13,7 +12,7 @@ import '../../widgets/buttons/custom_button.dart'; import '../../widgets/chip/app_custom_chip_widget.dart'; import 'package:maps_launcher/maps_launcher.dart'; import 'package:provider/provider.dart'; - +import '../../widgets/routes/custom_page_route.dart'; class ParkingSlot extends StatefulWidget { final QrParkingResponseModel model; @@ -28,7 +27,6 @@ class ParkingSlot extends StatefulWidget { } class _ParkingSlotState extends State { - void _openDirection() { final lat = widget.model.latitude; final lng = widget.model.longitude; @@ -36,8 +34,10 @@ class _ParkingSlotState extends State { final valid = lat != null && lng != null && !(lat == 0.0 && lng == 0.0) && - lat >= -90 && lat <= 90 && - lng >= -180 && lng <= 180; + lat >= -90 && + lat <= 90 && + lng >= -180 && + lng <= 180; if (!valid) { ScaffoldMessenger.of(context).showSnackBar( @@ -49,12 +49,33 @@ class _ParkingSlotState extends State { MapsLauncher.launchCoordinates(lat, lng); } + Future _resetDirection() async { final vm = context.read(); await vm.clearParking(); - Navigator.of(context).popUntil((route) => route.isFirst); + final model = await vm.scanAndGetParking(); + if (model == null) { + if (!mounted) return; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(vm.error ?? "Scan cancelled")), + ); + + Navigator.of(context).pop(); + return; + } + + if (!mounted) return; + Navigator.of(context).pushReplacement( + CustomPageRoute( + page: ChangeNotifierProvider.value( + value: vm, + child: ParkingSlot(model: model), + ), + ), + ); } + DateTime? _parseDotNetDate(String? value) { if (value == null || value.isEmpty) return null; @@ -65,11 +86,9 @@ class _ParkingSlotState extends State { final milliseconds = int.tryParse(match.group(1)!); if (milliseconds == null) return null; - return DateTime.fromMillisecondsSinceEpoch(milliseconds, isUtc: true) - .toLocal(); + return DateTime.fromMillisecondsSinceEpoch(milliseconds, isUtc: true).toLocal(); } - String _formatPrettyDate(String? value) { final date = _parseDotNetDate(value); if (date == null) return '-'; @@ -79,14 +98,13 @@ class _ParkingSlotState extends State { 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]; - final day = date.day; + final day = date.day.toString().padLeft(2, '0'); final month = months[date.month - 1]; final year = date.year; - return "$day $month $year"; + return "$day $month $year"; // ✅ 15 Dec 2025 } - String _formatPrettyTime(String? value) { final date = _parseDotNetDate(value); if (date == null) return '-'; @@ -100,7 +118,7 @@ class _ParkingSlotState extends State { hour = hour % 12; if (hour == 0) hour = 12; - return "${hour.toString().padLeft(2, '0')}:$minute $period"; + return "${hour.toString().padLeft(2, '0')}:$minute $period"; // ✅ 03:05 PM } @override @@ -126,11 +144,9 @@ class _ParkingSlotState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - Container( width: double.infinity, - decoration: RoundedRectangleBorder() - .toSmoothCornerDecoration( + decoration: RoundedRectangleBorder().toSmoothCornerDecoration( color: AppColors.whiteColor, borderRadius: 24.r, hasShadow: true, @@ -154,24 +170,16 @@ class _ParkingSlotState extends State { runSpacing: 4, children: [ AppCustomChipWidget( - labelText: - "Slot: ${widget.model.qRParkingCode ?? '-'}" - .needTranslation, + labelText: "Slot: ${widget.model.qRParkingCode ?? '-'}".needTranslation, ), AppCustomChipWidget( - labelText: - "Basement: ${widget.model.floorDescription ?? '-'}" - .needTranslation, + labelText: "Basement: ${widget.model.floorDescription ?? '-'}".needTranslation, ), AppCustomChipWidget( - labelText: - "Date: ${_formatPrettyDate(widget.model.createdOn)}" - .needTranslation, + labelText: "Date: ${_formatPrettyDate(widget.model.createdOn)}".needTranslation, ), AppCustomChipWidget( - labelText: - "Parked Since: ${_formatPrettyTime(widget.model.createdOn)}" - .needTranslation, + labelText: "Parked Since: ${_formatPrettyTime(widget.model.createdOn)}".needTranslation, ), ], ), @@ -179,13 +187,12 @@ class _ParkingSlotState extends State { ), ), ), - SizedBox(height: 24.h), SizedBox( width: double.infinity, height: 48.h, - child:CustomButton( + child: CustomButton( text: "Get Direction".needTranslation, onPressed: _openDirection, backgroundColor: AppColors.primaryRedColor, @@ -194,49 +201,25 @@ class _ParkingSlotState extends State { fontSize: 18, fontWeight: FontWeight.bold, borderRadius: 10, - ) - - // ElevatedButton( - // style: ElevatedButton.styleFrom( - // backgroundColor: AppColors.primaryRedColor, - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10), - // ), - // ), - // onPressed: _openDirection, - // child: Text( - // "Get Direction".needTranslation, - // style: TextStyle( - // fontSize: 18, - // fontWeight: FontWeight.bold, - // color: AppColors.whiteColor, - // ), - // ), - // ), + ), ), - // const Spacer(), - // SizedBox( - // width: double.infinity, - // height: 48.h, - // child: OutlinedButton( - // style: OutlinedButton.styleFrom( - // side: BorderSide(color: AppColors.primaryRedColor), - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10), - // ), - // ), - // onPressed: _resetDirection, - // child: Text( - // "Reset Direction".needTranslation, - // style: TextStyle( - // fontSize: 16, - // fontWeight: FontWeight.w600, - // color: AppColors.primaryRedColor, - // ), - // ), - // ), - // ), + const Spacer(), + + SizedBox( + width: double.infinity, + height: 48.h, + child: CustomButton( + text: "Reset Direction".needTranslation, + onPressed: _resetDirection, + backgroundColor: AppColors.primaryRedColor, + borderColor: AppColors.primaryRedColor, + textColor: AppColors.whiteColor, + fontSize: 18, + fontWeight: FontWeight.bold, + borderRadius: 10, + ), + ), ], ), ), @@ -249,3 +232,5 @@ class _ParkingSlotState extends State { } + +