prepare for multiple apps
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'app_state.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class AppStateKey extends _$AppStateKey {
|
||||
void reset() {
|
||||
state = GlobalKey(debugLabel: 'RootKey');
|
||||
}
|
||||
|
||||
@override
|
||||
GlobalKey build() {
|
||||
return GlobalKey(debugLabel: 'RootKey');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'app_state.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(AppStateKey)
|
||||
final appStateKeyProvider = AppStateKeyProvider._();
|
||||
|
||||
final class AppStateKeyProvider
|
||||
extends $NotifierProvider<AppStateKey, GlobalKey<State<StatefulWidget>>> {
|
||||
AppStateKeyProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'appStateKeyProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$appStateKeyHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
AppStateKey create() => AppStateKey();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(GlobalKey<State<StatefulWidget>> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<GlobalKey<State<StatefulWidget>>>(
|
||||
value,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$appStateKeyHash() => r'113c208139d84cdd52f623c2c6298b430fc1a889';
|
||||
|
||||
abstract class _$AppStateKey
|
||||
extends $Notifier<GlobalKey<State<StatefulWidget>>> {
|
||||
GlobalKey<State<StatefulWidget>> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref =
|
||||
this.ref
|
||||
as $Ref<
|
||||
GlobalKey<State<StatefulWidget>>,
|
||||
GlobalKey<State<StatefulWidget>>
|
||||
>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<
|
||||
GlobalKey<State<StatefulWidget>>,
|
||||
GlobalKey<State<StatefulWidget>>
|
||||
>,
|
||||
GlobalKey<State<StatefulWidget>>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/design/app_colors.dart';
|
||||
|
||||
part 'defaults.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Color lightSeedColorFallback(Ref ref) => AppColors.light.seedColor;
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Color darkSeedColorFallback(Ref ref) => AppColors.dark.seedColor;
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Uri docsUri(Ref ref) => Uri.parse('https://docs.weblibre.eu/');
|
||||
@@ -0,0 +1,134 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'defaults.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(lightSeedColorFallback)
|
||||
final lightSeedColorFallbackProvider = LightSeedColorFallbackProvider._();
|
||||
|
||||
final class LightSeedColorFallbackProvider
|
||||
extends $FunctionalProvider<Color, Color, Color>
|
||||
with $Provider<Color> {
|
||||
LightSeedColorFallbackProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'lightSeedColorFallbackProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$lightSeedColorFallbackHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<Color> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Color create(Ref ref) {
|
||||
return lightSeedColorFallback(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(Color value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<Color>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$lightSeedColorFallbackHash() =>
|
||||
r'851efdcb11e4367ea2e54f1884a73fd4cd841d4a';
|
||||
|
||||
@ProviderFor(darkSeedColorFallback)
|
||||
final darkSeedColorFallbackProvider = DarkSeedColorFallbackProvider._();
|
||||
|
||||
final class DarkSeedColorFallbackProvider
|
||||
extends $FunctionalProvider<Color, Color, Color>
|
||||
with $Provider<Color> {
|
||||
DarkSeedColorFallbackProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'darkSeedColorFallbackProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$darkSeedColorFallbackHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<Color> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Color create(Ref ref) {
|
||||
return darkSeedColorFallback(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(Color value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<Color>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$darkSeedColorFallbackHash() =>
|
||||
r'161a8c4318108c31d5c300441bc3332d08c24496';
|
||||
|
||||
@ProviderFor(docsUri)
|
||||
final docsUriProvider = DocsUriProvider._();
|
||||
|
||||
final class DocsUriProvider extends $FunctionalProvider<Uri, Uri, Uri>
|
||||
with $Provider<Uri> {
|
||||
DocsUriProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'docsUriProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$docsUriHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<Uri> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
Uri create(Ref ref) {
|
||||
return docsUri(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(Uri value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<Uri>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$docsUriHash() => r'6456efcf97ddc7ee87a67e2d3380f7241e3d76ea';
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'device_info.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class AndroidDeviceInfo extends _$AndroidDeviceInfo {
|
||||
@override
|
||||
Future<AndroidDeviceInfoData?> build() async {
|
||||
if (!Platform.isAndroid) return null;
|
||||
|
||||
final deviceInfo = DeviceInfoPlugin();
|
||||
final androidInfo = await deviceInfo.androidInfo;
|
||||
|
||||
return AndroidDeviceInfoData(sdkInt: androidInfo.version.sdkInt);
|
||||
}
|
||||
}
|
||||
|
||||
class AndroidDeviceInfoData {
|
||||
final int sdkInt;
|
||||
|
||||
const AndroidDeviceInfoData({required this.sdkInt});
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'device_info.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(AndroidDeviceInfo)
|
||||
final androidDeviceInfoProvider = AndroidDeviceInfoProvider._();
|
||||
|
||||
final class AndroidDeviceInfoProvider
|
||||
extends $AsyncNotifierProvider<AndroidDeviceInfo, AndroidDeviceInfoData?> {
|
||||
AndroidDeviceInfoProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'androidDeviceInfoProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$androidDeviceInfoHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
AndroidDeviceInfo create() => AndroidDeviceInfo();
|
||||
}
|
||||
|
||||
String _$androidDeviceInfoHash() => r'05c6cc63a6ee34f137aef538d65e8ab94b9cca89';
|
||||
|
||||
abstract class _$AndroidDeviceInfo
|
||||
extends $AsyncNotifier<AndroidDeviceInfoData?> {
|
||||
FutureOr<AndroidDeviceInfoData?> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref =
|
||||
this.ref
|
||||
as $Ref<AsyncValue<AndroidDeviceInfoData?>, AndroidDeviceInfoData?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<
|
||||
AsyncValue<AndroidDeviceInfoData?>,
|
||||
AndroidDeviceInfoData?
|
||||
>,
|
||||
AsyncValue<AndroidDeviceInfoData?>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'format.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class Format extends _$Format {
|
||||
String fullDateTime(DateTime date) {
|
||||
final pattern = DateFormat('yMMMMd').addPattern('Hm');
|
||||
|
||||
return pattern.format(date);
|
||||
}
|
||||
|
||||
String shortDate(DateTime date) {
|
||||
return DateFormat('yyyy-MM-dd').format(date);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> build() async {
|
||||
await initializeDateFormatting();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'format.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(Format)
|
||||
final formatProvider = FormatProvider._();
|
||||
|
||||
final class FormatProvider extends $AsyncNotifierProvider<Format, void> {
|
||||
FormatProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'formatProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$formatHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
Format create() => Format();
|
||||
}
|
||||
|
||||
String _$formatHash() => r'695b94cc4b25596e4ef953d08ba954424a5ec33e';
|
||||
|
||||
abstract class _$Format extends $AsyncNotifier<void> {
|
||||
FutureOr<void> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<void>, void>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<void>, void>,
|
||||
AsyncValue<void>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/data/models/drag_data.dart';
|
||||
|
||||
part 'global_drop.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class WillAcceptDrop extends _$WillAcceptDrop {
|
||||
// ignore: use_setters_to_change_properties api decision
|
||||
void setData(DropTargetData data) {
|
||||
state = data;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
state = null;
|
||||
}
|
||||
|
||||
@override
|
||||
DropTargetData? build() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'global_drop.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(WillAcceptDrop)
|
||||
final willAcceptDropProvider = WillAcceptDropProvider._();
|
||||
|
||||
final class WillAcceptDropProvider
|
||||
extends $NotifierProvider<WillAcceptDrop, DropTargetData?> {
|
||||
WillAcceptDropProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'willAcceptDropProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$willAcceptDropHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
WillAcceptDrop create() => WillAcceptDrop();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(DropTargetData? value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<DropTargetData?>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$willAcceptDropHash() => r'97b47784ef9101757602b4408d1f545ef2308830';
|
||||
|
||||
abstract class _$WillAcceptDrop extends $Notifier<DropTargetData?> {
|
||||
DropTargetData? build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<DropTargetData?, DropTargetData?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<DropTargetData?, DropTargetData?>,
|
||||
DropTargetData?,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:riverpod/experimental/persist.dart';
|
||||
import 'package:riverpod_annotation/experimental/persist.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/features/user/data/providers.dart';
|
||||
|
||||
part 'persisted_bool.g.dart';
|
||||
|
||||
enum PersistedBoolKey {
|
||||
extensionsExpanded(key: 'ExtensionsExpanded', defaultValue: false),
|
||||
searchSuggestionsExpanded(
|
||||
key: 'SearchSuggestionsExpanded',
|
||||
defaultValue: true,
|
||||
),
|
||||
tabSuggestions(key: 'TabSuggestions', defaultValue: false);
|
||||
|
||||
const PersistedBoolKey({required this.key, required this.defaultValue});
|
||||
|
||||
final String key;
|
||||
final bool defaultValue;
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class PersistedBool extends _$PersistedBool {
|
||||
void toggle() => state = !state;
|
||||
|
||||
// ignore: use_setters_to_change_properties
|
||||
void set(bool value) => state = value;
|
||||
|
||||
@override
|
||||
bool build(PersistedBoolKey key) {
|
||||
persist(
|
||||
ref.watch(riverpodDatabaseStorageProvider),
|
||||
key: key.key,
|
||||
encode: (state) => jsonEncode([state]),
|
||||
decode: (encoded) => (jsonDecode(encoded) as List<dynamic>).first as bool,
|
||||
);
|
||||
|
||||
return stateOrNull ?? key.defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'persisted_bool.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(PersistedBool)
|
||||
final persistedBoolProvider = PersistedBoolFamily._();
|
||||
|
||||
final class PersistedBoolProvider
|
||||
extends $NotifierProvider<PersistedBool, bool> {
|
||||
PersistedBoolProvider._({
|
||||
required PersistedBoolFamily super.from,
|
||||
required PersistedBoolKey super.argument,
|
||||
}) : super(
|
||||
retry: null,
|
||||
name: r'persistedBoolProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$persistedBoolHash();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return r'persistedBoolProvider'
|
||||
''
|
||||
'($argument)';
|
||||
}
|
||||
|
||||
@$internal
|
||||
@override
|
||||
PersistedBool create() => PersistedBool();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(bool value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<bool>(value),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return other is PersistedBoolProvider && other.argument == argument;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return argument.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
String _$persistedBoolHash() => r'97fd7ed82dfde444fddf4475a3982be00f5f197a';
|
||||
|
||||
final class PersistedBoolFamily extends $Family
|
||||
with
|
||||
$ClassFamilyOverride<
|
||||
PersistedBool,
|
||||
bool,
|
||||
bool,
|
||||
bool,
|
||||
PersistedBoolKey
|
||||
> {
|
||||
PersistedBoolFamily._()
|
||||
: super(
|
||||
retry: null,
|
||||
name: r'persistedBoolProvider',
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
isAutoDispose: false,
|
||||
);
|
||||
|
||||
PersistedBoolProvider call(PersistedBoolKey key) =>
|
||||
PersistedBoolProvider._(argument: key, from: this);
|
||||
|
||||
@override
|
||||
String toString() => r'persistedBoolProvider';
|
||||
}
|
||||
|
||||
abstract class _$PersistedBool extends $Notifier<bool> {
|
||||
late final _$args = ref.$arg as PersistedBoolKey;
|
||||
PersistedBoolKey get key => _$args;
|
||||
|
||||
bool build(PersistedBoolKey key);
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<bool, bool>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<bool, bool>,
|
||||
bool,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, () => build(_$args));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:weblibre/core/providers/app_state.dart';
|
||||
import 'package:weblibre/core/routing/routes.dart';
|
||||
import 'package:weblibre/features/user/domain/providers/profile_auth.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/onboarding.dart';
|
||||
|
||||
part 'router.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
Future<GoRouter> router(Ref ref) async {
|
||||
ref.watch(appStateKeyProvider); //Rebuild router on key changes
|
||||
|
||||
final onboardingRepository = ref.read(onboardingRepositoryProvider.notifier);
|
||||
unawaited(ref.read(profileAuthStateProvider.notifier).bootstrapFromProfile());
|
||||
|
||||
String? initialLocation;
|
||||
|
||||
final onboardingMandatory = await onboardingRepository.isOutdated();
|
||||
|
||||
if (onboardingMandatory) {
|
||||
final current = await onboardingRepository.getCurrentRevision();
|
||||
|
||||
final route = OnboardingRoute(
|
||||
currentRevision: current ?? -1,
|
||||
targetRevision: OnboardingRepository.targetRevision,
|
||||
);
|
||||
|
||||
initialLocation = route.location;
|
||||
}
|
||||
|
||||
final profileAuthRefreshListenable = ref.watch(profileAuthProvider);
|
||||
|
||||
return GoRouter(
|
||||
debugLogDiagnostics: true,
|
||||
routes: $appRoutes,
|
||||
initialLocation: initialLocation ?? const LockRoute().location,
|
||||
refreshListenable: profileAuthRefreshListenable,
|
||||
redirect: (context, state) {
|
||||
final authenticated = ref.read(profileAuthStateProvider);
|
||||
final currentTopRouteName = state.topRoute?.name;
|
||||
final isOnLockRoute = currentTopRouteName == LockRoute.name;
|
||||
final isOnOnboarding = currentTopRouteName == OnboardingRoute.name;
|
||||
|
||||
// Don't redirect during onboarding
|
||||
if (isOnOnboarding) return null;
|
||||
|
||||
if (!authenticated && !isOnLockRoute) {
|
||||
return const LockRoute().location;
|
||||
}
|
||||
|
||||
if (authenticated && isOnLockRoute) {
|
||||
return const BrowserRoute().location;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class CurrentTopRoute extends _$CurrentTopRoute {
|
||||
@override
|
||||
RouteBase? build() {
|
||||
final router = ref.watch(routerProvider).value;
|
||||
if (router == null) return null;
|
||||
|
||||
GoRoute? getCurrentRoute() {
|
||||
final config = router.routerDelegate.currentConfiguration;
|
||||
|
||||
if (config.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final match = config.last;
|
||||
return match.route;
|
||||
}
|
||||
|
||||
void update() {
|
||||
unawaited(
|
||||
Future(() {
|
||||
state = getCurrentRoute();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
router.routerDelegate.addListener(update);
|
||||
ref.onDispose(() => router.routerDelegate.removeListener(update));
|
||||
|
||||
return getCurrentRoute();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'router.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(router)
|
||||
final routerProvider = RouterProvider._();
|
||||
|
||||
final class RouterProvider
|
||||
extends
|
||||
$FunctionalProvider<AsyncValue<GoRouter>, GoRouter, FutureOr<GoRouter>>
|
||||
with $FutureModifier<GoRouter>, $FutureProvider<GoRouter> {
|
||||
RouterProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'routerProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$routerHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$FutureProviderElement<GoRouter> $createElement($ProviderPointer pointer) =>
|
||||
$FutureProviderElement(pointer);
|
||||
|
||||
@override
|
||||
FutureOr<GoRouter> create(Ref ref) {
|
||||
return router(ref);
|
||||
}
|
||||
}
|
||||
|
||||
String _$routerHash() => r'4402ca2d7061945c395f3963d6bde29be8999f96';
|
||||
|
||||
@ProviderFor(CurrentTopRoute)
|
||||
final currentTopRouteProvider = CurrentTopRouteProvider._();
|
||||
|
||||
final class CurrentTopRouteProvider
|
||||
extends $NotifierProvider<CurrentTopRoute, RouteBase?> {
|
||||
CurrentTopRouteProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'currentTopRouteProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$currentTopRouteHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
CurrentTopRoute create() => CurrentTopRoute();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(RouteBase? value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<RouteBase?>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$currentTopRouteHash() => r'bf9956935ede399b815348926bb75c6bad22619e';
|
||||
|
||||
abstract class _$CurrentTopRoute extends $Notifier<RouteBase?> {
|
||||
RouteBase? build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<RouteBase?, RouteBase?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<RouteBase?, RouteBase?>,
|
||||
RouteBase?,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user