@@ -43,6 +43,7 @@ import 'text_editing_intents.dart';
4343import 'text_selection.dart' ;
4444import 'text_selection_toolbar_anchors.dart' ;
4545import 'ticker_provider.dart' ;
46+ import 'view.dart' ;
4647import 'widget_span.dart' ;
4748
4849export 'package:flutter/services.dart' show SelectionChangedCause, SmartDashesType, SmartQuotesType, TextEditingValue, TextInputType, TextSelection;
@@ -3303,17 +3304,21 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
33033304
33043305 @override
33053306 void didChangeMetrics () {
3306- if (_lastBottomViewInset != WidgetsBinding .instance.window.viewInsets.bottom) {
3307+ if (! mounted) {
3308+ return ;
3309+ }
3310+ final ui.FlutterView view = View .of (context);
3311+ if (_lastBottomViewInset != view.viewInsets.bottom) {
33073312 SchedulerBinding .instance.addPostFrameCallback ((Duration _) {
33083313 _selectionOverlay? .updateForScroll ();
33093314 });
3310- if (_lastBottomViewInset < WidgetsBinding .instance.window .viewInsets.bottom) {
3315+ if (_lastBottomViewInset < view .viewInsets.bottom) {
33113316 // Because the metrics change signal from engine will come here every frame
33123317 // (on both iOS and Android). So we don't need to show caret with animation.
33133318 _scheduleShowCaretOnScreen (withAnimation: false );
33143319 }
33153320 }
3316- _lastBottomViewInset = WidgetsBinding .instance.window .viewInsets.bottom;
3321+ _lastBottomViewInset = view .viewInsets.bottom;
33173322 }
33183323
33193324 Future <void > _performSpellCheck (final String text) async {
@@ -3516,7 +3521,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
35163521 if (_hasFocus) {
35173522 // Listen for changing viewInsets, which indicates keyboard showing up.
35183523 WidgetsBinding .instance.addObserver (this );
3519- _lastBottomViewInset = WidgetsBinding .instance.window .viewInsets.bottom;
3524+ _lastBottomViewInset = View . of (context) .viewInsets.bottom;
35203525 if (! widget.readOnly) {
35213526 _scheduleShowCaretOnScreen (withAnimation: true );
35223527 }
0 commit comments