Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c12332b

Browse files
authored
Update "unregistered_view_type" error message (#33450)
1 parent c798582 commit c12332b

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

lib/web_ui/lib/src/engine/platform_views/message_handler.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ class PlatformViewMessageHandler {
7373
if (!_contentManager.knowsViewType(viewType)) {
7474
callback(_codec.encodeErrorEnvelope(
7575
code: 'unregistered_view_type',
76-
message: 'trying to create a view with an unregistered type',
77-
details: 'unregistered view type: $viewType',
76+
message: 'A HtmlElementView widget is trying to create a platform view '
77+
'with an unregistered type: <$viewType>.',
78+
details: 'If you are the author of the PlatformView, make sure '
79+
'`registerViewFactory` is invoked.',
7880
));
7981
return;
8082
}

lib/web_ui/test/engine/platform_views/message_handler_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void testMain() {
4646
codec.decodeEnvelope(response!);
4747
} on PlatformException catch (e) {
4848
expect(e.code, 'unregistered_view_type');
49-
expect(e.details, contains(viewType));
49+
expect(e.message, contains(viewType));
50+
expect(e.details, contains('registerViewFactory'));
5051
}
5152
});
5253

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@
129129
NSDictionary<NSString*, id>* args = [call arguments];
130130

131131
long viewId = [args[@"id"] longValue];
132-
std::string viewType([args[@"viewType"] UTF8String]);
132+
NSString* viewTypeString = args[@"viewType"];
133+
std::string viewType(viewTypeString.UTF8String);
133134

134135
if (views_.count(viewId) != 0) {
135136
result([FlutterError errorWithCode:@"recreating_view"
@@ -139,10 +140,18 @@
139140

140141
NSObject<FlutterPlatformViewFactory>* factory = factories_[viewType].get();
141142
if (factory == nil) {
142-
result([FlutterError errorWithCode:@"unregistered_view_type"
143-
message:@"trying to create a view with an unregistered type"
144-
details:[NSString stringWithFormat:@"unregistered view type: '%@'",
145-
args[@"viewType"]]]);
143+
result([FlutterError
144+
errorWithCode:@"unregistered_view_type"
145+
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a "
146+
@"PlatformView with an unregistered type: < %@ >",
147+
viewTypeString]
148+
details:@"If you are the author of the PlatformView, make sure `registerViewFactory` "
149+
@"is invoked.\n"
150+
@"See: "
151+
@"https://docs.flutter.dev/development/platform-integration/"
152+
@"platform-views#on-the-platform-side-1 for more details.\n"
153+
@"If you are not the author of the PlatformView, make sure to call "
154+
@"`GeneratedPluginRegistrant.register`."]);
146155
return;
147156
}
148157

shell/platform/darwin/macos/framework/Source/FlutterPlatformViewController.mm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ - (void)onCreateWithViewID:(int64_t)viewId
3939
if (!factory) {
4040
result([FlutterError
4141
errorWithCode:@"unregistered_view_type"
42-
message:@"trying to create a view with an unregistered type"
43-
details:[NSString stringWithFormat:@"unregistered view type: '%@'", viewType]]);
42+
message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a "
43+
@"PlatformView with an unregistered type: < %@ >",
44+
viewType]
45+
details:@"If you are the author of the PlatformView, make sure `registerViewFactory` "
46+
@"is invoked.\n"
47+
@"See: "
48+
@"https://docs.flutter.dev/development/platform-integration/"
49+
@"platform-views#on-the-platform-side-1 for more details.\n"
50+
@"If you are not the author of the PlatformView, make sure to call "
51+
@"`GeneratedPluginRegistrant.register`."]);
4452
return;
4553
}
4654

0 commit comments

Comments
 (0)