'Project not connecting to real time database - flutter
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
}
}
Solution 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |