mirror of
https://github.com/zapstore/zapstore.git
synced 2026-10-05 20:48:24 +00:00
Keep dbVersion in sharedprefs
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter_data/flutter_data.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:zapstore/main.dart';
|
||||
import 'package:zapstore/models/user.dart';
|
||||
|
||||
part 'settings.g.dart';
|
||||
@@ -12,8 +11,6 @@ class Settings extends DataModel<Settings> {
|
||||
String get id => '_';
|
||||
final BelongsTo<User> user = BelongsTo();
|
||||
bool isLoggedIn = false;
|
||||
@JsonKey(defaultValue: 1)
|
||||
int dbVersion = kDbVersion;
|
||||
}
|
||||
|
||||
mixin SettingsAdapter on Adapter<Settings> {
|
||||
|
||||
@@ -60,11 +60,9 @@ extension SettingsRelationshipGraphNodeX on RelationshipGraphNode<Settings> {
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Settings _$SettingsFromJson(Map<String, dynamic> json) => Settings()
|
||||
..isLoggedIn = json['isLoggedIn'] as bool
|
||||
..dbVersion = (json['dbVersion'] as num?)?.toInt() ?? 1;
|
||||
Settings _$SettingsFromJson(Map<String, dynamic> json) =>
|
||||
Settings()..isLoggedIn = json['isLoggedIn'] as bool;
|
||||
|
||||
Map<String, dynamic> _$SettingsToJson(Settings instance) => <String, dynamic>{
|
||||
'isLoggedIn': instance.isLoggedIn,
|
||||
'dbVersion': instance.dbVersion,
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_data/flutter_data.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:zapstore/main.dart';
|
||||
import 'package:zapstore/main.data.dart';
|
||||
import 'package:zapstore/models/app.dart';
|
||||
@@ -11,15 +12,20 @@ import 'package:zapstore/widgets/app_curation_container.dart';
|
||||
AppLifecycleListener? _lifecycleListener;
|
||||
|
||||
final appInitializer = FutureProvider<void>((ref) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final dbVersion = prefs.getInt('dbVersion');
|
||||
|
||||
// Perform migration
|
||||
if (dbVersion == null || dbVersion < kDbVersion) {
|
||||
final storage = ref.read(localStorageProvider);
|
||||
await storage.initialize(inIsolate: true);
|
||||
await storage.destroy();
|
||||
await prefs.setInt('dbVersion', kDbVersion);
|
||||
}
|
||||
|
||||
// Initialize Flutter Data
|
||||
await ref.read(initializeFlutterData(adapterProvidersMap).future);
|
||||
|
||||
// Check DB version
|
||||
final userDbVersion = ref.settings.findOneLocalById('_')!.dbVersion;
|
||||
if (userDbVersion < kDbVersion) {
|
||||
await ref.read(localStorageProvider).destroy();
|
||||
}
|
||||
|
||||
_lifecycleListener = AppLifecycleListener(
|
||||
onStateChange: (state) async {
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import Foundation
|
||||
import app_links
|
||||
import device_info_plus
|
||||
import path_provider_foundation
|
||||
import shared_preferences_foundation
|
||||
import sqflite
|
||||
import sqlite3_flutter_libs
|
||||
import url_launcher_macos
|
||||
@@ -16,6 +17,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
AppLinksMacosPlugin.register(with: registry.registrar(forPlugin: "AppLinksMacosPlugin"))
|
||||
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
||||
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
|
||||
@@ -962,6 +962,62 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.28.0"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "746e5369a43170c25816cc472ee016d3a66bc13fcf430c0bc41ad7b4b2922051"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: "480ba4345773f56acda9abf5f50bd966f581dac5d514e5fc4a18c62976bbba7e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: "07e050c7cd39bad516f8d64c455f04508d09df104be326d8c02551590a0d513d"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.3"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: d2ca4132d3946fec2184261726b355836a82c33d7d5b67af32692aff18a4684e
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.2"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -48,6 +48,7 @@ dependencies:
|
||||
dart_emoji: ^0.2.0+2
|
||||
remove_markdown: ^0.0.2
|
||||
install_plugin: ^2.1.0
|
||||
shared_preferences: ^2.3.2
|
||||
|
||||
dependency_overrides:
|
||||
purplebase:
|
||||
|
||||
Reference in New Issue
Block a user