【问题标题】:Firebase Realtime Database not being created in flutter while using firebase authentication使用 Firebase 身份验证时未在 Flutter 中创建 Firebase 实时数据库
【发布时间】:2021-07-30 22:19:11
【问题描述】:

所以我使用 Firebase 身份验证和实时数据库在颤动中制作了这个注册页面。身份验证工作正常,但我的数据库有问题,它只是没有被创建。在按照谷歌上的一些说明进行操作后,我也尝试使用 push(),但它没有帮助。 goggle 上没有足够的关于 firebase 实时数据库的说明。任何帮助将不胜感激!

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

DatabaseReference usersRef = FirebaseDatabase.instance.reference().child("users");
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  void registerNewUser(BuildContext context) async {
    final User firebaseUser = (await _firebaseAuth
            .createUserWithEmailAndPassword(
                email: emailTextEditingController.text,
                password: passwordTextEditingController.text)
            .catchError((errMsg) {
      displayToastMessage("Error: " + errMsg.toString(), context);
    }))
        .user;

    if (firebaseUser != null) {
      Map userDataMap = {
        "name": nameTextEditingController.text.trim(),
        "email": emailTextEditingController.text.trim(),
        "phone": phoneTextEditingController.text.trim(),
      };
      usersRef.child(firebaseUser.uid).set(userDataMap);

      displayToastMessage("Account Created", context);
      Navigator.pushNamedAndRemoveUntil(
          context, MainScreen.idScreen, (route) => false);

      //here
    } else {
      displayToastMessage("Account Not Created", context);
    }
  }

调试控制台

Launching lib/main.dart on M2003J15SC in debug mode...
lib/main.dart:1
✓ Built build/app/outputs/flutter-apk/app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:46469/nnTIbYfPB8Q=/ws
I/GED     (24582): ged_boost_gpu_freq, level 100, eOrigin 2, final_idx 31, oppidx_max 31, oppidx_min 0
I/deu.lagdeuride(24582): ProcessProfilingInfo new_methods=1227 is saved saved_to_disk=1 resolve_classes_delay=8000
W/IInputConnectionWrapper(24582): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(24582): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(24582): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(24582): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(24582): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(24582): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(24582): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(24582): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper(24582): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(24582): getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper(24582): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(24582): endBatchEdit on inactive InputConnection
W/System  (24582): Ignoring header X-Firebase-Locale because its value was null.
I/System.out(24582): [okhttp]:check permission begin!
W/System  (24582): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24582): [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out(24582): [socket]:check permission begin!
W/System  (24582): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24582): [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out(24582): [OkHttp] sendRequest<<
W/System  (24582): Ignoring header X-Firebase-Locale because its value was null.
I/System.out(24582): [okhttp]:check permission begin!
W/System  (24582): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24582): [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out(24582): [OkHttp] sendRequest<<
D/FirebaseAuth(24582): Notifying id token listeners about user ( hULpKuZcGNhVE45xcR5RkrlCPTl1 ).
D/FirebaseAuth(24582): Notifying auth state listeners about user ( hULpKuZcGNhVE45xcR5RkrlCPTl1 ).
D/ViewRootImpl[Toast](24582): hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false
I/Toast   (24582): Show toast from OpPackageName:com.lagdeu.lagdeurider, PackageName:com.lagdeu.lagdeurider
D/Surface (24582): Surface::connect(this=0x77eefc2000,api=1)
D/mali_winsys(24582): EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
D/Surface (24582): Surface::setBufferCount(this=0x77eefc2000,bufferCount=3)
D/Surface (24582): Surface::allocateBuffers(this=0x77eefc2000)
I/System.out(24582): [socket]:check permission begin!
W/System  (24582): ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out(24582): [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
D/Surface (24582): Surface::disconnect(this=0x77eefc2000,api=1)
D/View    (24582): [Warning] assignParent to null: this = android.widget.LinearLayout{7763522 V.E...... ......ID 0,0-564,316}

输出为空。

【问题讨论】:

  • 很难将您共享的调试输出与您也共享的代码关联起来。当您在调试器中逐行执行代码时,在usersRef.child(firebaseUser.uid).set(userDataMap); 之后/之后会生成什么输出?

标签: firebase flutter firebase-realtime-database


【解决方案1】:

这将起作用:

   final User? firebaseUser = (await _firebaseAuth
    .createUserWithEmailAndPassword(
        email: emailtextEditingController.text,
        password: passwordtextEditingController.text)
    .catchError((errMsg) {
  displayToastMessage(errMsg.toString(), context);
})).user;

添加一个“?”在用户之后..

【讨论】:

  • 请不要在此处添加宗教、有神论、福音传教士、迷信或其他不相关的材料 - 技术写作是必需的。
猜你喜欢
  • 2017-12-26
  • 1970-01-01
  • 2021-01-22
  • 2021-06-11
  • 2018-01-17
  • 2018-01-28
  • 1970-01-01
  • 1970-01-01
  • 2020-07-22
相关资源
最近更新 更多