[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
I kinda understand the error but whereever I put it, it doesn't work... I am trying to return only a string and a number value from firebase. And I also did all the requirements. build.graddle in android folder, and build.gradle in android/app folder. Everything. In addition to that I also did: cloud_firestore:
to the dependencies on the pubspec.yaml. Now my main.dart looks like this, but gives so much errors I can't paste here. It's very long. I was using this video as a base but it doesn't work..
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
Widget _buildListItem(BuildContext context, DocumentSnapshot document) {
return ListTile(
title: Row(
children: [
Expanded(
child: Text(
document.data()['adSoyad'],
),
),
Container(
decoration: const BoxDecoration(
color: Color(0xffddddff),
),
padding: const EdgeInsets.all(10.0),
child: Text(
document.data()['yas'].toString(),
style: Theme.of(context).textTheme.headline4,
),
),
],
),
onTap: () {
print("bisey");
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('tablolar').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
return ListView.builder(
itemExtent: 80.0,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) =>
_buildListItem(context, snapshot.data.documents[index]),
);
}),
);
}
}