From 00e53cfb052e64fb6551918b8c94e58a7501b078 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 29 Aug 2023 08:18:28 +0200 Subject: [PATCH] refactor(neon): use AppStorage in FirstLaunchBloc Signed-off-by: Nikolas Rimikis --- packages/neon/neon/lib/neon.dart | 1 - .../neon/neon/lib/src/blocs/first_launch.dart | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 22d99305..20c9cf2b 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -62,7 +62,6 @@ Future runNeon({ globalOptions, ); final firstLaunchBloc = FirstLaunchBloc( - sharedPreferences, disabled: firstLaunchDisabled, ); final nextPushBloc = NextPushBloc( diff --git a/packages/neon/neon/lib/src/blocs/first_launch.dart b/packages/neon/neon/lib/src/blocs/first_launch.dart index ed7c63f4..fef5589c 100644 --- a/packages/neon/neon/lib/src/blocs/first_launch.dart +++ b/packages/neon/neon/lib/src/blocs/first_launch.dart @@ -2,8 +2,8 @@ import 'dart:async'; import 'package:meta/meta.dart'; import 'package:neon/src/bloc/bloc.dart'; +import 'package:neon/src/settings/models/storage.dart'; import 'package:rxdart/rxdart.dart'; -import 'package:shared_preferences/shared_preferences.dart'; abstract class FirstLaunchBlocEvents {} @@ -11,20 +11,20 @@ abstract class FirstLaunchBlocStates { BehaviorSubject get onFirstLaunch; } +@immutable @internal class FirstLaunchBloc extends Bloc implements FirstLaunchBlocEvents, FirstLaunchBlocStates { - FirstLaunchBloc( - this._sharedPreferences, { + FirstLaunchBloc({ final bool disabled = false, - }) { - if (!disabled && !_sharedPreferences.containsKey(_keyFirstLaunch)) { + }) : _storage = AppStorage(_keyFirstLaunch) { + if (!disabled && !_storage.containsKey(_keyFirstLaunch)) { onFirstLaunch.add(null); - unawaited(_sharedPreferences.setBool(_keyFirstLaunch, false)); + unawaited(_storage.setBool(_keyFirstLaunch, false)); } } - final SharedPreferences _sharedPreferences; - final _keyFirstLaunch = 'first-launch'; + final AppStorage _storage; + static const _keyFirstLaunch = 'first-launch'; @override void dispose() { @@ -32,5 +32,5 @@ class FirstLaunchBloc extends Bloc implements FirstLaunchBlocEvents, FirstLaunch } @override - BehaviorSubject onFirstLaunch = BehaviorSubject(); + final BehaviorSubject onFirstLaunch = BehaviorSubject(); }