2020-05-29 16:14:17 +06:30
|
|
|
import 'dart:async';
|
|
|
|
|
|
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';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-05-29 16:14:17 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:pin_input_text_field/pin_input_text_field.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
2020-09-13 21:49:39 +06:30
|
|
|
import '../../helpers/theme.dart';
|
2020-05-29 16:14:17 +06:30
|
|
|
|
2020-09-12 03:34:52 +06:30
|
|
|
const resend_count_sec = 30;
|
2020-05-29 16:14:17 +06:30
|
|
|
|
2020-09-12 03:34:52 +06:30
|
|
|
class SmsCodePage extends StatefulWidget {
|
2020-05-29 16:14:17 +06:30
|
|
|
final String phoneNumber;
|
2020-09-12 03:34:52 +06:30
|
|
|
const SmsCodePage({Key key, this.phoneNumber}) : super(key: key);
|
2020-05-29 16:14:17 +06:30
|
|
|
@override
|
2020-09-12 03:34:52 +06:30
|
|
|
_SmsCodePageState createState() => _SmsCodePageState();
|
2020-05-29 16:14:17 +06:30
|
|
|
}
|
|
|
|
|
|
2020-09-12 03:34:52 +06:30
|
|
|
class _SmsCodePageState extends State<SmsCodePage> {
|
2020-05-29 16:14:17 +06:30
|
|
|
bool _isLoading = false;
|
|
|
|
|
String pin;
|
|
|
|
|
bool allNumberEntered;
|
|
|
|
|
Timer _timer;
|
|
|
|
|
int _start = resend_count_sec;
|
|
|
|
|
bool canResend = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
pin = "";
|
|
|
|
|
allNumberEntered = false;
|
|
|
|
|
super.initState();
|
|
|
|
|
startTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startTimer() {
|
|
|
|
|
_timer = new Timer.periodic(
|
|
|
|
|
Duration(seconds: 1),
|
|
|
|
|
(t) => setState(
|
|
|
|
|
() {
|
|
|
|
|
if (_start < 1) {
|
|
|
|
|
t.cancel();
|
|
|
|
|
canResend = true;
|
|
|
|
|
} else {
|
|
|
|
|
_start = _start - 1;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_timer.cancel();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2020-06-01 14:24:45 +06:30
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon: new Icon(Icons.close),
|
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
|
),
|
2020-05-29 16:14:17 +06:30
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
body: ListView(
|
|
|
|
|
padding: EdgeInsets.only(top: 5, left: 5, right: 5),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Card(
|
|
|
|
|
elevation: 5.0,
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 20, right: 20, top: 40),
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
2020-09-12 03:34:52 +06:30
|
|
|
'sms.verify.title',
|
2020-05-29 16:14:17 +06:30
|
|
|
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(
|
|
|
|
|
left: 20,
|
|
|
|
|
top: 20,
|
|
|
|
|
),
|
2020-09-12 03:34:52 +06:30
|
|
|
child: LocalText(context, 'sms.six.digit',
|
2020-05-29 16:14:17 +06:30
|
|
|
fontSize: 15, color: labelColor),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 20),
|
|
|
|
|
child: Text(
|
|
|
|
|
widget.phoneNumber,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 16),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 20, left: 20, right: 20),
|
|
|
|
|
child: PinInputTextField(
|
|
|
|
|
pinLength: 6,
|
2020-10-07 02:33:06 +06:30
|
|
|
decoration: BoxLooseDecoration(
|
|
|
|
|
strokeColorBuilder: PinListenColorBuilder(
|
|
|
|
|
primaryColor, Colors.grey[400])),
|
2020-05-29 16:14:17 +06:30
|
|
|
textInputAction: TextInputAction.done,
|
|
|
|
|
autoFocus: true,
|
|
|
|
|
onChanged: _pinChange,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 20, top: 20, right: 20),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
RaisedButton(
|
|
|
|
|
onPressed: canResend ? _resend : null,
|
|
|
|
|
color: canResend ? Colors.white : Colors.grey,
|
2020-09-12 03:34:52 +06:30
|
|
|
child: LocalText(context, 'sms.resend',
|
2020-05-29 16:14:17 +06:30
|
|
|
fontSize: 16,
|
|
|
|
|
color:
|
|
|
|
|
canResend ? primaryColor : Colors.grey[400]),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
|
|
|
side: BorderSide(
|
|
|
|
|
color: canResend
|
|
|
|
|
? primaryColor
|
|
|
|
|
: Colors.grey[400])),
|
|
|
|
|
),
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: allNumberEntered ? _verify : null,
|
|
|
|
|
child: CircleAvatar(
|
|
|
|
|
backgroundColor: allNumberEntered
|
|
|
|
|
? primaryColor
|
|
|
|
|
: Colors.grey[400],
|
|
|
|
|
child: Icon(
|
|
|
|
|
Icons.check,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
|
left: 20,
|
|
|
|
|
right: 20,
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
LocalText(
|
|
|
|
|
context,
|
2020-09-12 03:34:52 +06:30
|
|
|
'sms.resend.seconds',
|
2020-05-29 16:14:17 +06:30
|
|
|
fontSize: 15,
|
|
|
|
|
translationVariables: [_start.toString()],
|
2020-06-01 14:24:45 +06:30
|
|
|
color: primaryColor,
|
2020-05-29 16:14:17 +06:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 20),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_pinChange(pin) {
|
|
|
|
|
setState(() {
|
|
|
|
|
this.pin = pin;
|
|
|
|
|
this.allNumberEntered = this.pin.length == 6;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_resend() async {}
|
|
|
|
|
|
|
|
|
|
_verify() async {
|
2020-09-11 16:14:36 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
2020-08-30 21:26:37 +06:30
|
|
|
try {
|
2020-09-04 01:42:58 +06:30
|
|
|
AuthResult auth = await context.read<MainModel>().signin(this.pin);
|
2020-09-12 03:34:52 +06:30
|
|
|
|
2020-08-30 21:26:37 +06:30
|
|
|
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
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
}
|
2020-09-11 16:14:36 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
2020-05-29 16:14:17 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_completeResend() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
_start = resend_count_sec;
|
|
|
|
|
canResend = false;
|
|
|
|
|
startTimer();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_completeVerify() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|