@@ -43,6 +43,7 @@ import 'text_editing_intents.dart';
43
43
import 'text_selection.dart' ;
44
44
import 'text_selection_toolbar_anchors.dart' ;
45
45
import 'ticker_provider.dart' ;
46
+ import 'view.dart' ;
46
47
import 'widget_span.dart' ;
47
48
48
49
export 'package:flutter/services.dart' show SelectionChangedCause, SmartDashesType, SmartQuotesType, TextEditingValue, TextInputType, TextSelection;
@@ -3303,17 +3304,21 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
3303
3304
3304
3305
@override
3305
3306
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) {
3307
3312
SchedulerBinding .instance.addPostFrameCallback ((Duration _) {
3308
3313
_selectionOverlay? .updateForScroll ();
3309
3314
});
3310
- if (_lastBottomViewInset < WidgetsBinding .instance.window .viewInsets.bottom) {
3315
+ if (_lastBottomViewInset < view .viewInsets.bottom) {
3311
3316
// Because the metrics change signal from engine will come here every frame
3312
3317
// (on both iOS and Android). So we don't need to show caret with animation.
3313
3318
_scheduleShowCaretOnScreen (withAnimation: false );
3314
3319
}
3315
3320
}
3316
- _lastBottomViewInset = WidgetsBinding .instance.window .viewInsets.bottom;
3321
+ _lastBottomViewInset = view .viewInsets.bottom;
3317
3322
}
3318
3323
3319
3324
Future <void > _performSpellCheck (final String text) async {
@@ -3516,7 +3521,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
3516
3521
if (_hasFocus) {
3517
3522
// Listen for changing viewInsets, which indicates keyboard showing up.
3518
3523
WidgetsBinding .instance.addObserver (this );
3519
- _lastBottomViewInset = WidgetsBinding .instance.window .viewInsets.bottom;
3524
+ _lastBottomViewInset = View . of (context) .viewInsets.bottom;
3520
3525
if (! widget.readOnly) {
3521
3526
_scheduleShowCaretOnScreen (withAnimation: true );
3522
3527
}
0 commit comments