Created
December 12, 2023 08:21
-
-
Save growupanand/37485fd535d32f3b66b21efa5fbc93c5 to your computer and use it in GitHub Desktop.
In flutter, Check if virtual keyboard is open
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'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
bool isKeyboardOpen = false; | |
@override | |
Widget build(BuildContext context) { | |
MediaQueryData queryData = MediaQuery.of(context); | |
isKeyboardOpen = queryData.viewInsets.bottom > 0; | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Keyboard Status'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
TextField( | |
decoration: InputDecoration(labelText: 'Type here'), | |
), | |
SizedBox(height: 20), | |
Text('Is Keyboard Open: $isKeyboardOpen'), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment