use provider to keep logfilter alive

This commit is contained in:
Fabian Freund
2026-01-21 15:18:52 +01:00
parent b573ed5645
commit 9155b9bace
3 changed files with 120 additions and 14 deletions
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024-2025 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:logger/logger.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'log_filter.g.dart';
@Riverpod(keepAlive: true)
class LogFilter extends _$LogFilter {
@override
Level build() {
return Level.all;
}
// ignore: use_setters_to_change_properties
void setFilter(Level level) {
state = level;
}
}
@@ -0,0 +1,61 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'log_filter.dart';
// **************************************************************************
// RiverpodGenerator
// **************************************************************************
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint, type=warning
@ProviderFor(LogFilter)
final logFilterProvider = LogFilterProvider._();
final class LogFilterProvider extends $NotifierProvider<LogFilter, Level> {
LogFilterProvider._()
: super(
from: null,
argument: null,
retry: null,
name: r'logFilterProvider',
isAutoDispose: false,
dependencies: null,
$allTransitiveDependencies: null,
);
@override
String debugGetCreateSourceHash() => _$logFilterHash();
@$internal
@override
LogFilter create() => LogFilter();
/// {@macro riverpod.override_with_value}
Override overrideWithValue(Level value) {
return $ProviderOverride(
origin: this,
providerOverride: $SyncValueProvider<Level>(value),
);
}
}
String _$logFilterHash() => r'b2ee125735571998293b0396907938c38a54d0b5';
abstract class _$LogFilter extends $Notifier<Level> {
Level build();
@$mustCallSuper
@override
void runBuild() {
final ref = this.ref as $Ref<Level, Level>;
final element =
ref.element
as $ClassProviderElement<
AnyNotifier<Level, Level>,
Level,
Object?,
Object?
>;
element.handleCreate(ref, build);
}
}