easy_firebase_auth 2.4.0 easy_firebase_auth: ^2.4.0 copied to clipboard
Manage authentication with firebase in an extremely simple way
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:easy_firebase_auth/easy_firebase_auth.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AuthProvider(
autoSignInAnonymously: false,
splashScreenDurationMillis: 500,
child: MaterialApp(
home: AuthManagerWidget(
splashScreen: SplashScreen(),
loggedScreen: LoggedScreen(),
notLoggedScreen: NotLoggedScreen(),
actionsAfterLogIn: (method, user) async {
// Initialize user data here
},
actionsBeforeLogOut: (user) async {
// Stop listeners, remove notification tokens...
},
)),
);
}
}
class SplashScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Text(
"SPLASH SCREEN",
style: TextStyle(color: Colors.white),
),
),
);
}
}
class LoggedScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
AuthState authState = Provider.of(context);
return Scaffold(
backgroundColor: Colors.blue,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("${authState.uid}\nis anonymous: ${authState.isAnonymous}", textAlign: TextAlign.center,),
RaisedButton(
onPressed: () {
authState.signOut();
},
child: Text('Sign out'),
),
RaisedButton(
onPressed: () {
authState.signInWithEmail("l@g.com", "123456");
},
child: Text('Reauthenticate with email'),
),
],
),
));
}
}
class NotLoggedScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
// You can set your custom strings
// you can add the privacy of your app with markdown with the necessary links
AuthStrings authStrings = AuthStrings.spanish(
privacyMarkdown:
"Al continuar aceptas la [política de privacidad](https://myPrivacyUrl.com) "
"y las [condiciones de servicio](https://myTermsUrl.com).");
return LoginScreen(
authStrings: authStrings,
backgroundColor: Colors.purple,
expandedWidget: Center(
child: Container(
height: 200,
width: 300,
color: Colors.red,
),
),
);
}
}