Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:font_awesome_flutter/font_awesome_flutter.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:firebase_auth/firebase_auth.dart';
- import 'package:firebase_database/firebase_database.dart';
- import '../util/authentication.dart' as auth;
- bool buttons_visible = false;
- bool loader_visible = true;
- FirebaseUser _firebaseUser = null;
- final databaseReference = FirebaseDatabase.instance.reference();
- class Login extends StatefulWidget {
- @override
- LoginState createState() => new LoginState();
- }
- class LoginState extends State<Login> {
- @override
- void initState() {
- super.initState();
- _checkAuthStatus();
- }
- _swapvisibility(){
- setState((){
- buttons_visible = !buttons_visible;
- loader_visible = !loader_visible;
- });
- }
- _checkAuthStatus() async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- print('will attempt auto sign in');
- _performSignin(prefs.getString("auth_provider"));
- }
- _performSignin(String auth_provider) async {
- if(auth_provider==null){
- print('no auth info yet');
- _swapvisibility();
- return;
- }
- print('display buttons');
- _swapvisibility();
- if (auth_provider == 'facebook') _firebaseUser = await auth.signInWithFacebook();
- if (auth_provider == 'google') _firebaseUser = await auth.signInWithGoogle();
- }
- var linearGradient = new BoxDecoration(
- gradient: new LinearGradient(
- begin: FractionalOffset.centerRight,
- end: FractionalOffset.bottomLeft,
- colors: [
- const Color(0xFFCFD8DC),
- const Color(0xFF607D8B),
- ],
- ),
- );
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- body: new Container(
- decoration: linearGradient,
- child: new Center(
- child: new Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Opacity(
- opacity: loader_visible ? 1.0 : 0.0,
- child:
- new Container(
- padding: const EdgeInsets.all(32.0),
- child: new CircularProgressIndicator()
- )
- ),
- new Opacity(
- opacity: buttons_visible ? 1.0 : 0.0,
- child:
- new Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Container(
- width: 240.0,
- padding: const EdgeInsets.all(8.0),
- child:
- new RaisedButton.icon(
- icon: new Icon(FontAwesomeIcons.facebook),
- label: new Text('Sign in with Facebook'),
- onPressed: () {
- _performSignin('facebook');
- }
- )
- ),
- new Container(
- width: 240.0,
- padding: const EdgeInsets.all(8.0),
- child:
- new RaisedButton.icon(
- icon: new Icon(FontAwesomeIcons.google),
- label: new Text('Sign in with Google'),
- onPressed: () {
- _performSignin('google');
- }
- ),
- ),
- ]
- )
- )
- ]
- )
- )
- )
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement