Created
January 26, 2023 06:37
-
-
Save UsamaKarim/e40058055669795768e20eba6e03d6ad to your computer and use it in GitHub Desktop.
Wrap it with the widget you want to visible in case the keyboard pops out.
This file contains hidden or 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'; | |
class KeyboardAwareWidget extends StatelessWidget { | |
const KeyboardAwareWidget({ | |
Key? key, | |
this.padding = 16, | |
required this.child, | |
}) : super(key: key); | |
final double padding; | |
final Widget child; | |
@override | |
Widget build(BuildContext context) { | |
final keyboardVisibility = MediaQuery.of(context).viewInsets.bottom; | |
return Padding( | |
padding: EdgeInsets.only( | |
top: padding, | |
left: padding, | |
right: padding, | |
bottom: keyboardVisibility > 0 ? keyboardVisibility + padding : padding, | |
), | |
child: child, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment