add update phone number and recovery email
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import 'package:country_code_picker/country_code_picker.dart';
|
||||
import 'package:country_picker/country_picker.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/customer/model/customer_model.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
@@ -8,6 +8,8 @@ import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../widgets/input_phone.dart';
|
||||
|
||||
class InvitationCreate extends StatefulWidget {
|
||||
@override
|
||||
_InvitationCreateState createState() => _InvitationCreateState();
|
||||
@@ -18,13 +20,23 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
TextEditingController _phoneController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
late String dialCode;
|
||||
final _inviteFormKey = GlobalKey<FormState>();
|
||||
late Country _selectedCountry;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
dialCode = "+95";
|
||||
_selectedCountry = Country(
|
||||
name: 'Myanmar',
|
||||
countryCode: 'MM',
|
||||
displayName: 'Myanmar(MM)',
|
||||
displayNameNoCountryCode: 'Myanmar',
|
||||
e164Key: '',
|
||||
e164Sc: -1,
|
||||
example: '',
|
||||
geographic: false,
|
||||
level: -1,
|
||||
phoneCode: '95');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -47,6 +59,18 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
},
|
||||
);
|
||||
|
||||
final phoneBox = InputPhone(
|
||||
lableKey: "customer.phone",
|
||||
validationLabel: "customer.phone_empty",
|
||||
phoneCtl: _phoneController,
|
||||
selectedCountry: _selectedCountry,
|
||||
onValueChange: (country) {
|
||||
setState(() {
|
||||
_selectedCountry = country;
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -73,76 +97,8 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
children: <Widget>[
|
||||
nameBox,
|
||||
SizedBox(height: 10),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.phone,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
border:
|
||||
Border.all(color: Colors.grey.shade400, width: 1),
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(12.0))),
|
||||
child: CountryCodePicker(
|
||||
onChanged: _countryChange,
|
||||
initialSelection: dialCode,
|
||||
countryFilter: ['mm', 'us'],
|
||||
showCountryOnly: false,
|
||||
showOnlyCountryWhenClosed: false,
|
||||
alignLeft: false,
|
||||
textStyle:
|
||||
TextStyle(fontSize: 16, color: Colors.black87),
|
||||
searchDecoration: InputDecoration(
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.black, width: 1.0))),
|
||||
),
|
||||
),
|
||||
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)),
|
||||
errorStyle: TextStyle(
|
||||
color: dangerColor,
|
||||
)),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return "Please insert phone no";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
phoneBox,
|
||||
SizedBox(height: 30),
|
||||
fcsButton(context, getLocalString(context, "invite.btn"),
|
||||
callack: _invite),
|
||||
],
|
||||
@@ -153,23 +109,21 @@ class _InvitationCreateState extends State<InvitationCreate> {
|
||||
);
|
||||
}
|
||||
|
||||
_countryChange(CountryCode countryCode) {
|
||||
setState(() {
|
||||
dialCode = countryCode.dialCode!;
|
||||
});
|
||||
}
|
||||
|
||||
_invite() async {
|
||||
String userName = _nameController.text;
|
||||
String phoneNumber = dialCode + _phoneController.text;
|
||||
|
||||
if (!_inviteFormKey.currentState!.validate()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
String userName = _nameController.text;
|
||||
|
||||
bool isMyanmar = _selectedCountry.phoneCode == "95";
|
||||
String dialCode = isMyanmar ? "+959" : "+${_selectedCountry.phoneCode}";
|
||||
String phoneNumber = dialCode + _phoneController.text;
|
||||
|
||||
CustomerModel customerModel =
|
||||
Provider.of<CustomerModel>(context, listen: false);
|
||||
await customerModel.inviteUser(userName, phoneNumber);
|
||||
|
||||
Reference in New Issue
Block a user