2020-09-15 07:13:41 +06:30
|
|
|
import 'package:country_code_picker/country_code_picker.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/customer/model/customer_model.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-07 14:42:07 +06:30
|
|
|
import 'package:fcs/pages/widgets/input_text.dart';
|
2024-01-25 17:40:35 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-09-15 07:13:41 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class InvitationCreate extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_InvitationCreateState createState() => _InvitationCreateState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _InvitationCreateState extends State<InvitationCreate> {
|
|
|
|
|
TextEditingController _nameController = new TextEditingController();
|
|
|
|
|
TextEditingController _phoneController = new TextEditingController();
|
|
|
|
|
|
|
|
|
|
bool _isLoading = false;
|
2021-09-10 12:00:08 +06:30
|
|
|
late String dialCode;
|
2020-09-15 07:13:41 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
dialCode = "+95";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-07 14:42:07 +06:30
|
|
|
final nameBox = InputText(
|
|
|
|
|
labelTextKey: 'customer.name',
|
|
|
|
|
iconData: Icons.person,
|
|
|
|
|
controller: _nameController);
|
|
|
|
|
|
2020-09-15 07:13:41 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
2024-01-25 17:40:35 +06:30
|
|
|
appBar: LocalAppBar(
|
|
|
|
|
labelKey: "invitation.form.title",
|
2020-09-18 04:04:21 +06:30
|
|
|
backgroundColor: Colors.white,
|
2024-01-25 17:40:35 +06:30
|
|
|
labelColor: primaryColor,
|
|
|
|
|
arrowColor: primaryColor,
|
|
|
|
|
onBack: () {
|
|
|
|
|
if (isDataChanged()) {
|
|
|
|
|
showConfirmDialog(context, "back.button_confirm", () {
|
2020-12-04 17:28:21 +06:30
|
|
|
Navigator.of(context).pop();
|
2024-01-25 17:40:35 +06:30
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-09-15 07:13:41 +06:30
|
|
|
),
|
|
|
|
|
body: Container(
|
|
|
|
|
padding: EdgeInsets.all(18),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
2020-10-07 14:42:07 +06:30
|
|
|
nameBox,
|
2020-09-15 07:13:41 +06:30
|
|
|
SizedBox(height: 10),
|
|
|
|
|
Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.phone,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
decoration: BoxDecoration(
|
2021-09-13 11:20:35 +06:30
|
|
|
border:
|
|
|
|
|
Border.all(color: Colors.grey.shade400, width: 1),
|
2020-09-15 07:13:41 +06:30
|
|
|
borderRadius: BorderRadius.all(Radius.circular(12.0))),
|
|
|
|
|
child: CountryCodePicker(
|
|
|
|
|
onChanged: _countryChange,
|
|
|
|
|
initialSelection: dialCode,
|
2020-10-08 11:38:05 +06:30
|
|
|
countryFilter: ['mm', 'us'],
|
2020-09-15 07:13:41 +06:30
|
|
|
showCountryOnly: false,
|
|
|
|
|
showOnlyCountryWhenClosed: false,
|
|
|
|
|
alignLeft: false,
|
2021-09-13 11:20:35 +06:30
|
|
|
textStyle: TextStyle(fontSize: 16, color: Colors.black87),
|
2020-09-15 07:13:41 +06:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 10,
|
|
|
|
|
),
|
|
|
|
|
Flexible(
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 10, bottom: 10),
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _phoneController,
|
|
|
|
|
cursorColor: primaryColor,
|
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
|
keyboardType: TextInputType.phone,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
fillColor: Colors.white,
|
|
|
|
|
labelText: getLocalString(context, "customer.phone"),
|
|
|
|
|
labelStyle:
|
|
|
|
|
TextStyle(fontSize: 16, color: Colors.grey),
|
|
|
|
|
filled: true,
|
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide:
|
|
|
|
|
BorderSide(color: Colors.grey, width: 1.0)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 20),
|
|
|
|
|
fcsButton(context, getLocalString(context, "invite.btn"),
|
|
|
|
|
callack: _invite),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_countryChange(CountryCode countryCode) {
|
|
|
|
|
setState(() {
|
2021-09-10 12:00:08 +06:30
|
|
|
dialCode = countryCode.dialCode!;
|
2020-09-15 07:13:41 +06:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_invite() async {
|
|
|
|
|
String userName = _nameController.text;
|
|
|
|
|
String phoneNumber = dialCode + _phoneController.text;
|
2024-01-23 16:28:08 +06:30
|
|
|
if (userName == "" || phoneNumber == "") {
|
2020-09-15 07:13:41 +06:30
|
|
|
showMsgDialog(context, "Error", "Invalid name or phone number");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
|
|
|
|
CustomerModel customerModel =
|
|
|
|
|
Provider.of<CustomerModel>(context, listen: false);
|
|
|
|
|
await customerModel.inviteUser(userName, phoneNumber);
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-08 20:24:15 +06:30
|
|
|
|
|
|
|
|
isDataChanged() {
|
2021-09-13 11:20:35 +06:30
|
|
|
String userName = _nameController.text;
|
2020-12-08 20:24:15 +06:30
|
|
|
String phoneNumber = _phoneController.text;
|
|
|
|
|
return userName != "" || phoneNumber != "";
|
|
|
|
|
}
|
2020-09-15 07:13:41 +06:30
|
|
|
}
|