Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

verify this code is working and verify data in firebase 1. configure firebase in firbase website and your application ( https://www.youtube.com/watch?v=fxDusoMcWj8&ab_channel=CodingWithTea if u find error

verify this code is working and verify data in firebase

1. configure firebase in firbase website and your application ( https://www.youtube.com/watch?v=fxDusoMcWj8&ab_channel=CodingWithTea

if u find error make sure pubspec.yahl has :

cloud_firestore: ^3.5.1 firebase_core: ^1.24.0 firebase_core_platform_interface: 4.5.1 firebase_crashlytics: ^2.9.0 firebase_remote_config: ^2.0.20 firebase_messaging: ^12.0.3 2. use this code and make it work

import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_core/firebase_core.dart'; import 'firebase_options.dart'; import 'package:flutter/material.dart';

Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); runApp(const MyApp()); }

class MyApp extends StatelessWidget { const MyApp({super.key});

@override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( //add data to firebase floatingActionButton: FloatingActionButton( backgroundColor: Colors.green, child: Icon(Icons.add), onPressed: () { FirebaseFirestore.instance.collection('test').add({ 'ID': 2, 'class': '313cis', 'name': 'Huda', }); }, ), appBar: AppBar( title: Text('Title test'), ), body: ClassList(), ), ); } }

class ClassList extends StatefulWidget { const ClassList({super.key});

@override State createState() => _ClassListState(); }

class _ClassListState extends State { @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(8.0), //read data child: StreamBuilder( stream: FirebaseFirestore.instance.collection('test').snapshots(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (!snapshot.hasData) { return const Center( child: CircularProgressIndicator(), ); }

return ListView( children: snapshot.data!.docs.map((document) { return Column( children: [ Container( child: Center(child: Text(document['ID'].toString())), ), Container( child: Center(child: Text(document['name'])), ), Container( child: Center(child: Text(document['class'])), ), ], ); }).toList(), ); }, ), ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

Students also viewed these Databases questions

Question

Show the properties and structure of allotropes of carbon.

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago

Question

2. How do they influence my actions?

Answered: 1 week ago