104 lines
2.9 KiB
Dart
104 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:progress/progress.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../model/main_model.dart';
|
|
import '../fcs/common/helpers/theme.dart';
|
|
import '../widget/localization/app_translations.dart';
|
|
import '../widget/progress.dart';
|
|
import '../fcs/common/pages/util.dart';
|
|
|
|
class SmsCodePage extends StatefulWidget {
|
|
final String id, password;
|
|
|
|
const SmsCodePage({Key key, this.id, this.password}) : super(key: key);
|
|
@override
|
|
_SmsCodePageState createState() => _SmsCodePageState();
|
|
}
|
|
|
|
class _SmsCodePageState extends State<SmsCodePage> {
|
|
final TextEditingController _sms = new TextEditingController();
|
|
bool _isLoading = false;
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
_confimSignin() async {
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
|
if (!_formKey.currentState.validate()) {
|
|
return;
|
|
}
|
|
|
|
setState(() {
|
|
_isLoading = true;
|
|
});
|
|
try {
|
|
await mainModel.confirmSignup(widget.id, widget.password, _sms.text);
|
|
await mainModel.login(widget.id, widget.password);
|
|
Navigator.pushNamedAndRemoveUntil(context, "/", (r) => false);
|
|
} catch (e) {
|
|
showMsgDialog(context, "Error", e.toString());
|
|
}
|
|
|
|
Future.delayed(Duration(seconds: 1), () {
|
|
if (mounted) {
|
|
setState(() {
|
|
_isLoading = false;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final smsInput = TextFormField(
|
|
controller: _sms,
|
|
keyboardType: TextInputType.number,
|
|
autofocus: false,
|
|
decoration: new InputDecoration(
|
|
labelText: AppTranslations.of(context).text("sms.sms"),
|
|
labelStyle: labelStyle,
|
|
hintText: 'eg. 123456',
|
|
icon: Icon(
|
|
Icons.lock,
|
|
color: primaryColor,
|
|
)),
|
|
validator: (value) {
|
|
if (value.isEmpty) {
|
|
return AppTranslations.of(context).text("sms.empty");
|
|
}
|
|
return null;
|
|
},
|
|
);
|
|
|
|
final singInButton = Padding(
|
|
padding: EdgeInsets.symmetric(vertical: 16.0),
|
|
child: RaisedButton(
|
|
onPressed: () => _confimSignin(),
|
|
padding: EdgeInsets.all(12),
|
|
color: primaryColor,
|
|
child: Text(AppTranslations.of(context).text("singin"),
|
|
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
),
|
|
);
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(AppTranslations.of(context).text("input_sms")),
|
|
backgroundColor: primaryColor,
|
|
),
|
|
body: Center(
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
children: <Widget>[
|
|
Form(key: _formKey, child: smsInput),
|
|
SizedBox(height: 8.0),
|
|
singInButton,
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|