Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:firebase_auth/firebase_auth.dart';
- import 'package:firebase_core/firebase_core.dart';
- import 'package:firebase_database/firebase_database.dart';
- import 'package:firebase_database/ui/firebase_animated_list.dart';
- import 'package:flutter/material.dart';
- import 'firebase_options.dart';
- void main() {
- runApp( MyApp());
- }
- class MyApp extends StatelessWidget {
- const MyApp({Key? key}) : super(key: key);
- Future<UserCredential> _signIn() async {
- print('init app');
- return Firebase.initializeApp(
- options: DefaultFirebaseOptions.currentPlatform,
- ).then((value) async {
- print('signing in');
- return await FirebaseAuth.instance.signInWithEmailAndPassword(
- password: "mypassword",
- );
- });
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- home: FutureBuilder<UserCredential>(
- future: _signIn(),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.waiting) {
- return const Scaffold(
- body: Center(
- child: CircularProgressIndicator(),
- ),
- );
- } else if (snapshot.hasError) {
- return Scaffold(
- body: Center(
- child: Text("Error signing in: ${snapshot.error}"),
- ),
- );
- } else {
- return const StateHome();
- }
- },
- ),
- );
- }
- }
- class StateHome extends StatefulWidget {
- const StateHome({Key? key}) : super(key: key);
- @override
- State<StateHome> createState() => _StateHomeState();
- }
- class _StateHomeState extends State<StateHome> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text("Home"),
- actions: [
- IconButton(
- icon: const Icon(Icons.logout),
- onPressed: () async {
- FirebaseAuth.instance.signOut().then((value) => print('logged out'));
- },
- )
- ],
- ),
- body: Column(children: [
- Expanded(
- child: FirebaseAnimatedList(
- query: FirebaseDatabase.instance.ref().child('msg'),
- itemBuilder: (BuildContext context, DataSnapshot snapshot,
- Animation<double> animation, int index) {
- return ListTile(
- title: Text("message.content"),
- );
- }),
- ),
- ]
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment