mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: avoid non-null promise on null value (#3569)
This commit is contained in:
parent
4a433a3176
commit
94a3a59001
@ -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/home/home_setting_bloc.dart';
|
||||||
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
||||||
import 'package:appflowy/workspace/application/view/view_ext.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/hotkeys.dart';
|
||||||
import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar.dart';
|
import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar.dart';
|
||||||
import 'package:appflowy/workspace/presentation/widgets/edit_panel/panel_animation.dart';
|
import 'package:appflowy/workspace/presentation/widgets/edit_panel/panel_animation.dart';
|
||||||
@ -42,21 +43,26 @@ class DesktopHomeScreen extends StatelessWidget {
|
|||||||
]),
|
]),
|
||||||
builder: (context, snapshots) {
|
builder: (context, snapshots) {
|
||||||
if (!snapshots.hasData) {
|
if (!snapshots.hasData) {
|
||||||
return const Center(child: CircularProgressIndicator.adaptive());
|
return _buildLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
final workspaceSetting = snapshots.data?[0].fold(
|
final workspaceSetting = snapshots.data?[0].fold(
|
||||||
(workspaceSettingPB) {
|
(workspaceSettingPB) => workspaceSettingPB as WorkspaceSettingPB,
|
||||||
return workspaceSettingPB as WorkspaceSettingPB;
|
|
||||||
},
|
|
||||||
(error) => null,
|
(error) => null,
|
||||||
);
|
);
|
||||||
final userProfile =
|
final userProfile = snapshots.data?[1].fold(
|
||||||
snapshots.data?[1].fold((error) => null, (userProfilePB) {
|
(error) => null,
|
||||||
return userProfilePB as UserProfilePB;
|
(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(
|
return MultiBlocProvider(
|
||||||
key: ValueKey(userProfile!.id),
|
key: ValueKey(userProfile.id),
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider<ReminderBloc>.value(
|
BlocProvider<ReminderBloc>.value(
|
||||||
value: getIt<ReminderBloc>()..add(const ReminderEvent.started()),
|
value: getIt<ReminderBloc>()..add(const ReminderEvent.started()),
|
||||||
@ -64,7 +70,7 @@ class DesktopHomeScreen extends StatelessWidget {
|
|||||||
BlocProvider<TabsBloc>.value(value: getIt<TabsBloc>()),
|
BlocProvider<TabsBloc>.value(value: getIt<TabsBloc>()),
|
||||||
BlocProvider<HomeBloc>(
|
BlocProvider<HomeBloc>(
|
||||||
create: (context) {
|
create: (context) {
|
||||||
return HomeBloc(userProfile, workspaceSetting!)
|
return HomeBloc(userProfile, workspaceSetting)
|
||||||
..add(const HomeEvent.initial());
|
..add(const HomeEvent.initial());
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -72,7 +78,7 @@ class DesktopHomeScreen extends StatelessWidget {
|
|||||||
create: (context) {
|
create: (context) {
|
||||||
return HomeSettingBloc(
|
return HomeSettingBloc(
|
||||||
userProfile,
|
userProfile,
|
||||||
workspaceSetting!,
|
workspaceSetting,
|
||||||
context.read<AppearanceSettingsCubit>(),
|
context.read<AppearanceSettingsCubit>(),
|
||||||
)..add(const HomeSettingEvent.initial());
|
)..add(const HomeSettingEvent.initial());
|
||||||
},
|
},
|
||||||
@ -109,8 +115,7 @@ class DesktopHomeScreen extends StatelessWidget {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return FlowyContainer(
|
return FlowyContainer(
|
||||||
Theme.of(context).colorScheme.surface,
|
Theme.of(context).colorScheme.surface,
|
||||||
child:
|
child: _buildBody(context, userProfile, workspaceSetting),
|
||||||
_buildBody(context, userProfile, workspaceSetting!),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -122,6 +127,9 @@ class DesktopHomeScreen extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildLoading() =>
|
||||||
|
const Center(child: CircularProgressIndicator.adaptive());
|
||||||
|
|
||||||
Widget _buildBody(
|
Widget _buildBody(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
UserProfilePB userProfile,
|
UserProfilePB userProfile,
|
||||||
|
@ -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'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -54,7 +54,12 @@
|
|||||||
"reset": "Reset workspace",
|
"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",
|
"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",
|
"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": {
|
"shareAction": {
|
||||||
"buttonText": "Share",
|
"buttonText": "Share",
|
||||||
@ -804,4 +809,4 @@
|
|||||||
"noResult": "No results",
|
"noResult": "No results",
|
||||||
"caseSensitive": "Case sensitive"
|
"caseSensitive": "Case sensitive"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user