Persist navigation and sidebar visibility state

This commit is contained in:
Elias Bonnici 2024-06-14 14:04:12 +02:00
parent 0b8bcf8c67
commit 574e63e147
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF

View File

@ -22,6 +22,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:material_symbols_icons/symbols.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../core/state.dart';
import '../../management/models.dart';
@ -34,18 +35,23 @@ import 'keys.dart';
import 'navigation.dart';
final _navigationVisibilityProvider =
StateNotifierProvider<_VisibilityNotifier, bool>(
(ref) => _VisibilityNotifier());
StateNotifierProvider<_VisibilityNotifier, bool>((ref) =>
_VisibilityNotifier('NAVIGATION_VISIBILITY', ref.watch(prefProvider)));
final _detailViewVisibilityProvider =
StateNotifierProvider<_VisibilityNotifier, bool>(
(ref) => _VisibilityNotifier());
StateNotifierProvider<_VisibilityNotifier, bool>((ref) =>
_VisibilityNotifier('DETAIL_VIEW_VISIBILITY', ref.watch(prefProvider)));
class _VisibilityNotifier extends StateNotifier<bool> {
_VisibilityNotifier() : super(true);
final String _key;
final SharedPreferences _prefs;
_VisibilityNotifier(this._key, this._prefs)
: super(_prefs.getBool(_key) ?? true);
void toggleExpanded() {
state = !state;
final newValue = !state;
state = newValue;
_prefs.setBool(_key, newValue);
}
}
@ -693,8 +699,8 @@ class _AppPageState extends ConsumerState<AppPage> {
),
),
if (widget.actionButtonBuilder == null &&
(widget.keyActionsBuilder != null && !hasManage ||
!showDetailView))
(widget.keyActionsBuilder != null &&
(!hasManage || !showDetailView)))
Padding(
padding: const EdgeInsets.only(left: 4),
child: IconButton(