Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: avoid non-null promise on null value (#3569)
Mathias Mogensen94a3a59001a4
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dartindex 7de744024a..e3916cbab6 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/desktop_home_screen.dart@@ -9,6 +9,7 @@ import 'package:appflowy/workspace/application/home/home_service.dart';import 'package:appflowy/workspace/application/home/home_setting_bloc.dart';import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';import 'package:appflowy/workspace/application/view/view_ext.dart';+import 'package:appflowy/workspace/presentation/home/errors/workspace_failed_screen.dart';import 'package:appflowy/workspace/presentation/home/hotkeys.dart';import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar.dart';import 'package:appflowy/workspace/presentation/widgets/edit_panel/panel_animation.dart';@@ -42,21 +43,26 @@ class DesktopHomeScreen extends StatelessWidget {]),builder: (context, snapshots) {if (!snapshots.hasData) {- return const Center(child: CircularProgressIndicator.adaptive());+ return _buildLoading();}final workspaceSetting = snapshots.data?[0].fold(- (workspaceSettingPB) {- return workspaceSettingPB as WorkspaceSettingPB;- },+ (workspaceSettingPB) => workspaceSettingPB as WorkspaceSettingPB,(error) => null,);- final userProfile =- snapshots.data?[1].fold((error) => null, (userProfilePB) {- return userProfilePB as UserProfilePB;- });+ final userProfile = snapshots.data?[1].fold(+ (error) => null,+ (userProfilePB) => userProfilePB as UserProfilePB,+ );++ // In the unlikely case either of the above is null, eg.+ // when a workspace is already open this can happen.+ if (workspaceSetting == null || userProfile == null) {+ return const WorkspaceFailedScreen();+ }+return MultiBlocProvider(- key: ValueKey(userProfile!.id),+ key: ValueKey(userProfile.id),providers: [BlocProvider<ReminderBloc>.value(value: getIt<ReminderBloc>()..add(const ReminderEvent.started()),@@ -64,7 +70,7 @@ class DesktopHomeScreen extends StatelessWidget {BlocProvider<TabsBloc>.value(value: getIt<TabsBloc>()),BlocProvider<HomeBloc>(create: (context) {- return HomeBloc(userProfile, workspaceSetting!)+ return HomeBloc(userProfile, workspaceSetting)..add(const HomeEvent.initial());},),@@ -72,7 +78,7 @@ class DesktopHomeScreen extends StatelessWidget {create: (context) {return HomeSettingBloc(userProfile,- workspaceSetting!,+ workspaceSetting,context.read<AppearanceSettingsCubit>(),)..add(const HomeSettingEvent.initial());},@@ -109,8 +115,7 @@ class DesktopHomeScreen extends StatelessWidget {builder: (context, state) {return FlowyContainer(Theme.of(context).colorScheme.surface,- child:- _buildBody(context, userProfile, workspaceSetting!),+ child: _buildBody(context, userProfile, workspaceSetting),);},),@@ -122,6 +127,9 @@ class DesktopHomeScreen extends StatelessWidget {);}+ Widget _buildLoading() =>+ const Center(child: CircularProgressIndicator.adaptive());+Widget _buildBody(BuildContext context,UserProfilePB userProfile,diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/errors/workspace_failed_screen.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/errors/workspace_failed_screen.dartnew file mode 100644index 0000000000..60f3330408--- /dev/null+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/errors/workspace_failed_screen.dart@@ -0,0 +1,77 @@+import 'dart:io';++import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra_ui/widget/rounded_button.dart';+import 'package:flowy_infra_ui/widget/spacing.dart';+import 'package:flutter/material.dart';+import 'package:package_info_plus/package_info_plus.dart';++class WorkspaceFailedScreen extends StatefulWidget {+ const WorkspaceFailedScreen({super.key});++ @override+ State<WorkspaceFailedScreen> createState() => _WorkspaceFailedScreenState();+}++class _WorkspaceFailedScreenState extends State<WorkspaceFailedScreen> {+ String version = '';+ final String os = Platform.operatingSystem;++ @override+ void initState() {+ super.initState();+ initVersion();+ }++ Future<void> initVersion() async {+ final platformInfo = await PackageInfo.fromPlatform();+ setState(() {+ version = platformInfo.version;+ });+ }++ @override+ Widget build(BuildContext context) {+ return Material(+ child: Scaffold(+ body: Center(+ child: SizedBox(+ width: 400,+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Text(LocaleKeys.workspace_failedToLoad.tr()),+ const VSpace(20),+ Row(+ children: [+ Flexible(+ child: RoundedTextButton(+ title:+ LocaleKeys.workspace_errorActions_reportIssue.tr(),+ height: 40,+ onPressed: () => safeLaunchUrl(+ 'https://github.com/AppFlowy-IO/AppFlowy/issues/new?assignees=&labels=&projects=&template=bug_report.yaml&title=[Bug]%20Workspace%20failed%20to%20load&version=$version&os=$os',+ ),+ ),+ ),+ const HSpace(20),+ Flexible(+ child: RoundedTextButton(+ title: LocaleKeys.workspace_errorActions_reachOut.tr(),+ height: 40,+ onPressed: () =>+ safeLaunchUrl('https://discord.gg/JucBXeU2FE'),+ ),+ ),+ ],+ ),+ ],+ ),+ ),+ ),+ ),+ );+ }+}diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex c86a8ed566..f850b3fc9d 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -54,7 +54,12 @@"reset": "Reset workspace","resetWorkspacePrompt": "Resetting the workspace will delete all pages and data within it. Are you sure you want to reset the workspace? Alternatively, you can contact the support team to restore the workspace","hint": "workspace",- "notFoundError": "Workspace not found"+ "notFoundError": "Workspace not found",+ "failedToLoad": "Something went wrong! Failed to load the workspace. Try to close any open instance of AppFlowy and try again.",+ "errorActions": {+ "reportIssue": "Report issue",+ "reachOut": "Reach out on Discord"+ }},"shareAction": {"buttonText": "Share",@@ -804,4 +809,4 @@"noResult": "No results","caseSensitive": "Case sensitive"}-}\ No newline at end of file+}