easy_firebase 0.1.2 easy_firebase: ^0.1.2 copied to clipboard
An useful tool to quickly use firebase functionalities in any flutter app.
// ignore_for_file: avoid_print
import 'package:easy_firebase/easy_firebase.dart';
import 'package:example/firebase_options.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
var auth = EasyFire().getAuthObject();
var store = EasyFire().getFirestoreObject();
var rtdb = EasyFire().getRtdbObject();
var storage = EasyFire().getStorageObject();
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
_incrementCounter();
//To signIn with Google
// await auth.signInWithGoogle();
//To get firestore data
// To download data from firebase storage
store.getData('Users', 'uid').then((value) => print(value));
//To get Realtime Database data
rtdb.getData('/data').then((value) => print(value));
// To download a file (opens a file picker)
storage.downloadFile(firestorePath: '/sample.png');
// To upload a file (opens file picker)
storage.uploadFile();
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}