fix: empty view id

This commit is contained in:
Nathan 2025-04-21 22:10:52 +08:00
parent 4e2990e599
commit b0c2b04a2d
5 changed files with 13 additions and 4 deletions

View File

@ -145,7 +145,7 @@ class _MobileHomePageState extends State<MobileHomePage> {
void _onLatestViewChange() async { void _onLatestViewChange() async {
final id = getIt<MenuSharedState>().latestOpenView?.id; final id = getIt<MenuSharedState>().latestOpenView?.id;
if (id == null) { if (id == null || id.isEmpty) {
return; return;
} }
await FolderEventSetLatestView(ViewIdPB(value: id)).send(); await FolderEventSetLatestView(ViewIdPB(value: id)).send();

View File

@ -36,7 +36,7 @@ class BlankPagePlugin extends Plugin {
PluginWidgetBuilder get widgetBuilder => BlankPagePluginWidgetBuilder(); PluginWidgetBuilder get widgetBuilder => BlankPagePluginWidgetBuilder();
@override @override
PluginId get id => "BlankStack"; PluginId get id => "";
@override @override
PluginType get pluginType => PluginType.blank; PluginType get pluginType => PluginType.blank;

View File

@ -404,7 +404,7 @@ class ViewBloc extends Bloc<ViewEvent, ViewState> {
}); });
} }
if (update.updateChildViews.isNotEmpty) { if (update.updateChildViews.isNotEmpty && update.parentViewId.isNotEmpty) {
final view = await ViewBackendService.getView(update.parentViewId); final view = await ViewBackendService.getView(update.parentViewId);
final childViews = view.fold((l) => l.childViews, (r) => []); final childViews = view.fold((l) => l.childViews, (r) => []);
bool isSameOrder = true; bool isSameOrder = true;

View File

@ -111,6 +111,12 @@ class ViewBackendService {
static Future<FlowyResult<List<ViewPB>, FlowyError>> getChildViews({ static Future<FlowyResult<List<ViewPB>, FlowyError>> getChildViews({
required String viewId, required String viewId,
}) { }) {
if (viewId.isEmpty) {
return Future.value(
FlowyResult<List<ViewPB>, FlowyError>.success(<ViewPB>[]),
);
}
final payload = ViewIdPB.create()..value = viewId; final payload = ViewIdPB.create()..value = viewId;
return FolderEventGetView(payload).send().then((result) { return FolderEventGetView(payload).send().then((result) {
@ -262,6 +268,9 @@ class ViewBackendService {
static Future<FlowyResult<ViewPB, FlowyError>> getView( static Future<FlowyResult<ViewPB, FlowyError>> getView(
String viewId, String viewId,
) async { ) async {
if (viewId.isEmpty) {
Log.error('ViewId is empty');
}
final payload = ViewIdPB.create()..value = viewId; final payload = ViewIdPB.create()..value = viewId;
return FolderEventGetView(payload).send(); return FolderEventGetView(payload).send();
} }

View File

@ -631,7 +631,7 @@ class PageNotifier extends ChangeNotifier {
} }
// Set the plugin view as the latest view. // Set the plugin view as the latest view.
if (setLatest) { if (setLatest && newPlugin.id.isNotEmpty) {
FolderEventSetLatestView(ViewIdPB(value: newPlugin.id)).send(); FolderEventSetLatestView(ViewIdPB(value: newPlugin.id)).send();
} }