Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Used to constrain the child of a scrollable to the max height of the view.
import 'package:flutter/material.dart';
class ConstrainedView extends StatelessWidget {
const ConstrainedView({Key key, this.child}) : super(key: key);
final Widget child;
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Padding(
padding: MediaQuery.of(context).viewInsets,
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
maxHeight: constraints.maxHeight,
minHeight: constraints.maxHeight),
child: child,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment