keyboard_info 0.1.1
keyboard_info: ^0.1.1 copied to clipboard
Provides API for querying information about the system's keyboard.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:keyboard_info/keyboard_info.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
KeyboardInfo? _keyboardInfo;
@override
void initState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
KeyboardInfo? keyboardInfo;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
keyboardInfo = await getKeyboardInfo();
} on PlatformException catch (e) {
print(e);
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_keyboardInfo = keyboardInfo;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Keyboard info example'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Layout: ${_keyboardInfo?.layout}'),
SizedBox(height: 10),
Text('Variant: ${_keyboardInfo?.variant}'),
],
),
),
),
);
}
}