From 52160f6d7e2392a4e8f6069f3e20ed70aae86ba0 Mon Sep 17 00:00:00 2001 From: Hitesh-23 Date: Sat, 23 May 2026 14:53:18 +0530 Subject: [PATCH] fix: prevent crash when mobile workspace list is empty --- .../mobile_workspace_start_screen.dart | 30 +++++++-------- .../mobile_workspace_start_screen_test.dart | 38 +++++++++++++++++++ 2 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 frontend/appflowy_flutter/test/widget_test/mobile_workspace_start_screen_test.dart diff --git a/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart b/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart index a6124da60bfc7..7af070cd41f7e 100644 --- a/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart +++ b/frontend/appflowy_flutter/lib/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart @@ -37,6 +37,7 @@ class _MobileWorkspaceStartScreenState final style = Theme.of(context); final size = MediaQuery.of(context).size; const double spacing = 16.0; + final hasWorkspaces = widget.workspaceState.workspaces.isNotEmpty; final List> workspaceEntries = >[]; for (final WorkspacePB workspace in widget.workspaceState.workspaces) { @@ -48,7 +49,7 @@ class _MobileWorkspaceStartScreenState ); } -// render the workspace dropdown menu if success, otherwise render error page + // render the workspace dropdown menu if success, otherwise render error page final body = widget.workspaceState.successOrFailure.fold( (_) { return Padding( @@ -106,21 +107,18 @@ class _MobileWorkspaceStartScreenState style: ElevatedButton.styleFrom( minimumSize: const Size(double.infinity, 56), ), - onPressed: () { - if (selectedWorkspace == null) { - // If user didn't choose any workspace, pop to the initial workspace(first workspace) - _popToWorkspace( - context, - widget.workspaceState.workspaces.first, - ); - return; - } - // pop to the selected workspace - _popToWorkspace( - context, - selectedWorkspace!, - ); - }, + onPressed: + hasWorkspaces + ? () { + final workspace = + selectedWorkspace ?? + widget.workspaceState.workspaces.first; + + // If user didn't choose any workspace, pop to the + // initial workspace(first workspace). + _popToWorkspace(context, workspace); + } + : null, child: Text(LocaleKeys.signUp_getStartedText.tr()), ), const VSpace(spacing), diff --git a/frontend/appflowy_flutter/test/widget_test/mobile_workspace_start_screen_test.dart b/frontend/appflowy_flutter/test/widget_test/mobile_workspace_start_screen_test.dart new file mode 100644 index 0000000000000..d14b4dfb1e043 --- /dev/null +++ b/frontend/appflowy_flutter/test/widget_test/mobile_workspace_start_screen_test.dart @@ -0,0 +1,38 @@ +import 'package:appflowy/user/presentation/screens/workspace_start_screen/mobile_workspace_start_screen.dart'; +import 'package:appflowy/workspace/application/workspace/prelude.dart'; +import 'package:appflowy_result/appflowy_result.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'test_material_app.dart'; + +void main() { + setUpAll(() async { + EasyLocalization.logger.enableLevels = []; + await EasyLocalization.ensureInitialized(); + }); + + group('MobileWorkspaceStartScreen', () { + testWidgets('disables get started when workspaces are empty', ( + tester, + ) async { + await tester.pumpWidget( + WidgetTestApp( + child: MobileWorkspaceStartScreen( + workspaceState: WorkspaceState( + isLoading: false, + workspaces: const [], + successOrFailure: FlowyResult.success(null), + ), + ), + ), + ); + + await tester.pumpAndSettle(); + + final button = tester.widget(find.byType(ElevatedButton)); + expect(button.onPressed, isNull); + }); + }); +}