Skip to content

Instantly share code, notes, and snippets.

@UsamaKarim
Created January 26, 2023 06:37
Show Gist options
  • Save UsamaKarim/e40058055669795768e20eba6e03d6ad to your computer and use it in GitHub Desktop.
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.
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