Skip to content

Instantly share code, notes, and snippets.

@fnicastri
Forked from slightfoot/scroll_view_height.dart
Created March 27, 2023 18:02
Show Gist options
  • Save fnicastri/efd64d4a33e6d8597e6755bfe7ffcf61 to your computer and use it in GitHub Desktop.
Save fnicastri/efd64d4a33e6d8597e6755bfe7ffcf61 to your computer and use it in GitHub Desktop.
ScrollView With Height for Flutter. Simple ScrollView with its content having a minimum height of the ScrollView's parent. This allows you to space out your components inside your ScrollView to fit the avaliable space and not have them "squish up" when the soft keyboard (IME) appears.
class ScrollViewWithHeight extends StatelessWidget {
final Widget child;
const ScrollViewWithHeight({Key key, this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return new LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
return new SingleChildScrollView(
child: new ConstrainedBox(
constraints: constraints.copyWith(minHeight: constraints.maxHeight, maxHeight: double.infinity),
child: child,
),
);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment