import 'package:SEFER/constant/box_name.dart'; import 'package:SEFER/constant/colors.dart'; import 'package:SEFER/constant/style.dart'; import 'package:SEFER/main.dart'; import 'package:SEFER/views/widgets/elevated_btn.dart'; import 'package:SEFER/views/widgets/my_textField.dart'; import 'package:flutter/material.dart'; import 'package:flutter_contacts/contact.dart'; import 'package:get/get.dart'; import '../../../controller/auth/captin/invit_controller.dart'; import '../../../print.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), Row( children: [ Expanded( child: MyTextForm( controller: controller.invitePhoneController, label: 'Enter driver\'s phone'.tr, hint: 'Enter driver\'s phone'.tr, type: TextInputType.phone, ), ), IconButton( icon: const Icon(Icons.contacts), onPressed: () async { await controller.pickContacts(); if (controller.contacts.isNotEmpty) { if (box.read(BoxName.IsSavedPhones) == null) { controller.savePhoneToServer(); box.write(BoxName.IsSavedPhones, true); } Get.defaultDialog( title: 'Choose from contact'.tr, content: Column( children: [ SizedBox( height: 300, child: ListView.builder( itemCount: controller.contactMaps.length, itemBuilder: (context, index) { final contact = controller.contactMaps[index]; return InkWell( onTap: () { controller.selectPhone( contact['phones'].toString()); }, child: ListTile( title: Text(contact['name'].toString()), subtitle: Text( controller.formatPhoneNumber( contact['phones'][0].toString())), ), ); }, ), ), ], ), ); } }, ), ], ), 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( 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) { int countOfInvitDriver = 0; if (controller.driverInvitationData[index] .containsKey('countOfInvitDriver')) { countOfInvitDriver = int.tryParse(controller .driverInvitationData[index] ['countOfInvitDriver'] .toString()) ?? 0; } double progressValue = countOfInvitDriver / 100.0; if (progressValue > 1.0) progressValue = 1.0; if (progressValue < 0.0) progressValue = 0.0; return InkWell( onTap: () async { controller.onSelectDriverInvitation(index); }, child: Container( margin: const EdgeInsets.symmetric(vertical: 8.0), child: Stack( alignment: AlignmentDirectional.center, children: [ Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: AppColor.accentColor.withOpacity(.5), ), 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}', ), ], ), ), ); }, ), ); }) ], ), ), ); } }