Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created March 24, 2019 20:13
Show Gist options
  • Select an option

  • Save xsahil03x/633b29cc83c1a07874b02c2a98a978a6 to your computer and use it in GitHub Desktop.

Select an option

Save xsahil03x/633b29cc83c1a07874b02c2a98a978a6 to your computer and use it in GitHub Desktop.
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final FirebaseAuth _auth = FirebaseAuth.instance;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Firebase Auth Demo',
routes: {
'/phone': (context) => FlutterPhoneAuth(),
'/home': (context) => HomeScreen(),
},
home: FutureBuilder(
initialData: false,
future: _isUserLoggedIn(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
return snapshot.data ? HomeScreen() : FlutterPhoneAuth();
},
),
);
}
Future<bool> _isUserLoggedIn() async {
return await _auth.currentUser().then((user) {
if (user != null) {
return true;
} else
return false;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment