194 lines
7.8 KiB
Dart
194 lines
7.8 KiB
Dart
import 'package:SEFER/constant/box_name.dart';
|
|
import 'package:SEFER/constant/colors.dart';
|
|
import 'package:SEFER/main.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../../controller/auth/captin/invit_controller.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../widgets/elevated_btn.dart';
|
|
|
|
class InviteDriverScreen extends StatelessWidget {
|
|
final InviteController controller = Get.put(InviteController());
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: Text('Invite a Driver'.tr),
|
|
leading: CupertinoNavigationBarBackButton(
|
|
onPressed: () => Get.back(),
|
|
),
|
|
),
|
|
child: SafeArea(
|
|
child: SingleChildScrollView(
|
|
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: CupertinoTheme.of(context).textTheme.navTitleTextStyle,
|
|
),
|
|
const SizedBox(height: 20),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: CupertinoTextField(
|
|
controller: controller.invitePhoneController,
|
|
placeholder: 'Enter driver\'s phone'.tr,
|
|
keyboardType: TextInputType.phone,
|
|
),
|
|
),
|
|
CupertinoButton(
|
|
child: const Icon(CupertinoIcons.person_2),
|
|
onPressed: () async {
|
|
await controller.pickContacts();
|
|
if (controller.contacts.isNotEmpty) {
|
|
if (box.read(BoxName.IsSavedPhones) == null) {
|
|
controller.savePhoneToServer();
|
|
box.write(BoxName.IsSavedPhones, true);
|
|
}
|
|
_showContactsDialog(context);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
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<InviteController>(
|
|
builder: (controller) {
|
|
return SizedBox(
|
|
height: Get.height * .4,
|
|
child: controller.driverInvitationData.isEmpty
|
|
? Center(
|
|
child: Text(
|
|
"No invitation found yet!".tr,
|
|
style: CupertinoTheme.of(context)
|
|
.textTheme
|
|
.navTitleTextStyle,
|
|
),
|
|
)
|
|
: ListView.builder(
|
|
itemCount: controller.driverInvitationData.length,
|
|
itemBuilder: (context, index) {
|
|
int countOfInvitDriver = int.tryParse(controller
|
|
.driverInvitationData[index]
|
|
['countOfInvitDriver']
|
|
?.toString() ??
|
|
'0') ??
|
|
0;
|
|
|
|
double progressValue = countOfInvitDriver / 100.0;
|
|
progressValue = progressValue.clamp(0.0, 1.0);
|
|
|
|
return GestureDetector(
|
|
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: CupertinoColors.systemGrey5,
|
|
),
|
|
width: Get.width * .85,
|
|
height: 35,
|
|
child: ClipRRect(
|
|
borderRadius:
|
|
BorderRadius.circular(12),
|
|
child: LinearProgressIndicator(
|
|
value: progressValue,
|
|
backgroundColor:
|
|
CupertinoColors.systemGrey3,
|
|
valueColor:
|
|
const AlwaysStoppedAnimation<
|
|
Color>(
|
|
CupertinoColors.activeBlue),
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
'${controller.driverInvitationData[index]['invitorName']} ${countOfInvitDriver} / 100 ${'Trip'.tr}',
|
|
style: CupertinoTheme.of(context)
|
|
.textTheme
|
|
.textStyle,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showContactsDialog(BuildContext context) {
|
|
showCupertinoModalPopup(
|
|
context: context,
|
|
builder: (BuildContext context) => CupertinoActionSheet(
|
|
title: Text('Choose from contact'.tr),
|
|
actions: [
|
|
SizedBox(
|
|
height: 300,
|
|
child: CupertinoScrollbar(
|
|
child: ListView.builder(
|
|
itemCount: controller.contactMaps.length,
|
|
itemBuilder: (context, index) {
|
|
final contact = controller.contactMaps[index];
|
|
return CupertinoActionSheetAction(
|
|
child: Text(
|
|
'${contact['name']} - ${controller.formatPhoneNumber(contact['phones'][0].toString())}'),
|
|
onPressed: () {
|
|
controller.selectPhone(contact['phones'].toString());
|
|
// Navigator.pop(context);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
child: Text('Cancel'.tr),
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|