I started to learn flutter again (started some time ago but stopped). You may find my code below. If I run the app on my smartphone it gives me the error: [core/no-app] No Firebase App['DEFAULT'} has been created - call Firebase.initializeApp(). I read in the documentation, but since I use the recent versions firebase_core: ^0.5.0, firebase_auth: ^0.18.0+1, cloud_firestore: ^0.14.0+2 it seems like the documentation isnt finished or I didnt get it. Where do I need to initialize that one? Why isnt that one enough: CollectionReference users = FirebaseFirestore.instance.collection('users');
timeline.dart (code is mostly from flutter getting started):
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:example/widgets/header.dart';
import 'package:example/widgets/progress.dart';
class Timeline extends StatefulWidget {
@override
_TimelineState createState() => _TimelineState();
}
class _TimelineState extends State<Timeline> {
@override
void initState() {
// getUserById();
super.initState();
}
@override
Widget build(BuildContext context) {
CollectionReference users = FirebaseFirestore.instance.collection('users');
return StreamBuilder<QuerySnapshot>(
stream: users.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Text("Loading");
}
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
return new ListTile(
title: new Text(document.data()['username']),
subtitle: new Text(document.data()['posts_count']),
);
}).toList(),
);
},
);
}
}
This is my code for main.dart
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'pages/home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Example',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
accentColor: Colors.blue,
),
home: Home(),
);
}
}
Thank you so much in advance!