Skip to content

Instantly share code, notes, and snippets.

@growupanand
Created December 12, 2023 08:21
Show Gist options
  • Save growupanand/37485fd535d32f3b66b21efa5fbc93c5 to your computer and use it in GitHub Desktop.
Save growupanand/37485fd535d32f3b66b21efa5fbc93c5 to your computer and use it in GitHub Desktop.
In flutter, Check if virtual keyboard is open
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