import 'package:SEFER/constant/colors.dart'; import 'package:SEFER/constant/style.dart'; import 'package:SEFER/views/widgets/elevated_btn.dart'; import 'package:SEFER/views/widgets/my_textField.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../../../controller/auth/captin/invit_controller.dart'; class InviteDriverScreen extends StatelessWidget { final InviteController controller = Get.put(InviteController()); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Invite a Driver'.tr)), body: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Invite another driver and both get a gift after he completes 100 trips!" .tr, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 20), MyTextForm( controller: controller.invitePhoneController, label: 'Enter driver\'s phone'.tr, hint: 'Enter driver\'s phone'.tr, type: TextInputType.phone), const SizedBox(height: 20), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ MyElevatedButton( title: 'Send Invite'.tr, onPressed: controller.sendInvite, ), MyElevatedButton( title: 'Show Invitations'.tr, onPressed: () async { controller.fetchDriverStats(); }, ), ], ), const SizedBox(height: 20), GetBuilder(builder: (controller) { return SizedBox( // decoration: AppStyle.boxDecoration, height: Get.height * .4, child: controller.driverInvitationData.isEmpty ? Center( child: Text( "No invitation found yet!".tr, style: AppStyle.title, ), ) : ListView.builder( itemCount: controller.driverInvitationData.length, itemBuilder: (context, index) { // Ensure the 'countOfInvitDriver' key exists and is parseable as an int int countOfInvitDriver = 0; if (controller.driverInvitationData[index] .containsKey('countOfInvitDriver')) { countOfInvitDriver = int.tryParse(controller .driverInvitationData[index] ['countOfInvitDriver'] .toString()) ?? 0; } // Calculate the progress value, ensuring it is between 0 and 1 double progressValue = countOfInvitDriver / 100.0; if (progressValue > 1.0) progressValue = 1.0; if (progressValue < 0.0) progressValue = 0.0; return Container( margin: const EdgeInsets.symmetric(vertical: 8.0), child: Stack( alignment: AlignmentDirectional.center, children: [ InkWell( onTap: () async { controller.onSelectDriverInvitation(index); }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: AppColor.accentColor.withOpacity( .5), // Background color of the container ), width: Get.width * .85, child: ClipRRect( borderRadius: BorderRadius.circular(12), child: LinearProgressIndicator( value: progressValue, color: AppColor.blueColor, backgroundColor: AppColor.accentColor .withOpacity(.3), minHeight: 35, ), ), ), ), Text( '${controller.driverInvitationData[index]['invitorName']} ${controller.driverInvitationData[index]['countOfInvitDriver']} / 100 ${'Trip'.tr}'), ], ), ); }, ), ); }) ], ), ), ); } }