关闭应用程序后,当我再次尝试打开它时,出现以下错误,但仅在 iOS 平台上,Android 运行良好。
我环顾四周,有几个关于这个问题的问题和问题,但我无法解决它。我也在使用bloc模式来管理状态。
我GlobalKey<FormState>在我的AuthenticateForm.
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:low_code/blocs/authentication/authentication_bloc.dart';
import 'package:low_code/blocs/authentication/authentication_event.dart';
import 'package:low_code/helpers/app_localization/app_localizations.dart';
class AuthenticateForm extends StatefulWidget {
@override
_AuthenticateFormState createState() => _AuthenticateFormState();
}
class _AuthenticateFormState extends State<AuthenticateForm> {
GlobalKey<FormState> _formKey = GlobalKey<FormState>();
String username;
String password;
@override
Widget build(BuildContext context) {
AppLocalizations appLocalizations = AppLocalizations.of(context);
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextFormField(
onSaved: (String value) => username = value,
initialValue: 'dms-bpm',
decoration: InputDecoration(
labelText: appLocalizations.translate('username')),
// ignore: missing_return
validator: (String value) {
if (value.isEmpty) {
return 'Please enter your ${appLocalizations.translate('username')}';
}
},
),
TextFormField(
onSaved: (String value) => password = value,
obscureText: true,
decoration: InputDecoration(
labelText: appLocalizations.translate('password')),
initialValue: 'dms-bpm',
// ignore: missing_return
validator: (String value) {
if (value.isEmpty) {
return 'Please enter your ${appLocalizations.translate('password')}';
}
},
),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15))),
child: Text(appLocalizations.translate('login')),
onPressed: () {
_formKey.currentState.save();
if (_formKey.currentState.validate()) {
BlocProvider.of<AuthenticationBloc>(context)
..dispatch(
Authenticate(username: username, password: password));
}
},
)
],
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
Flutter(通道稳定,v1.7.8+hotfix.4,在 Microsoft Windows [版本 10.0.17763.615],语言环境 en-GB)
就我而言,发生此错误是因为我设置了initialRoute属性,而我应该设置home属性:
class RouteTestApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo',
//initialRoute: '/', //remove this
home: FirstScreen(), //this is the calling screen
routes: {
ExtractArgumentsScreen.routeName: (context) => ExtractArgumentsScreen(),
},
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9771 次 |
| 最近记录: |