-1
I’m a beginner in Flutter and I’m wondering how to work with the Realtime Database in a project I’m part of, I wanted to know how to take this data from the image of the database and put in the cards of the image of my app.
App initial test code:
import 'package:flutter/material.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
runApp(const MyApp());
}
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Smartfuse';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
/// This is the stateful widget that the main application instantiates.
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({Key? key}) : super(key: key);
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
/// This is the private State class that goes with MyStatefulWidget.
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Testes"),
),
body: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * .25,
width: MediaQuery.of(context).size.width * .55,
child: Card(
child: ListTile(
title: Text("Filme de Ação"),
),
elevation: 8,
margin: EdgeInsets.all(20),
),
),
Container(
height: MediaQuery.of(context).size.height * .25,
width: MediaQuery.of(context).size.width * .55,
child: Card(
child: ListTile(
title: Text("Filmes de Terror"),
),
elevation: 8,
margin: EdgeInsets.all(20),
),
),
Container(
height: MediaQuery.of(context).size.height * .25,
width: MediaQuery.of(context).size.width * .55,
child: Card(
child: ListTile(
title: Text("Filmes de comédia"),
),
elevation: 8,
margin: EdgeInsets.all(20),
),
),
],
),
);
}
}
The image of the database:
Application Cards:
In your example, it shows that you tried to initialize the Firebase already, but what have you tried so far to access the database data? A tip is that you use the Firestore, can take a look at this package that has a very cool example of how to do cloud_firestore
– Matheus Ribeiro
Due to the limitations of my project, I will have to use the Realtime Database, due to the Google charging mode that within our project fits better. Unfortunately I find few examples close to what I need, that also use RD. I tried to get other examples from the internet but I was unsuccessful. I tried to get values like this: Firebasedatabase.instance.Reference(). get(). then((snapshot){ Database=(snapshot.value); });, but wanted to call the specific values within the database and was unsuccessful
– dev_21
My initial idea was for example within Text("Action Movie:") to be able to pass $Filmesdeation of the database within the card. That in theory would be Text("Action Movie: ${"Action Movies"}")
– dev_21