0

so I was making this sign up page in flutter using firebase authentication and realtime database. authentication works fine but I have a problem with database, it just isn't being created. I tried using push() as well, after following some instructions on google but it doesnt help. there aren't enough instructions on goggle regarding firebase realtime database. Any help will be appreciated!

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);
    }
  }

debug Console

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}

output is empty.

  • It's hard to correlate the debug output you shared to the code you also shared. When you step through your code line-by-line in the debugger, what output is generated when/right after the `usersRef.child(firebaseUser.uid).set(userDataMap);`? – Frank van Puffelen May 09 '21 at 15:13

2 Answers2

0

This will work:

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

Add a "?" after User ..

halfer
  • 19,824
  • 17
  • 99
  • 186
RA Hat
  • 25
  • 8
  • Please do not add religious, theistic, evangelist, superstitious or other irrelevant material here - technical writing is a requirement. – halfer Oct 08 '21 at 19:17
0

So I tried the same thing with this code and got this on console:

W/PersistentConnection(17703): pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to https://flutter-uber-clone-220d2-default-rtdb.asia-southeast1.firebasedatabase.app

Solution:

  1. Either you change your database URL to said link, or
  2. Recreate your project with closer regional time

You also can check this: Firebase Realtime Database connection killed: Different Region

Willy Hystor
  • 21
  • 1
  • 3