火力基地的错误
Posted
技术标签:
【中文标题】火力基地的错误【英文标题】:Erro with firebase 【发布时间】:2021-05-04 14:23:13 【问题描述】:我是 Flutter 的新手。 我尝试连接 firebase 以在屏幕登录中验证电子邮件和密码。
代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:login/page.dart';
import 'package:login/register_page.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'forgivePassword.dart';
class MyApp extends StatefulWidget
@override
_MyAppState createState() => _MyAppState();
class _MyAppState extends State<MyApp>
String _email, _password;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context)
return Scaffold(
backgroundColor: Colors.blue,
body: Center(
child: SizedBox(
width: 380,
height: 400,
child: Form(
key: _formKey,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(top: 10.0),
),
Container(
padding: EdgeInsets.fromLTRB(50.0, 1.0, 50.0, 1.0),
child: TextFormField(
validator: (input)
if(input.isEmpty)
return ;
,
onSaved: (input) => _email = input,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "E-mail",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
)
),
),
),
Container(
padding: EdgeInsets.only(top: 10.0),
),
Container(
padding: EdgeInsets.fromLTRB(50.0, 1.0, 50.0, 0.0),
child: TextFormField(
validator: (input)
if(input.length < 6)
return 'Your password needs to be atleast 6 characters';
,
onSaved: (input) => _password = input,
obscureText: true,
decoration: const InputDecoration(
labelText: "Password",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0)))),
keyboardType: TextInputType.emailAddress,
),
),
Row(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(178, 0, 0, 0),
child: TextButton(
onPressed: ()
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
ForgivePassword()));
,
child: Text(
"Esqueci minha senha",
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
)),
)
],
),
SizedBox(
width: 310,
height: 35,
child: RaisedButton(
color: Colors.blue,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
onPressed: sigIn,
child: Text("Login"),
)),
Padding(
padding: const EdgeInsets.only(top: 15.0),
child: SizedBox(
width: 310,
height: 35,
child: RaisedButton(
color: Colors.blue,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
onPressed: ()
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
PaginaRegistro()));
,
child: Text("Registre-se"),
)),
),
],
),
),
),
),
),
);
Future<void> sigIn() async
final formState = _formKey.currentState;
if(formState.validate())
try
UserCredential user = await FirebaseAuth.
instance.signInWithEmailAndPassword(email: _email, password: _password);
Navigator.push(context, MaterialPageRoute(builder: (context) => Home()));
catch(e)
print(e.massage);
错误:
正在执行热重启...正在将文件同步到 IA 上的设备 AOSP 模拟器...在 925 毫秒内重新启动应用程序。 E/颤动(4428): [错误:flutter/lib/ui/ui_dart_state.cc(186)] 未处理的异常: NoSuchMethodError:“FirebaseException”类没有实例获取器 '按摩'。 E/颤振(4428):接收器:实例 'FirebaseException' E/flutter(4428):尝试调用:按摩 E/颤振(4428):#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5) E/flutter (4428): #1 _MyAppState.sigIn (package:login/login_page.dart:149:17) E/flutter (4428): #2 _InkResponseState._handleTap (包:flutter/src/material/ink_well.dart:991:20) E/flutter (4428): #3 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter ( 4428): #4 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11) E/flutter (4428): #5 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5) E/flutter (4428): #6 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:222:7) E/flutter (4428): #7 PrimaryPointerGestureRecognizer.handleEvent (包:flutter/src/gestures/recognizer.dart:475:9) E/flutter ( 4428):#8 PointerRouter._dispatch (包:flutter/src/gestures/pointer_router.dart:93:12) E/flutter ( 4428):#9 PointerRouter._dispatchEventToRoutes。 (包:flutter/src/gestures/pointer_router.dart:138:9) E/颤振(4428):#10 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8) E/flutter (4428): #11 PointerRouter._dispatchEventToRoutes (包:flutter/src/gestures/pointer_router.dart:136:18) E/flutter ( 4428): #12 PointerRouter.route (包:flutter/src/gestures/pointer_router.dart:122:7) E/flutter ( 4428): #13 手势绑定.handleEvent (包:flutter/src/gestures/binding.dart:381:19)E/flutter(4428): #14 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:361:22) E/flutter (4428): #15 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:278:11) E/flutter (4428): #16 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:316:7) E/flutter (4428): #17 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:280:5) E/flutter (4428): #18 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:238:7) E/flutter (4428): #19 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:221:7) E/flutter (4428): #20 _rootRunUnary (dart:async/zone.dart:1202:13) E/flutter (4428): #21 _CustomZone.runUnary (dart:async/zone.dart:1097:19) E/颤振(4428):#22 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1002:7) E/flutter (4428): #23 _invoke1 (dart:ui/hooks.dart:176:10) E/flutter (4428): #24 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:276:7) E/flutter (4428): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31) E/flutter (4428):
【问题讨论】:
错字:` print(e.massage);` 应该是 ` print(e.message);` (e
在m
之后)。
【参考方案1】:
您输入错误。使用“打印(e.message);”而不是“打印(e.massage);”在您的打印声明中:
catch(e)
print(e.message);
【讨论】:
以上是关于火力基地的错误的主要内容,如果未能解决你的问题,请参考以下文章
未处理的拒绝(TypeError):无法读取未定义的属性“映射”? (反应火力基地)