Browse Source

refactor(neon): use AppStorage in FirstLaunchBloc

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/654/head
Nikolas Rimikis 1 year ago
parent
commit
00e53cfb05
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 1
      packages/neon/neon/lib/neon.dart
  2. 18
      packages/neon/neon/lib/src/blocs/first_launch.dart

1
packages/neon/neon/lib/neon.dart

@ -62,7 +62,6 @@ Future runNeon({
globalOptions, globalOptions,
); );
final firstLaunchBloc = FirstLaunchBloc( final firstLaunchBloc = FirstLaunchBloc(
sharedPreferences,
disabled: firstLaunchDisabled, disabled: firstLaunchDisabled,
); );
final nextPushBloc = NextPushBloc( final nextPushBloc = NextPushBloc(

18
packages/neon/neon/lib/src/blocs/first_launch.dart

@ -2,8 +2,8 @@ import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/settings/models/storage.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:shared_preferences/shared_preferences.dart';
abstract class FirstLaunchBlocEvents {} abstract class FirstLaunchBlocEvents {}
@ -11,20 +11,20 @@ abstract class FirstLaunchBlocStates {
BehaviorSubject get onFirstLaunch; BehaviorSubject get onFirstLaunch;
} }
@immutable
@internal @internal
class FirstLaunchBloc extends Bloc implements FirstLaunchBlocEvents, FirstLaunchBlocStates { class FirstLaunchBloc extends Bloc implements FirstLaunchBlocEvents, FirstLaunchBlocStates {
FirstLaunchBloc( FirstLaunchBloc({
this._sharedPreferences, {
final bool disabled = false, final bool disabled = false,
}) { }) : _storage = AppStorage(_keyFirstLaunch) {
if (!disabled && !_sharedPreferences.containsKey(_keyFirstLaunch)) { if (!disabled && !_storage.containsKey(_keyFirstLaunch)) {
onFirstLaunch.add(null); onFirstLaunch.add(null);
unawaited(_sharedPreferences.setBool(_keyFirstLaunch, false)); unawaited(_storage.setBool(_keyFirstLaunch, false));
} }
} }
final SharedPreferences _sharedPreferences; final AppStorage _storage;
final _keyFirstLaunch = 'first-launch'; static const _keyFirstLaunch = 'first-launch';
@override @override
void dispose() { void dispose() {
@ -32,5 +32,5 @@ class FirstLaunchBloc extends Bloc implements FirstLaunchBlocEvents, FirstLaunch
} }
@override @override
BehaviorSubject onFirstLaunch = BehaviorSubject(); final BehaviorSubject onFirstLaunch = BehaviorSubject();
} }

Loading…
Cancel
Save