Merge pull request #1531 from abarth/raw_keyboard_crash
RawKeyboardListener asserts if disposed without keyboard
This commit is contained in:
@@ -39,19 +39,20 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> implements mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_detachKeyboard();
|
_detachKeyboardIfAttached();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _attachOrDetachKeyboard() {
|
void _attachOrDetachKeyboard() {
|
||||||
if (config.focused && _stub == null)
|
if (config.focused)
|
||||||
_attachKeyboard();
|
_attachKeyboardIfDetached();
|
||||||
else if (!config.focused && _stub != null)
|
else
|
||||||
_detachKeyboard();
|
_detachKeyboardIfAttached();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _attachKeyboard() {
|
void _attachKeyboardIfDetached() {
|
||||||
assert(_stub == null);
|
if (_stub != null)
|
||||||
|
return;
|
||||||
_stub = new mojom.RawKeyboardListenerStub.unbound()..impl = this;
|
_stub = new mojom.RawKeyboardListenerStub.unbound()..impl = this;
|
||||||
mojom.RawKeyboardServiceProxy keyboard = new mojom.RawKeyboardServiceProxy.unbound();
|
mojom.RawKeyboardServiceProxy keyboard = new mojom.RawKeyboardServiceProxy.unbound();
|
||||||
shell.connectToService(null, keyboard);
|
shell.connectToService(null, keyboard);
|
||||||
@@ -59,9 +60,8 @@ class _RawKeyboardListenerState extends State<RawKeyboardListener> implements mo
|
|||||||
keyboard.close();
|
keyboard.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _detachKeyboard() {
|
void _detachKeyboardIfAttached() {
|
||||||
assert(_stub != null);
|
_stub?.close();
|
||||||
_stub.close();
|
|
||||||
_stub = null;
|
_stub = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
packages/flutter/test/widget/raw_keyboard_listener_test.dart
Normal file
16
packages/flutter/test/widget/raw_keyboard_listener_test.dart
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('Can dispose without keyboard', () {
|
||||||
|
testWidgets((WidgetTester tester) {
|
||||||
|
tester.pumpWidget(new RawKeyboardListener(child: new Container()));
|
||||||
|
tester.pumpWidget(new Container());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user