add update phone number and recovery email

This commit is contained in:
tzw
2025-01-14 17:10:10 +06:30
parent 21cf7a2517
commit ace3af1785
22 changed files with 1087 additions and 221 deletions

View File

@@ -1,4 +1,4 @@
import 'package:country_code_picker/country_code_picker.dart';
import 'package:country_picker/country_picker.dart';
import 'package:fcs/domain/entities/auth_result.dart';
import 'package:fcs/domain/entities/auth_status.dart';
import 'package:fcs/pages/main/model/main_model.dart';
@@ -13,6 +13,7 @@ import 'package:provider/provider.dart';
import '../../helpers/theme.dart';
import '../main/util.dart';
import '../widgets/input_phone.dart';
import 'sms_code_page.dart';
class SigninPage extends StatefulWidget {
@@ -25,15 +26,22 @@ class _SigninPageState extends State<SigninPage> {
late String dialCode;
TextEditingController phonenumberCtl = new TextEditingController();
late Country _selectedCountry;
@override
void initState() {
super.initState();
phonenumberCtl = new TextEditingController(text: "09");
phonenumberCtl.selection = TextSelection.fromPosition(
TextPosition(offset: phonenumberCtl.text.length));
dialCode = "+95";
_selectedCountry = Country(
name: 'Myanmar',
countryCode: 'MM',
displayName: 'Myanmar(MM)',
displayNameNoCountryCode: 'Myanmar',
e164Key: '',
e164Sc: -1,
example: '',
geographic: false,
level: -1,
phoneCode: '95');
}
@override
@@ -67,53 +75,16 @@ class _SigninPageState extends State<SigninPage> {
fontSize: 16,
),
),
Row(
children: <Widget>[
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: phonenumberCtl,
cursorColor: primaryColor,
textAlign: TextAlign.left,
autofocus: true,
keyboardType: TextInputType.phone,
style: TextStyle(
fontSize: 18,
),
decoration: new InputDecoration(
contentPadding: EdgeInsets.only(top: 8),
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: primaryColor, width: 1.0)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: primaryColor, width: 1.0)),
),
),
),
),
],
InputPhone(
autofocus: true,
validationLabel: "login.phone_empty",
phoneCtl: phonenumberCtl,
selectedCountry: _selectedCountry,
onValueChange: (country) {
setState(() {
_selectedCountry = country;
});
},
),
SizedBox(
height: 20,
@@ -140,15 +111,8 @@ class _SigninPageState extends State<SigninPage> {
);
}
_countryChange(CountryCode countryCode) {
setState(() {
dialCode = countryCode.dialCode ?? '+95';
});
}
_next() async {
String phoneNumber = phonenumberCtl.text;
if (phoneNumber.length < 5) {
if (phonenumberCtl.text.length < 5) {
showMsgDialog(context, "Error", "Invalid phone number");
return;
}
@@ -157,16 +121,17 @@ class _SigninPageState extends State<SigninPage> {
_isLoading = true;
});
try {
phoneNumber = phoneNumber[0] == "0"
? phoneNumber.replaceFirst("0", "")
: phoneNumber;
phoneNumber = dialCode + phoneNumber;
bool isMyanmar = _selectedCountry.phoneCode == "95";
String dialCode = isMyanmar ? "+959" : "+${_selectedCountry.phoneCode}";
try {
String phoneNumber = dialCode + phonenumberCtl.text;
AuthResult auth = await context.read<MainModel>().sendSms(phoneNumber);
if (auth.authStatus == AuthStatus.SMS_SENT) {
await Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => SmsCodePage(phoneNumber: phoneNumber)));
builder: (context) => SmsCodePage(
phoneNumber: phoneNumber,
forceResendingToken: auth.forceResendingToken)));
Navigator.pop(context);
} else if (auth.authStatus == AuthStatus.AUTH_VERIFIED) {
await navigateAfterAuthVerified(context);