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,
);
final firstLaunchBloc = FirstLaunchBloc(
sharedPreferences,
disabled: firstLaunchDisabled,
);
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: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();
}

Loading…
Cancel
Save