import 'package:flutter_riverpod/flutter_riverpod.dart'; enum DesktopContent { workspace, library, resourceLibrary, workflow, settings } typedef DesktopContentSelection = ({ DesktopContent surface, int settingsTab, int settingsRequest, (String, String)? workspace, bool settingsVisited, bool resourcesSelected, bool librarySelected, }); final desktopContentProvider = NotifierProvider( DesktopContentController.new, ); /// Navigation changes visibility without disposing any visited content. class DesktopContentController extends Notifier { DesktopContent _settingsReturnSurface = DesktopContent.workspace; @override DesktopContentSelection build() => ( surface: DesktopContent.workspace, settingsTab: 0, settingsRequest: 0, workspace: null, settingsVisited: false, resourcesSelected: false, librarySelected: false, ); void select(DesktopContent surface) { state = ( surface: surface, settingsTab: state.settingsTab, settingsRequest: state.settingsRequest, workspace: state.workspace, settingsVisited: state.settingsVisited || surface == DesktopContent.settings, resourcesSelected: surface == DesktopContent.library, librarySelected: surface == DesktopContent.resourceLibrary, ); } void showSettings({int? tab, (String, String)? workspace}) { if (state.surface != DesktopContent.settings) { _settingsReturnSurface = state.surface; } state = ( surface: DesktopContent.settings, settingsTab: tab ?? state.settingsTab, settingsRequest: state.settingsRequest + (tab == null ? 0 : 1), workspace: workspace ?? state.workspace, settingsVisited: true, resourcesSelected: state.resourcesSelected, librarySelected: state.librarySelected, ); } void closeSettings() { if (state.surface == DesktopContent.settings) { select(_settingsReturnSurface); } } }