2025-01-14 17:10:10 +06:30
|
|
|
import 'package:country_picker/country_picker.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
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';
|
|
|
|
|
import 'package:fcs/pages/signin/signin_logic.dart';
|
2024-01-26 16:56:20 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-10-14 13:54:42 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-05-29 16:14:17 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
2020-08-30 21:26:37 +06:30
|
|
|
import 'package:provider/provider.dart';
|
2020-05-29 16:14:17 +06:30
|
|
|
|
2020-09-18 04:04:21 +06:30
|
|
|
import '../../helpers/theme.dart';
|
2020-10-07 02:33:06 +06:30
|
|
|
import '../main/util.dart';
|
2025-01-14 17:10:10 +06:30
|
|
|
import '../widgets/input_phone.dart';
|
2020-09-18 04:04:21 +06:30
|
|
|
import 'sms_code_page.dart';
|
2020-05-29 16:14:17 +06:30
|
|
|
|
|
|
|
|
class SigninPage extends StatefulWidget {
|
|
|
|
|
@override
|
|
|
|
|
_SigninPageState createState() => _SigninPageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SigninPageState extends State<SigninPage> {
|
|
|
|
|
bool _isLoading = false;
|
2021-09-10 12:02:08 +06:30
|
|
|
late String dialCode;
|
2020-05-29 16:14:17 +06:30
|
|
|
|
2021-09-10 12:02:08 +06:30
|
|
|
TextEditingController phonenumberCtl = new TextEditingController();
|
2025-01-14 17:10:10 +06:30
|
|
|
late Country _selectedCountry;
|
2020-05-29 16:14:17 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-01-14 17:10:10 +06:30
|
|
|
_selectedCountry = Country(
|
|
|
|
|
name: 'Myanmar',
|
|
|
|
|
countryCode: 'MM',
|
|
|
|
|
displayName: 'Myanmar(MM)',
|
|
|
|
|
displayNameNoCountryCode: 'Myanmar',
|
|
|
|
|
e164Key: '',
|
|
|
|
|
e164Sc: -1,
|
|
|
|
|
example: '',
|
|
|
|
|
geographic: false,
|
|
|
|
|
level: -1,
|
|
|
|
|
phoneCode: '95');
|
2020-05-29 16:14:17 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
2024-01-26 16:56:20 +06:30
|
|
|
child: new Scaffold(appBar: LocalAppBar(), body: _buildLogin(context)),
|
2020-05-29 16:14:17 +06:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget _buildLogin(BuildContext context) {
|
|
|
|
|
return ListView(
|
|
|
|
|
padding: EdgeInsets.only(top: 5, left: 15, right: 15),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 40),
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'login.title',
|
|
|
|
|
fontSize: 21,
|
2020-06-01 14:24:45 +06:30
|
|
|
color: primaryColor,
|
2020-05-29 16:14:17 +06:30
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 25),
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
'login.phone',
|
|
|
|
|
color: labelColor,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-01-14 17:10:10 +06:30
|
|
|
InputPhone(
|
|
|
|
|
autofocus: true,
|
|
|
|
|
validationLabel: "login.phone_empty",
|
|
|
|
|
phoneCtl: phonenumberCtl,
|
|
|
|
|
selectedCountry: _selectedCountry,
|
|
|
|
|
onValueChange: (country) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedCountry = country;
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-05-29 16:14:17 +06:30
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () => _next(),
|
|
|
|
|
child: CircleAvatar(
|
|
|
|
|
minRadius: 25,
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
child: Icon(
|
|
|
|
|
FontAwesomeIcons.arrowRight,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_next() async {
|
2025-01-14 17:10:10 +06:30
|
|
|
if (phonenumberCtl.text.length < 5) {
|
2020-05-29 16:14:17 +06:30
|
|
|
showMsgDialog(context, "Error", "Invalid phone number");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-30 21:26:37 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
|
2025-01-14 17:10:10 +06:30
|
|
|
bool isMyanmar = _selectedCountry.phoneCode == "95";
|
|
|
|
|
String dialCode = isMyanmar ? "+959" : "+${_selectedCountry.phoneCode}";
|
2020-08-30 21:26:37 +06:30
|
|
|
|
2025-01-14 17:10:10 +06:30
|
|
|
try {
|
|
|
|
|
String phoneNumber = dialCode + phonenumberCtl.text;
|
2020-09-04 01:42:58 +06:30
|
|
|
AuthResult auth = await context.read<MainModel>().sendSms(phoneNumber);
|
2020-08-30 21:26:37 +06:30
|
|
|
if (auth.authStatus == AuthStatus.SMS_SENT) {
|
2020-10-14 13:54:42 +06:30
|
|
|
await Navigator.of(context).push(CupertinoPageRoute(
|
2025-01-14 17:10:10 +06:30
|
|
|
builder: (context) => SmsCodePage(
|
|
|
|
|
phoneNumber: phoneNumber,
|
|
|
|
|
forceResendingToken: auth.forceResendingToken)));
|
2020-08-30 21:26:37 +06:30
|
|
|
Navigator.pop(context);
|
2020-09-11 16:14:36 +06:30
|
|
|
} else if (auth.authStatus == AuthStatus.AUTH_VERIFIED) {
|
2020-09-13 21:49:39 +06:30
|
|
|
await navigateAfterAuthVerified(context);
|
2020-08-30 21:26:37 +06:30
|
|
|
}
|
|
|
|
|
if (auth.authStatus == AuthStatus.ERROR) {
|
2021-09-10 16:33:52 +06:30
|
|
|
showMsgDialog(context, "Error", auth.authErrorMsg ?? "");
|
2020-08-30 21:26:37 +06:30
|
|
|
}
|
2020-05-29 16:14:17 +06:30
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
}
|
2020-08-30 21:26:37 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
2020-05-29 16:14:17 +06:30
|
|
|
}
|
|
|
|
|
}
|