keyboard_height_plugin/example/lib/main.dart

77 lines
1.9 KiB
Dart
Raw Permalink Normal View History

2023-04-28 19:21:41 +00:00
import 'package:flutter/material.dart';
import 'package:keyboard_height_plugin/keyboard_height_plugin.dart';
void main() {
2023-04-28 19:59:37 +00:00
runApp(MyApp());
2023-04-28 19:21:41 +00:00
}
2023-04-28 19:59:37 +00:00
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
2023-04-28 19:21:41 +00:00
2023-04-28 19:59:37 +00:00
class HomePage extends StatefulWidget {
2023-04-28 19:21:41 +00:00
@override
2023-04-28 19:59:37 +00:00
_HomePageState createState() => _HomePageState();
2023-04-28 19:21:41 +00:00
}
2023-04-28 19:59:37 +00:00
class _HomePageState extends State<HomePage> {
double _keyboardHeight = 0;
final KeyboardHeightPlugin _keyboardHeightPlugin = KeyboardHeightPlugin();
2023-04-28 19:21:41 +00:00
@override
void initState() {
super.initState();
2023-04-28 19:59:37 +00:00
_keyboardHeightPlugin.onKeyboardHeightChanged((double height) {
setState(() {
_keyboardHeight = height;
});
2023-04-28 19:21:41 +00:00
});
}
@override
2023-04-28 19:59:37 +00:00
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
2023-04-28 19:21:41 +00:00
appBar: AppBar(
2023-04-28 19:59:37 +00:00
title: Text('Keyboard Height'),
2023-04-28 19:21:41 +00:00
),
body: Center(
2023-04-28 19:59:37 +00:00
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Keyboard height: $_keyboardHeight',
),
SizedBox(height: 16),
ElevatedButton(
child: Text('Get Keyboard Height'),
onPressed: () => {},
),
],
),
Positioned(
bottom: _keyboardHeight,
left: 0,
right: 0,
child: TextField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.orange,
hintText: 'Type here to open keyboard',
),
),
),
],
),
2023-04-28 19:21:41 +00:00
),
2023-04-28 19:59:37 +00:00
);
}
2023-04-28 19:21:41 +00:00
}