final
This commit is contained in:
@@ -11,9 +11,8 @@ import '../../store/actions.dart';
|
||||
import '../../store/store.dart';
|
||||
|
||||
class MobileLogin extends StatefulWidget {
|
||||
final Key key;
|
||||
|
||||
const MobileLogin({this.key}) : super(key: key);
|
||||
const MobileLogin({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
@@ -26,9 +25,9 @@ class MobileLoginState extends State<MobileLogin> {
|
||||
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
bool passwordVisible;
|
||||
bool passwordVisible = false;
|
||||
|
||||
bool onSubmitting;
|
||||
bool onSubmitting = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -103,8 +102,8 @@ class MobileLoginState extends State<MobileLogin> {
|
||||
fontSize: 18.0
|
||||
),
|
||||
autofocus: true,
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).this_field_is_required;
|
||||
}
|
||||
return null;
|
||||
@@ -143,8 +142,8 @@ class MobileLoginState extends State<MobileLogin> {
|
||||
fontSize: 18.0
|
||||
),
|
||||
obscureText: passwordVisible,
|
||||
validator: (String value) {
|
||||
if (value.trim().isEmpty) {
|
||||
validator: (String? value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return S.of(context).password_is_required;
|
||||
}
|
||||
return null;
|
||||
@@ -196,7 +195,7 @@ class MobileLoginState extends State<MobileLogin> {
|
||||
padding: EdgeInsets.only(top: 20.0, left: 16.0, right: 16.0, bottom: 20.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Theme.of(context).primaryColor,
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
),
|
||||
child: Text(
|
||||
S.of(context).login,
|
||||
@@ -226,8 +225,8 @@ class MobileLoginState extends State<MobileLogin> {
|
||||
}
|
||||
|
||||
void signIn() {
|
||||
final FormState form = _formKey.currentState;
|
||||
if (form.validate()) {
|
||||
final FormState? form = _formKey.currentState;
|
||||
if (form != null && form.validate()) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
onSubmitting = true;
|
||||
@@ -239,19 +238,15 @@ class MobileLoginState extends State<MobileLogin> {
|
||||
print('response $response');
|
||||
User user = User.fromJson(response.data['user']);
|
||||
store.dispatch(UpdateCurrentUser(user));
|
||||
Utils.getBox().then((box) {
|
||||
box.put(Constants.KEY_USER_ID, response.data['user_id']);
|
||||
box.put(Constants.KEY_ACCESS_TOKEN, response.data['access_token']);
|
||||
if (store.state.redirectRoute != null) {
|
||||
Routes.router.navigateTo(context, store.state.redirectRoute, replace: true);
|
||||
store.dispatch(UpdateRedirectRoute(null));
|
||||
} else {
|
||||
Routes.router.navigateTo(
|
||||
context, '/me', replace: true, clearStack: false);
|
||||
}
|
||||
}).catchError((error) {
|
||||
Utils.showMessageDialog(context, error);
|
||||
});
|
||||
Utils.prefs?.setString(Constants.KEY_USER_ID, response.data['user_id']);
|
||||
Utils.prefs?.setString(Constants.KEY_ACCESS_TOKEN, response.data['access_token']);
|
||||
if (store.state.redirectRoute != null) {
|
||||
Routes.router.navigateTo(context, store.state.redirectRoute!, replace: true);
|
||||
store.dispatch(UpdateRedirectRoute(null));
|
||||
} else {
|
||||
Routes.router.navigateTo(
|
||||
context, '/me', replace: true, clearStack: false);
|
||||
}
|
||||
},
|
||||
queryParameters: {
|
||||
'client_id': '${Utils.getPlatformName()}',
|
||||
|
||||
Reference in New Issue
Block a user