|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:healthcare_user/common/settings.dart';
|
|
|
|
|
import 'package:flutter_native_contact_picker/flutter_native_contact_picker.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
|
|
class Invitations extends StatefulWidget {
|
|
|
|
|
const Invitations({Key? key}) : super(key: key);
|
|
|
|
@ -11,7 +11,6 @@ class Invitations extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _InvitationsState extends State<Invitations> {
|
|
|
|
|
|
|
|
|
|
TextEditingController mobileNumberController = TextEditingController();
|
|
|
|
|
TextEditingController nameController = TextEditingController();
|
|
|
|
|
|
|
|
|
@ -36,39 +35,141 @@ class _InvitationsState extends State<Invitations> {
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
cursorColor: greyColor,
|
|
|
|
|
controller: nameController,
|
|
|
|
|
decoration: textFormFieldDecoration(Icons.phone,'Enter Name'),
|
|
|
|
|
|
|
|
|
|
decoration: textFormFieldDecoration(
|
|
|
|
|
Icons.phone, 'Enter Name'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .02,),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height * .02,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
cursorColor: greyColor,
|
|
|
|
|
controller: mobileNumberController,
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
decoration: textFormFieldDecoration(Icons.phone,'Enter MobileNumber'),
|
|
|
|
|
|
|
|
|
|
decoration: textFormFieldDecoration(
|
|
|
|
|
Icons.phone, 'Enter MobileNumber'),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .02,),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height * .04,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: Text('Or',style: TextStyle(color: primaryColor,fontWeight: FontWeight.bold,fontSize: 20),),
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height:
|
|
|
|
|
MediaQuery.of(context).size.height * .05,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
primary: buttonColors, // background
|
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (nameController.text != '' &&
|
|
|
|
|
mobileNumberController.text != '') {
|
|
|
|
|
AppSettings.preLoaderDialog(context);
|
|
|
|
|
|
|
|
|
|
var now = new DateTime.now();
|
|
|
|
|
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
|
|
|
|
|
|
|
|
|
|
var payload = new Map<String, dynamic>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
payload["name"] = nameController.text;
|
|
|
|
|
payload["phone"] = mobileNumberController.text;
|
|
|
|
|
payload["dateAndTime"] = formattedDate;
|
|
|
|
|
bool invitationStatus = await AppSettings.inviteFriend(payload);
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
if(invitationStatus){
|
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
|
AppSettings.longSuccessToast("Invitation sent successfully");
|
|
|
|
|
nameController.clear();
|
|
|
|
|
mobileNumberController.clear();
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
|
AppSettings.longFailedToast("Failed invite your friend");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(e){
|
|
|
|
|
AppSettings.longFailedToast("Failed invite your friend");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
AppSettings.longFailedToast("details should not be empty");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: const Text('Invite'),
|
|
|
|
|
)),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height * .02,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: Text(
|
|
|
|
|
'Or',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 20),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height * .02,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height:MediaQuery.of(context).size.height * .02,),
|
|
|
|
|
TextButton(
|
|
|
|
|
child: const Text(
|
|
|
|
|
'Select from contacts',
|
|
|
|
|
style: TextStyle(decoration: TextDecoration.underline,color: primaryColor,fontSize: 20),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontSize: 20),
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
Contact? contact = await _contactPicker.selectContact();
|
|
|
|
|
Contact? contact =
|
|
|
|
|
await _contactPicker.selectContact();
|
|
|
|
|
setState(() {
|
|
|
|
|
_contact = contact;
|
|
|
|
|
});
|
|
|
|
|
AppSettings.preLoaderDialog(context);
|
|
|
|
|
|
|
|
|
|
var now = new DateTime.now();
|
|
|
|
|
String formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
|
|
|
|
|
|
|
|
|
|
var payload = new Map<String, dynamic>();
|
|
|
|
|
|
|
|
|
|
String contactNumber=_contact!.phoneNumbers.toString();
|
|
|
|
|
String newContact= contactNumber.substring( 1, contactNumber.length - 1 ).trim();
|
|
|
|
|
|
|
|
|
|
String stringAfterRemovingWhiteSpace = '';
|
|
|
|
|
for (int i = 0; i < newContact.length; i++) {
|
|
|
|
|
if (!newContact[i].contains(' ')) {
|
|
|
|
|
stringAfterRemovingWhiteSpace = stringAfterRemovingWhiteSpace + "" + newContact[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
payload["name"] =_contact!.fullName;
|
|
|
|
|
payload["phone"] = stringAfterRemovingWhiteSpace;
|
|
|
|
|
payload["dateAndTime"] = formattedDate;
|
|
|
|
|
bool invitationStatus = await AppSettings.inviteFriend(payload);
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
if(invitationStatus){
|
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
|
AppSettings.longSuccessToast("Invitation sent successfully");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
|
AppSettings.longFailedToast("Failed invite your friend");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(e){
|
|
|
|
|
AppSettings.longFailedToast("Failed invite your friend");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
)))));
|
|
|
|
|
))))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|