Skip to content

Instantly share code, notes, and snippets.

@BudhabhooshanPatil
Last active May 31, 2022 00:29
Show Gist options
  • Save BudhabhooshanPatil/0dad952f6906855a4f70cdec7488079f to your computer and use it in GitHub Desktop.
Save BudhabhooshanPatil/0dad952f6906855a4f70cdec7488079f to your computer and use it in GitHub Desktop.
## 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