0

I am having a problem with real time database not working, I copied a project from GitHub and made a new project in firebase with my app ID, added the JSON file to my app and changed the write and read rules to true but still not working or showing anything in the terminal

source code :

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class CustomData extends StatefulWidget {
  CustomData({this.app});
  final FirebaseApp app;
  @override
  _CustomDataState createState() => _CustomDataState();
}

class _CustomDataState extends State<CustomData> {
  final refrenceDatabase = FirebaseDatabase.instance;
  final MovieController  = TextEditingController();

  @override
  Widget build(BuildContext context) {
    final ref = refrenceDatabase.reference();
    return Scaffold(
      appBar: AppBar(title: Text('Real Time DataBase'),backgroundColor: Colors.red,),
      backgroundColor: CupertinoColors.systemGrey,
      body: SingleChildScrollView(
        child: Column(children: [
          Center(child:
          Container(
            color: Colors.blue,
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.height,
            child: Column(
              children: [
                Text('Movie title',style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), textAlign: TextAlign.center,),
                TextField(controller: MovireController, textAlign: TextAlign.center,),
                FlatButton(
                  color: Colors.orange,
                    onPressed: (){
                  ref.child('Movies').push().child('movie title').set(MovieController).asStream();
                }, child: Text('Submit'))
              ],
            ),

          ),)
        ],),
      ),
    );
  }
}

Database rules:

{
  "rules": {
    ".read": true,  // 2021-3-23
    ".write": true,  // 2021-3-23
  }
}
5
  • And do you get any error? Commented Feb 22, 2021 at 14:15
  • Please share your database rules, check if you have put the google-services.json file properly and well, has it been connected to Firebase Analytics or any other firebase service properly? Are you receiving any error? Commented Feb 22, 2021 at 14:48
  • No, it shows nothing, nor that it's connecting nor any errors @Renaud Tarnec Commented Feb 22, 2021 at 15:13
  • I am not receiving any errors or any thing in the prompt and analytics show nothing too, I made sure to add google-services.json in the proper place under app, I also added the database rules. @Preet Shah Commented Feb 22, 2021 at 15:19
  • Also, how exactly do you know it is not working? Commented Feb 23, 2021 at 4:52

1 Answer 1

1

Ok. So, from what I have seen, you do not receive any errors. So, it means that your firebase is connecting properly. The second thing is the following error in the code. I don't know what you expect to do with the following code but it is not correct.

// Firstly, you're passing a TextEditingController instead of a string.
// Secondly, you're streaming data but you're not accessing it anywhere.
ref.child('Movies').push().child('movie title').set(MovieController).asStream();
ref.child('Movies').push().set({
  "movie title": MovieController.text,
});

This should push data to your Database.

Sign up to request clarification or add additional context in comments.

3 Comments

I was getting an error error: Too many positional arguments: 0 expected, but 1 found. (extra_positional_arguments at [realtime_test] lib\Customdatabase.dart:42) so I added .set() ref.child('Movies').push().set({ "movie title": MovieController.text, }); but still nothing is showing up in the database @Preet Shah
Well, you're right. I have updated my answer accordingly. However, the error should be some error log or something.
indeed there was something wrong with the database, I created a new project and set the location to US instead of EU and now it works perfectly @Preet Shah

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.