mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Hide the keyboard in a deferred task.
This is intended to eliminate the flicker that occurs when one widget hides the keyboard and then another shows it within the same update cycle.
This commit is contained in:
parent
ccd4a179b0
commit
fc8bbaaccc
@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:mojo_services/keyboard/keyboard.mojom.dart';
|
||||
|
||||
import 'shell.dart';
|
||||
@ -32,6 +34,8 @@ class Keyboard {
|
||||
|
||||
KeyboardHandle _currentHandle;
|
||||
|
||||
bool _hidePending = false;
|
||||
|
||||
KeyboardHandle show(KeyboardClientStub stub, KeyboardType keyboardType) {
|
||||
assert(stub != null);
|
||||
if (_currentHandle != null) {
|
||||
@ -43,6 +47,20 @@ class Keyboard {
|
||||
return _currentHandle;
|
||||
}
|
||||
|
||||
void _scheduleHide() {
|
||||
if (_hidePending) return;
|
||||
_hidePending = true;
|
||||
|
||||
// Schedule a deferred task that hides the keyboard. If someone else shows
|
||||
// the keyboard during this update cycle, then the task will do nothing.
|
||||
scheduleMicrotask(() {
|
||||
_hidePending = false;
|
||||
if (_currentHandle == null) {
|
||||
service.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class KeyboardHandle {
|
||||
@ -70,9 +88,9 @@ class KeyboardHandle {
|
||||
void release() {
|
||||
if (_attached) {
|
||||
assert(_keyboard._currentHandle == this);
|
||||
_keyboard.service.hide();
|
||||
_attached = false;
|
||||
_keyboard._currentHandle = null;
|
||||
_keyboard._scheduleHide();
|
||||
}
|
||||
assert(_keyboard._currentHandle != this);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user