Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:legal_legend/constants/strings.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- class SharedPrefs {
- static SharedPreferences _sharedPrefs;
- init() async {
- if (_sharedPrefs == null) {
- _sharedPrefs = await SharedPreferences.getInstance();
- }
- }
- List<int> get serviceItem => [];
- set serviceItem(List<int> serviceItem) {
- }
- int get userId => _sharedPrefs.getInt(keyUserId) ?? 0;
- set userId(int value) {
- _sharedPrefs.setInt(keyUserId, value);
- }
- String get userName => _sharedPrefs.getString(keyUsername) ?? null;
- set userName(String value) {
- _sharedPrefs.setString(keyUsername, value);
- }
- String get accessToken => _sharedPrefs.getString(keyAccessToken) ?? null;
- set accessToken(String value) {
- _sharedPrefs.setString(keyAccessToken, value);
- }
- bool get isLoggedIn => _sharedPrefs.getBool(keyIsUserLoggedIn) ?? false;
- set isLoggedIn(bool value) {
- _sharedPrefs.setBool(keyIsUserLoggedIn, value);
- }
- }
- final sharedPrefs = SharedPrefs();
- //--------------- main.dart ---------------//
- Future<void> main() async {
- WidgetsFlutterBinding.ensureInitialized();
- await sharedPrefs.init();
- runApp(MyApp());
- }
Add Comment
Please, Sign In to add comment