我的代码中有一个TextFormField,用户需要在其中输入一个单词(在本例中是一封电子邮件(但是当应用程序打开这个屏幕时,它会立即抛出一个异常,并且每当用户按下键盘上的键时,该异常就会重复
E/MethodChannel#flutter/platform(24591): Failed to handle method call
E/MethodChannel#flutter/platform(24591): java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.app.trust.ITrustManager.isDeviceLocked(int)' on a null object reference
E/MethodChannel#flutter/platform(24591): at android.os.Parcel.readException(Parcel.java:1626)
E/MethodChannel#flutter/platform(24591): at android.os.Parcel.readException(Parcel.java:1573)
E/MethodChannel#flutter/platform(24591): at android.content.IClipboard$Stub$Proxy.hasPrimaryClip(IClipboard.java:233)
E/MethodChannel#flutter/platform(24591): at android.content.ClipboardManager.hasPrimaryClip(ClipboardManager.java:156)
E/MethodChannel#flutter/platform(24591): at io.flutter.plugin.platform.PlatformPlugin.getClipboardData(PlatformPlugin.java:287)
E/MethodChannel#flutter/platform(24591): at io.flutter.plugin.platform.PlatformPlugin.access$700(PlatformPlugin.java:26)
E/MethodChannel#flutter/platform(24591): at io.flutter.plugin.platform.PlatformPlugin$1.getClipboardData(PlatformPlugin.java:85)
E/MethodChannel#flutter/platform(24591): at io.flutter.embedding.engine.systemchannels.PlatformChannel$1.onMethodCall(PlatformChannel.java:141)
E/MethodChannel#flutter/platform(24591): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/MethodChannel#flutter/platform(24591): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#flutter/platform(24591): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:693)
E/MethodChannel#flutter/platform(24591): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#flutter/platform(24591): at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#flutter/platform(24591): at android.os.Looper.loop(Looper.java:135)
E/MethodChannel#flutter/platform(24591): at android.app.ActivityThread.main(ActivityThread.java:5445)
E/MethodChannel#flutter/platform(24591): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#flutter/platform(24591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/MethodChannel#flutter/platform(24591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
这是被调用的异常,我相信这是因为TextFormField,因为当我注释与该Widget相关的代码时,异常就会消失。
我的这个小工具的代码:
class AuthPageState extends State<AuthPage> {
final formKey = GlobalKey<FormState>();
String _email, _password = "";
@override
Widget build(BuildContext context) {
final emailField = SizedBox(
height: 44.0,
child: TextFormField(
obscureText: false,
onChanged: (val) => _email = val,
autovalidateMode: AutovalidateMode.onUserInteraction,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
labelText: "Email",
hintText: "Enter Valid Email",
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
)),
);
return Scaffold(
body: Center(
child: Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Form(key: formKey, child: emailField),
],
),
),
),
),
),
);
}
}
也许我在错误的地方添加了一些东西,或者我忘记了一些东西。我对Flutter的移动开发相当陌生。我不理解这个异常,到目前为止,我还没有在TextFormField中找到任何关于这类异常的信息。
谢谢你的帮助!
参数autovalidateMode: AutovalidateMode.onUserInteraction,
已弃用,请尝试删除它链接