Created
March 5, 2021 05:44
-
-
Save nhancv/08670cb390323db8bc2be9bcafb0f178 to your computer and use it in GitHub Desktop.
Flutter keyboard detector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:nft/utils/app_route.dart'; | |
// // AppRoute from nft template | |
// WKeyboardDetector( | |
// onState: (bool isOpen, double keyboardHeight) { | |
// print('isOpen: $isOpen'); | |
// }, | |
// ), | |
class WKeyboardDetector extends StatefulWidget { | |
const WKeyboardDetector({ | |
this.onState, | |
Key key, | |
}) : super(key: key); | |
final Function(bool isOpen, double keyboardHeight) onState; | |
@override | |
_WKeyboardDetectorState createState() => _WKeyboardDetectorState(); | |
} | |
class _WKeyboardDetectorState extends State<WKeyboardDetector> { | |
bool _keyboardVisible = false; | |
double _keyboardHeight = 0; | |
set keyboardVisible(bool value) { | |
if (_keyboardVisible != value) { | |
_keyboardVisible = value; | |
if (widget.onState != null) { | |
widget.onState(_keyboardVisible, _keyboardHeight); | |
} | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
_keyboardHeight = MediaQuery.of(AppRoute.I.appContext).viewInsets.bottom; | |
keyboardVisible = _keyboardHeight > 0; | |
return Container(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment