Last active
May 31, 2022 00:29
-
-
Save BudhabhooshanPatil/0dad952f6906855a4f70cdec7488079f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Run this command to add this package as a library: | |
## --> flutter pub add shared_preferences | |
import 'package:flutter/material.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
Future<void> main() async { | |
WidgetsFlutterBinding.ensureInitialized(); | |
final SharedPreferences prefs = await SharedPreferences.getInstance(); | |
var isLoggedIn = (prefs.getBool('isLoggedIn') == null) | |
? false | |
: prefs.getBool('isLoggedIn'); | |
runApp(MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: isLoggedIn ? DashboardPage() : LoginPage(), | |
)); | |
} | |
class DashboardPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.blue, | |
); | |
} | |
} | |
class LoginPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.amber, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment