@@ -76,7 +76,7 @@ class WebLinkDelegateState extends State<WebLinkDelegate> {
76
76
child: PlatformViewLink (
77
77
viewType: linkViewType,
78
78
onCreatePlatformView: (PlatformViewCreationParams params) {
79
- _controller = LinkViewController .fromParams (params, context );
79
+ _controller = LinkViewController .fromParams (params);
80
80
return _controller
81
81
..setUri (widget.link.uri)
82
82
..setTarget (widget.link.target);
@@ -100,7 +100,7 @@ class WebLinkDelegateState extends State<WebLinkDelegate> {
100
100
/// Controls link views.
101
101
class LinkViewController extends PlatformViewController {
102
102
/// Creates a [LinkViewController] instance with the unique [viewId] .
103
- LinkViewController (this .viewId, this .context ) {
103
+ LinkViewController (this .viewId) {
104
104
if (_instances.isEmpty) {
105
105
// This is the first controller being created, attach the global click
106
106
// listener.
@@ -113,12 +113,17 @@ class LinkViewController extends PlatformViewController {
113
113
/// platform view [params] .
114
114
factory LinkViewController .fromParams (
115
115
PlatformViewCreationParams params,
116
- BuildContext context,
117
116
) {
118
117
final int viewId = params.id;
119
- final LinkViewController controller = LinkViewController (viewId, context );
118
+ final LinkViewController controller = LinkViewController (viewId);
120
119
controller._initialize ().then ((_) {
121
- params.onPlatformViewCreated (viewId);
120
+ /// Because _initialize is async, it can happen that [LinkViewController.dispose]
121
+ /// may get called before this `then` callback.
122
+ /// Check that the `controller` that was created by this factory is not
123
+ /// disposed before calling `onPlatformViewCreated` .
124
+ if (_instances[viewId] == controller) {
125
+ params.onPlatformViewCreated (viewId);
126
+ }
122
127
});
123
128
return controller;
124
129
}
@@ -159,9 +164,6 @@ class LinkViewController extends PlatformViewController {
159
164
@override
160
165
final int viewId;
161
166
162
- /// The context of the [Link] widget that created this controller.
163
- final BuildContext context;
164
-
165
167
late html.Element _element;
166
168
167
169
bool get _isInitialized => _element != null ;
@@ -208,7 +210,7 @@ class LinkViewController extends PlatformViewController {
208
210
// browser handle it.
209
211
event.preventDefault ();
210
212
final String routeName = _uri.toString ();
211
- pushRouteNameToFramework (context , routeName);
213
+ pushRouteNameToFramework (null , routeName);
212
214
}
213
215
214
216
Uri ? _uri;
0 commit comments