提交 4e45045a authored 作者: Kevin's avatar Kevin

Fix Bug Issues:47

上级 75484143
## [0.5.4]
* TODO: Fix Bug Issues:47
## [0.5.3] ## [0.5.3]
* TODO: 修复键盘有时候不会收起来的问题 * TODO: 修复键盘有时候不会收起来的问题
......
...@@ -9,7 +9,7 @@ Usage Add this to your package's pubspec.yaml file: ...@@ -9,7 +9,7 @@ Usage Add this to your package's pubspec.yaml file:
Flutter >=1.17 Flutter >=1.17
``` yaml ``` yaml
dependencies: dependencies:
cool_ui: "^0.5.3" cool_ui: "^0.5.4"
``` ```
Flutter >=1.7 Flutter >=1.7
......
...@@ -52,7 +52,7 @@ class CustomKeyboardDemoState extends State<CustomKeyboardDemo> { ...@@ -52,7 +52,7 @@ class CustomKeyboardDemoState extends State<CustomKeyboardDemo> {
), ),
TextField( TextField(
decoration: InputDecoration(labelText: '多个键盘演示'), decoration: InputDecoration(labelText: '多个键盘演示'),
keyboardType: TestKeyboard.inputType, keyboardType: NumberKeyboard.inputType,
) )
], ],
)); ));
......
...@@ -19,6 +19,8 @@ class CoolKeyboard { ...@@ -19,6 +19,8 @@ class CoolKeyboard {
static String _keyboardParam; static String _keyboardParam;
static Timer clearTask;
static init(BuildContext context) { static init(BuildContext context) {
_context = context; _context = context;
interceptorInput(); interceptorInput();
...@@ -27,12 +29,16 @@ class CoolKeyboard { ...@@ -27,12 +29,16 @@ class CoolKeyboard {
static interceptorInput() { static interceptorInput() {
if (isInterceptor) return; if (isInterceptor) return;
isInterceptor = true; isInterceptor = true;
ServicesBinding.instance.defaultBinaryMessenger.setMockMessageHandler("flutter/textinput", ServicesBinding.instance.defaultBinaryMessenger
(ByteData data) async { .setMockMessageHandler("flutter/textinput", (ByteData data) async {
var methodCall = _codec.decodeMethodCall(data); var methodCall = _codec.decodeMethodCall(data);
switch (methodCall.method) { switch (methodCall.method) {
case 'TextInput.show': case 'TextInput.show':
if (_currentKeyboard != null) { if (_currentKeyboard != null) {
if (clearTask != null) {
clearTask.cancel();
clearTask = null;
}
openKeyboard(); openKeyboard();
return _codec.encodeSuccessEnvelope(null); return _codec.encodeSuccessEnvelope(null);
} else { } else {
...@@ -41,7 +47,9 @@ class CoolKeyboard { ...@@ -41,7 +47,9 @@ class CoolKeyboard {
break; break;
case 'TextInput.hide': case 'TextInput.hide':
if (_currentKeyboard != null) { if (_currentKeyboard != null) {
hideKeyboard(); if(clearTask == null){
clearTask = new Timer(Duration(milliseconds: 16), ()=>hideKeyboard(animation: true));
}
return _codec.encodeSuccessEnvelope(null); return _codec.encodeSuccessEnvelope(null);
} else { } else {
return await _sendPlatformMessage("flutter/textinput", data); return await _sendPlatformMessage("flutter/textinput", data);
...@@ -55,7 +63,9 @@ class CoolKeyboard { ...@@ -55,7 +63,9 @@ class CoolKeyboard {
} }
break; break;
case 'TextInput.clearClient': case 'TextInput.clearClient':
hideKeyboard(animation: true); if(clearTask == null){
clearTask = new Timer(Duration(milliseconds: 16), ()=>hideKeyboard(animation: true));
}
clearKeyboard(); clearKeyboard();
break; break;
case 'TextInput.setClient': case 'TextInput.setClient':
...@@ -65,7 +75,8 @@ class CoolKeyboard { ...@@ -65,7 +75,8 @@ class CoolKeyboard {
if (inputType.name == setInputType['name']) { if (inputType.name == setInputType['name']) {
client = InputClient.fromJSON(methodCall.arguments); client = InputClient.fromJSON(methodCall.arguments);
_keyboardParam = (client.configuration.inputType as CKTextInputType).params; _keyboardParam =
(client.configuration.inputType as CKTextInputType).params;
clearKeyboard(); clearKeyboard();
_currentKeyboard = keyboardConfig; _currentKeyboard = keyboardConfig;
...@@ -76,7 +87,8 @@ class CoolKeyboard { ...@@ -76,7 +87,8 @@ class CoolKeyboard {
_keyboardController.client.connectionId, _keyboardController.client.connectionId,
_keyboardController.value.toJSON() _keyboardController.value.toJSON()
]); ]);
defaultBinaryMessenger.handlePlatformMessage( ServicesBinding.instance.defaultBinaryMessenger
.handlePlatformMessage(
"flutter/textinput", "flutter/textinput",
_codec.encodeMethodCall(callbackMethodCall), _codec.encodeMethodCall(callbackMethodCall),
(data) {}); (data) {});
...@@ -92,7 +104,9 @@ class CoolKeyboard { ...@@ -92,7 +104,9 @@ class CoolKeyboard {
_codec.encodeMethodCall(MethodCall('TextInput.hide'))); _codec.encodeMethodCall(MethodCall('TextInput.hide')));
return _codec.encodeSuccessEnvelope(null); return _codec.encodeSuccessEnvelope(null);
} else { } else {
if(clearTask == null){
hideKeyboard(animation: false); hideKeyboard(animation: false);
}
clearKeyboard(); clearKeyboard();
} }
break; break;
...@@ -128,7 +142,7 @@ class CoolKeyboard { ...@@ -128,7 +142,7 @@ class CoolKeyboard {
static openKeyboard() { static openKeyboard() {
var keyboardHeight = _currentKeyboard.getHeight(_context); var keyboardHeight = _currentKeyboard.getHeight(_context);
_keyboardHeightNotifier.value = keyboardHeight; _keyboardHeightNotifier.value = keyboardHeight;
if (_keyboardEntry != null) return; if (_keyboardEntry != null && _pageKey != null) return;
_pageKey = GlobalKey<KeyboardPageState>(); _pageKey = GlobalKey<KeyboardPageState>();
// KeyboardMediaQueryState queryState = _context // KeyboardMediaQueryState queryState = _context
// .ancestorStateOfType(const TypeMatcher<KeyboardMediaQueryState>()) // .ancestorStateOfType(const TypeMatcher<KeyboardMediaQueryState>())
...@@ -141,7 +155,8 @@ class CoolKeyboard { ...@@ -141,7 +155,8 @@ class CoolKeyboard {
return KeyboardPage( return KeyboardPage(
key: tempKey, key: tempKey,
builder: (ctx) { builder: (ctx) {
return _currentKeyboard?.builder(ctx, _keyboardController, _keyboardParam); return _currentKeyboard?.builder(
ctx, _keyboardController, _keyboardParam);
}, },
height: _keyboardHeightNotifier.value); height: _keyboardHeightNotifier.value);
} else { } else {
...@@ -158,9 +173,14 @@ class CoolKeyboard { ...@@ -158,9 +173,14 @@ class CoolKeyboard {
} }
static hideKeyboard({bool animation = true}) { static hideKeyboard({bool animation = true}) {
if (clearTask != null) {
if (clearTask.isActive) {
clearTask.cancel();
}
clearTask = null;
}
BackButtonInterceptor.removeByName('CustomKeyboard'); BackButtonInterceptor.removeByName('CustomKeyboard');
if (_keyboardEntry != null && _pageKey != null) { if (_keyboardEntry != null && _pageKey != null) {
_keyboardHeightNotifier.value = null;
// _pageKey.currentState.animationController // _pageKey.currentState.animationController
// .addStatusListener((AnimationStatus status) { // .addStatusListener((AnimationStatus status) {
// if (status == AnimationStatus.dismissed || // if (status == AnimationStatus.dismissed ||
...@@ -186,6 +206,7 @@ class CoolKeyboard { ...@@ -186,6 +206,7 @@ class CoolKeyboard {
} }
} }
_pageKey = null; _pageKey = null;
_keyboardHeightNotifier.value = null;
try { try {
// KeyboardMediaQueryState queryState = _context // KeyboardMediaQueryState queryState = _context
// .ancestorStateOfType(const TypeMatcher<KeyboardMediaQueryState>()) // .ancestorStateOfType(const TypeMatcher<KeyboardMediaQueryState>())
...@@ -210,7 +231,7 @@ class CoolKeyboard { ...@@ -210,7 +231,7 @@ class CoolKeyboard {
} }
static updateKeyboardHeight() { static updateKeyboardHeight() {
if (_pageKey != null && _pageKey.currentState != null) { if (_pageKey != null && _pageKey.currentState != null && clearTask == null) {
_pageKey.currentState.updateHeight(_keyboardHeightNotifier.value); _pageKey.currentState.updateHeight(_keyboardHeightNotifier.value);
} }
} }
...@@ -366,9 +387,9 @@ class KeyboardPageState extends State<KeyboardPage> { ...@@ -366,9 +387,9 @@ class KeyboardPageState extends State<KeyboardPage> {
// TODO: implement initState // TODO: implement initState
super.initState(); super.initState();
WidgetsBinding.instance.addPostFrameCallback((_){ WidgetsBinding.instance.addPostFrameCallback((_) {
_height = widget.height; _height = widget.height;
setState(()=>{}); setState(() => {});
}); });
} }
...@@ -414,15 +435,15 @@ class KeyboardPageState extends State<KeyboardPage> { ...@@ -414,15 +435,15 @@ class KeyboardPageState extends State<KeyboardPage> {
} }
update() { update() {
WidgetsBinding.instance.addPostFrameCallback((_){ WidgetsBinding.instance.addPostFrameCallback((_) {
setState(()=>{}); setState(() => {});
}); });
} }
updateHeight(double height) { updateHeight(double height) {
WidgetsBinding.instance.addPostFrameCallback((_){ WidgetsBinding.instance.addPostFrameCallback((_) {
this._height = height ?? 0; this._height = height ?? 0;
setState(()=>{}); setState(() => {});
}); });
} }
} }
name: cool_ui name: cool_ui
description: Some practical Widget for flutter,Popover,Weui,Custom Keyboard description: Some practical Widget for flutter,Popover,Weui,Custom Keyboard
version: 0.5.3 version: 0.5.4
author: Kevin <liangkaikevin@gmail.com> author: Kevin <liangkaikevin@gmail.com>
homepage: https://github.com/Im-Kevin/cool_ui homepage: https://github.com/Im-Kevin/cool_ui
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论