refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import 'dart:async';
|
||||
@@ -7,9 +8,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../app/adaptive/desktop_workspace_controller.dart';
|
||||
import '../../app/adaptive/desktop_content_controller.dart';
|
||||
import '../settings/settings_content.dart';
|
||||
import '../../app/adaptive/workspace_layout_policy.dart';
|
||||
import '../../app/shells/phone_workspace_shell.dart';
|
||||
import '../../app/shells/desktop_workspace_shell.dart';
|
||||
import '../../app/shells/desktop_window_frame.dart';
|
||||
import '../../app/shells/tablet_workspace_shell.dart';
|
||||
import '../../integrations/platform/device_experience.dart';
|
||||
import '../../integrations/platform/editor_window_chrome.dart';
|
||||
@@ -30,8 +34,9 @@ import '../../workspace/workspace_session_scope.dart';
|
||||
import '../assistant/workspace_agent_surface.dart';
|
||||
import '../editor/background_tasks_button.dart';
|
||||
import '../editor/editor_page.dart';
|
||||
import '../settings/settings_dialog.dart';
|
||||
import '../settings/settings_page.dart';
|
||||
import 'editor_loading_region.dart';
|
||||
import 'project_switch_region.dart';
|
||||
import 'project_sidebar.dart';
|
||||
import 'widgets/name_dialog.dart';
|
||||
|
||||
@@ -103,7 +108,7 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
if (!created && context.mounted) {
|
||||
final error = ref.read(projectsProvider).value?.error;
|
||||
if (error?.requiresProjectLocation == true) {
|
||||
await showSettingsDialog(context);
|
||||
await showSettingsPage(context);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -113,10 +118,13 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
.pickDirectory(confirmButtonText: context.l10n.openProject);
|
||||
if (directory == null || !context.mounted) return;
|
||||
await ref.read(projectsProvider.notifier).open(directory);
|
||||
} catch (_) {
|
||||
} catch (error) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(context.l10n.selectDirectoryFailed)),
|
||||
ErrorNotificationHost.of(context).show(
|
||||
ErrorNotification(
|
||||
content: Text(context.l10n.selectDirectoryFailed),
|
||||
details: error.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -174,10 +182,11 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
ref.watch(workspaceNavigationProvider);
|
||||
final experience = ref.watch(deviceExperienceProvider);
|
||||
final desktop = experience == DeviceExperience.desktop;
|
||||
final contentSelection = ref.watch(desktopContentProvider);
|
||||
final projects = ref.watch(projectsProvider);
|
||||
final state = projects.value ?? const ProjectState();
|
||||
return EditorWindowChrome(
|
||||
headerHeight: desktop ? AppControlSize.panelHeader : 48,
|
||||
headerHeight: desktop ? DesktopWindowFrame.headerHeight : 48,
|
||||
builder: (context, integrated) => Scaffold(
|
||||
body: SafeArea(
|
||||
top: !integrated,
|
||||
@@ -195,120 +204,138 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
final navigationHiddenBySpace =
|
||||
desktop &&
|
||||
!WorkspaceLayoutPolicy.desktopNavigationFits(
|
||||
constraints.maxWidth,
|
||||
constraints.maxWidth -
|
||||
DesktopWindowFrame.railWidth -
|
||||
DesktopWindowFrame.contentInset,
|
||||
);
|
||||
final navigationCollapsed =
|
||||
_sidebarCollapsed || navigationHiddenBySpace;
|
||||
Widget controlSlot(Widget child) {
|
||||
if (!desktop) {
|
||||
return SizedBox.square(
|
||||
dimension: 48,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
const buttonSize = AppControlSize.headerButton;
|
||||
return SizedBox(
|
||||
width: buttonSize,
|
||||
height: buttonSize,
|
||||
child: Center(
|
||||
child: IconButtonTheme(
|
||||
data: IconButtonThemeData(
|
||||
style: Theme.of(context)
|
||||
.iconButtonTheme
|
||||
.style
|
||||
?.copyWith(
|
||||
fixedSize:
|
||||
const WidgetStatePropertyAll(
|
||||
Size.square(buttonSize),
|
||||
),
|
||||
minimumSize:
|
||||
const WidgetStatePropertyAll(
|
||||
Size.square(buttonSize),
|
||||
),
|
||||
maximumSize:
|
||||
const WidgetStatePropertyAll(
|
||||
Size.square(buttonSize),
|
||||
),
|
||||
padding:
|
||||
const WidgetStatePropertyAll(
|
||||
EdgeInsets.zero,
|
||||
),
|
||||
tapTargetSize: MaterialTapTargetSize
|
||||
.shrinkWrap,
|
||||
),
|
||||
),
|
||||
child: SizedBox.square(
|
||||
dimension: buttonSize,
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget controls({
|
||||
bool navigationToggle = true,
|
||||
}) => HeaderControlRegion(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: AppSpacing.tiny,
|
||||
children: [
|
||||
if (navigationToggle)
|
||||
SizedBox.square(
|
||||
dimension: AppControlSize.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key(
|
||||
'project-sidebar-toggle',
|
||||
),
|
||||
tooltip: navigationCollapsed
|
||||
? context.l10n.expandSidebar
|
||||
: context.l10n.collapseSidebar,
|
||||
onPressed: () {
|
||||
if (navigationHiddenBySpace) {
|
||||
_desktopScaffoldKey.currentState
|
||||
?.openDrawer();
|
||||
} else {
|
||||
_sidebarCollapsed =
|
||||
!_sidebarCollapsed;
|
||||
_saveViewState();
|
||||
}
|
||||
},
|
||||
style: sidebarActionButtonStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.view_sidebar_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (desktop &&
|
||||
navigationCollapsed &&
|
||||
navigationToggle)
|
||||
PopupMenuButton<WorkspaceMode>(
|
||||
key: const Key('desktop-workspace-mode'),
|
||||
initialValue: _mode,
|
||||
onSelected: _setMode,
|
||||
itemBuilder: (context) => [
|
||||
for (final mode in WorkspaceMode.values)
|
||||
PopupMenuItem(
|
||||
key: ValueKey(
|
||||
'desktop-mode-${mode.name}',
|
||||
),
|
||||
value: mode,
|
||||
child: Text(
|
||||
mode == WorkspaceMode.agent
|
||||
? context.l10n.workspaceAgent
|
||||
: context.l10n.workspaceCut,
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: desktop
|
||||
? (DesktopWindowFrame.railWidth -
|
||||
AppControlSize.headerButton) /
|
||||
2
|
||||
: 0,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
spacing: AppSpacing.tiny,
|
||||
children: [
|
||||
if (navigationToggle)
|
||||
controlSlot(
|
||||
IconButton(
|
||||
key: const Key(
|
||||
'project-sidebar-toggle',
|
||||
),
|
||||
tooltip: navigationCollapsed
|
||||
? context.l10n.expandSidebar
|
||||
: context.l10n.collapseSidebar,
|
||||
onPressed: () {
|
||||
if (navigationHiddenBySpace) {
|
||||
_desktopScaffoldKey.currentState
|
||||
?.openDrawer();
|
||||
} else {
|
||||
_sidebarCollapsed =
|
||||
!_sidebarCollapsed;
|
||||
_saveViewState();
|
||||
}
|
||||
},
|
||||
style: sidebarActionButtonStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.view_sidebar_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
_mode == WorkspaceMode.agent
|
||||
? context.l10n.workspaceAgent
|
||||
: context.l10n.workspaceCut,
|
||||
),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox.square(
|
||||
dimension: desktop
|
||||
? AppControlSize.headerButton
|
||||
: 48,
|
||||
child: IconButton(
|
||||
key: const Key('project-settings-button'),
|
||||
tooltip: context.l10n.settings,
|
||||
onPressed: () =>
|
||||
showSettingsDialog(context),
|
||||
style: sidebarActionButtonStyle(context),
|
||||
icon: const Icon(
|
||||
Icons.settings_outlined,
|
||||
size: AppIconSize.header,
|
||||
if (!desktop)
|
||||
SizedBox.square(
|
||||
dimension: desktop
|
||||
? AppControlSize.headerButton
|
||||
: 48,
|
||||
child: IconButton(
|
||||
key: const Key(
|
||||
'project-settings-button',
|
||||
),
|
||||
tooltip: context.l10n.settings,
|
||||
onPressed: () =>
|
||||
showSettingsPage(context),
|
||||
style: sidebarActionButtonStyle(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.settings_outlined,
|
||||
size: AppIconSize.header,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox.square(
|
||||
dimension: desktop
|
||||
? AppControlSize.headerButton
|
||||
: 48,
|
||||
child: const BackgroundTasksButton(),
|
||||
),
|
||||
],
|
||||
controlSlot(const BackgroundTasksButton()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
Widget leading() => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (navigationCollapsed && integrated)
|
||||
if (!desktop &&
|
||||
navigationCollapsed &&
|
||||
integrated)
|
||||
SizedBox(
|
||||
width: EditorWindowChrome.leadingWidth,
|
||||
),
|
||||
if (navigationCollapsed) controls(),
|
||||
if (!desktop && navigationCollapsed) controls(),
|
||||
const SizedBox(width: AppSpacing.compact),
|
||||
],
|
||||
);
|
||||
@@ -330,19 +357,43 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
onCreateProject: () =>
|
||||
_selectProject(context, ref, create: true),
|
||||
);
|
||||
void selectSidebar(bool resources) {
|
||||
ref
|
||||
.read(desktopContentProvider.notifier)
|
||||
.select(
|
||||
resources
|
||||
? DesktopContent.library
|
||||
: DesktopContent.workspace,
|
||||
);
|
||||
setState(() => _sidebarCollapsed = false);
|
||||
_saveViewState();
|
||||
if (navigationHiddenBySpace) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((
|
||||
_,
|
||||
) {
|
||||
if (mounted) {
|
||||
_desktopScaffoldKey.currentState
|
||||
?.openDrawer();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget navigation({
|
||||
DesktopWorkspaceGeometry? geometry,
|
||||
VoidCallback? expandEditor,
|
||||
bool drawer = false,
|
||||
}) => ProjectSidebar(
|
||||
experience: experience,
|
||||
resourcesSelected:
|
||||
desktop && contentSelection.resourcesSelected,
|
||||
key: drawer
|
||||
? _drawerNavigationKey
|
||||
: _navigationKey,
|
||||
agent: desktop && !drawer
|
||||
? agent
|
||||
: const SizedBox.shrink(),
|
||||
navigationOnly: !desktop || drawer,
|
||||
navigationOnly: true,
|
||||
onNavigationComplete: desktop && !drawer
|
||||
? null
|
||||
: () => Navigator.of(context).maybePop(),
|
||||
@@ -359,14 +410,15 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
state: state,
|
||||
selectedProjectId:
|
||||
_selectedProjectId ?? state.activeProject?.id,
|
||||
integratedTitlebar: integrated,
|
||||
integratedTitlebar: !desktop && integrated,
|
||||
externalWindowFrame: desktop && !drawer,
|
||||
onCreateProject: () =>
|
||||
_selectProject(context, ref, create: true),
|
||||
onSelectProject: selectProject,
|
||||
onRenameProject: (project) =>
|
||||
_renameProject(context, ref, project),
|
||||
headerControls: desktop && !drawer
|
||||
? controls()
|
||||
? const SizedBox.shrink()
|
||||
: HeaderControlRegion(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -386,61 +438,210 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
),
|
||||
),
|
||||
);
|
||||
final editor = ProjectLoadingRegion(
|
||||
loading: _switchingProject,
|
||||
child:
|
||||
state.activeProject != null &&
|
||||
state.timeline != null
|
||||
? EditorWorkspace(
|
||||
key: _editorKey,
|
||||
experience: experience,
|
||||
projectId: state.activeProject!.id,
|
||||
timelineId: state.timeline!.id,
|
||||
projectName: state.activeProject!.name,
|
||||
showProjectName:
|
||||
desktop && _mode == WorkspaceMode.cut,
|
||||
integratedTitlebar: desktop && integrated,
|
||||
headerLeading:
|
||||
desktop && _mode == WorkspaceMode.cut
|
||||
? leading()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
)
|
||||
: EmptyEditor(
|
||||
state: state,
|
||||
showProjectName:
|
||||
desktop && _mode == WorkspaceMode.cut,
|
||||
headerLeading:
|
||||
desktop && _mode == WorkspaceMode.cut
|
||||
? leading()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
),
|
||||
final pendingProject = _switchingProject
|
||||
? state.recent
|
||||
.where(
|
||||
(item) => item.id == _selectedProjectId,
|
||||
)
|
||||
.firstOrNull
|
||||
: null;
|
||||
final projectLoading =
|
||||
pendingProject != null &&
|
||||
pendingProject.id != state.activeProject?.id;
|
||||
final editor = ProjectSwitchRegion(
|
||||
pendingProjectId: projectLoading
|
||||
? pendingProject.id
|
||||
: null,
|
||||
builder: (context, showDefaults) {
|
||||
final displayDefaults =
|
||||
projectLoading && showDefaults;
|
||||
final visibleProject = displayDefaults
|
||||
? pendingProject
|
||||
: state.activeProject;
|
||||
return visibleProject != null &&
|
||||
(displayDefaults ||
|
||||
state.timeline != null)
|
||||
? EditorWorkspace(
|
||||
key: _editorKey,
|
||||
experience: experience,
|
||||
projectId: visibleProject.id,
|
||||
timelineId: displayDefaults
|
||||
? ''
|
||||
: state.timeline!.id,
|
||||
projectName: visibleProject.name,
|
||||
projectLoading: displayDefaults,
|
||||
showProjectName:
|
||||
desktop &&
|
||||
_mode == WorkspaceMode.cut,
|
||||
integratedTitlebar: false,
|
||||
headerLeading: desktop
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
)
|
||||
: EmptyEditor(
|
||||
desktop: desktop,
|
||||
state: state,
|
||||
showProjectName:
|
||||
desktop &&
|
||||
_mode == WorkspaceMode.cut,
|
||||
headerLeading: desktop
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: AppSpacing.compact,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
Widget contentSurface(
|
||||
DesktopContent surface,
|
||||
Widget child,
|
||||
) => ExcludeFocus(
|
||||
excluding:
|
||||
(contentSelection.surface ==
|
||||
DesktopContent.settings) !=
|
||||
(surface == DesktopContent.settings),
|
||||
child: TickerMode(
|
||||
enabled:
|
||||
(contentSelection.surface ==
|
||||
DesktopContent.settings) ==
|
||||
(surface == DesktopContent.settings),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
Widget desktopContents(
|
||||
Widget workspace,
|
||||
) => IndexedStack(
|
||||
index:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.settings
|
||||
? 1
|
||||
: 0,
|
||||
children: [
|
||||
contentSurface(
|
||||
DesktopContent.workspace,
|
||||
workspace,
|
||||
),
|
||||
contentSurface(
|
||||
DesktopContent.settings,
|
||||
contentSelection.settingsVisited
|
||||
? SizedBox(
|
||||
key: const Key(
|
||||
'desktop-settings-workspace',
|
||||
),
|
||||
child: SettingsContent(
|
||||
cardLayout: true,
|
||||
initialTab:
|
||||
contentSelection.settingsTab,
|
||||
navigationRequest: contentSelection
|
||||
.settingsRequest,
|
||||
workspace:
|
||||
contentSelection.workspace,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
],
|
||||
);
|
||||
return switch (experience) {
|
||||
DeviceExperience.desktop => DesktopWorkspaceShell(
|
||||
controller: _desktopSplits,
|
||||
scaffoldKey: _desktopScaffoldKey,
|
||||
navigationDrawer: navigation(drawer: true),
|
||||
mode: _mode,
|
||||
sidebarCollapsed: navigationCollapsed,
|
||||
sidebarWidth: _sidebarWidthOverride,
|
||||
onSidebarCollapsedChanged: (value) {
|
||||
_sidebarCollapsed = value;
|
||||
_saveViewState();
|
||||
DeviceExperience.desktop => DesktopWindowFrame(
|
||||
integratedTitlebar: integrated,
|
||||
headerControls: controls(),
|
||||
librarySelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.library,
|
||||
settingsSelected:
|
||||
contentSelection.surface ==
|
||||
DesktopContent.settings,
|
||||
onModeChanged: (mode) {
|
||||
selectSidebar(false);
|
||||
_setMode(mode);
|
||||
},
|
||||
onSidebarWidthChanged: (value) {
|
||||
_sidebarWidthOverride = value;
|
||||
_saveViewState();
|
||||
},
|
||||
sidebarBuilder: (geometry, expand) =>
|
||||
navigation(
|
||||
geometry: geometry,
|
||||
expandEditor: expand,
|
||||
onLibraryPressed: () => selectSidebar(true),
|
||||
onSettingsPressed: () =>
|
||||
showSettingsPage(context),
|
||||
child: desktopContents(
|
||||
DesktopWorkspaceShell(
|
||||
controller: _desktopSplits,
|
||||
scaffoldKey: _desktopScaffoldKey,
|
||||
navigationDrawer: navigation(drawer: true),
|
||||
mode: _mode,
|
||||
sidebarCollapsed: navigationCollapsed,
|
||||
sidebarWidth: _sidebarWidthOverride,
|
||||
onSidebarCollapsedChanged: (value) {
|
||||
_sidebarCollapsed = value;
|
||||
_saveViewState();
|
||||
},
|
||||
onSidebarWidthChanged: (value) {
|
||||
_sidebarWidthOverride = value;
|
||||
_saveViewState();
|
||||
},
|
||||
sidebarBuilder: (geometry, expand) =>
|
||||
navigation(
|
||||
geometry: geometry,
|
||||
expandEditor: expand,
|
||||
),
|
||||
agentBuilder: (geometry, expand) => Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
key: const Key(
|
||||
'agent-content-header',
|
||||
),
|
||||
height: AppControlSize.panelToolbar,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
AppSpacing.gap,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Spacer(),
|
||||
HeaderControlRegion(
|
||||
child: SizedBox.square(
|
||||
dimension: AppControlSize
|
||||
.headerButton,
|
||||
child: IconButton(
|
||||
key: const Key(
|
||||
'agent-fullscreen-button',
|
||||
),
|
||||
isSelected:
|
||||
geometry.editorHidden,
|
||||
tooltip:
|
||||
geometry.editorHidden
|
||||
? context
|
||||
.l10n
|
||||
.exitPreviewFullscreen
|
||||
: context
|
||||
.l10n
|
||||
.agentFullscreen,
|
||||
onPressed:
|
||||
geometry.editorHidden
|
||||
? expand
|
||||
: () => _desktopSplits
|
||||
.setAgentFullscreen(
|
||||
true,
|
||||
),
|
||||
icon: Icon(
|
||||
size:
|
||||
AppIconSize.header,
|
||||
geometry.editorHidden
|
||||
? Icons
|
||||
.fullscreen_exit
|
||||
: Icons.fullscreen,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(child: agent),
|
||||
],
|
||||
),
|
||||
editor: editor,
|
||||
editor: editor,
|
||||
),
|
||||
),
|
||||
),
|
||||
DeviceExperience.tablet => TabletWorkspaceShell(
|
||||
mode: _mode,
|
||||
@@ -472,10 +673,11 @@ class _EditingPageState extends ConsumerState<EditingPage> {
|
||||
PositionedDirectional(
|
||||
top: AppSpacing.compact,
|
||||
end: AppSpacing.compact,
|
||||
child: _SonnerErrorToast(
|
||||
child: ErrorFailureListener(
|
||||
message: projects.hasError
|
||||
? const AppFailure(
|
||||
? AppFailure(
|
||||
AppErrorCode.loadProjectsFailed,
|
||||
diagnostic: projects.error.toString(),
|
||||
)
|
||||
: state.error,
|
||||
),
|
||||
@@ -542,123 +744,3 @@ class _StartupLoadingState extends State<_StartupLoading>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _SonnerErrorToast extends StatefulWidget {
|
||||
const _SonnerErrorToast({required this.message});
|
||||
|
||||
final AppFailure? message;
|
||||
|
||||
@override
|
||||
State<_SonnerErrorToast> createState() => _SonnerErrorToastState();
|
||||
}
|
||||
|
||||
class _SonnerErrorToastState extends State<_SonnerErrorToast> {
|
||||
static const _displayDuration = Duration(seconds: 6);
|
||||
|
||||
Timer? _timer;
|
||||
AppFailure? _displayedMessage;
|
||||
bool _visible = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_show(widget.message);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _SonnerErrorToast oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.message != null &&
|
||||
(oldWidget.message == null || widget.message != oldWidget.message)) {
|
||||
_show(widget.message);
|
||||
}
|
||||
}
|
||||
|
||||
void _show(AppFailure? message) {
|
||||
if (message == null) return;
|
||||
_timer?.cancel();
|
||||
_displayedMessage = message;
|
||||
_visible = true;
|
||||
_timer = Timer(_displayDuration, _hide);
|
||||
}
|
||||
|
||||
void _hide() {
|
||||
if (mounted) setState(() => _visible = false);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final message = _displayedMessage;
|
||||
if (message == null) return const SizedBox.shrink();
|
||||
final theme = Theme.of(context);
|
||||
return IgnorePointer(
|
||||
ignoring: !_visible,
|
||||
child: AnimatedSlide(
|
||||
offset: _visible ? Offset.zero : const Offset(0.08, 0),
|
||||
duration: const Duration(milliseconds: 180),
|
||||
curve: Curves.easeOutCubic,
|
||||
child: AnimatedOpacity(
|
||||
opacity: _visible ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 160),
|
||||
child: Semantics(
|
||||
liveRegion: true,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 360),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHigh,
|
||||
border: Border.all(color: theme.colorScheme.outlineVariant),
|
||||
borderRadius: BorderRadius.circular(AppRadius.large),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: theme.colorScheme.shadow.withValues(alpha: .25),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 6),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(
|
||||
start: AppSpacing.compact,
|
||||
top: AppSpacing.small,
|
||||
bottom: AppSpacing.small,
|
||||
end: AppSpacing.tiny,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: AppIconSize.small,
|
||||
color: theme.colorScheme.error,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.small),
|
||||
Flexible(
|
||||
child: Text(
|
||||
context.l10n.failureMessage(message),
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: MaterialLocalizations.of(context)
|
||||
.closeButtonTooltip,
|
||||
onPressed: _hide,
|
||||
icon: const Icon(Icons.close, size: AppIconSize.small),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user