Skip to content

Instantly share code, notes, and snippets.

@Nash0x7E2
Last active March 28, 2019 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nash0x7E2/6d4b5d45d4146eb2e35f2f34f4074fbe to your computer and use it in GitHub Desktop.
Save Nash0x7E2/6d4b5d45d4146eb2e35f2f34f4074fbe to your computer and use it in GitHub Desktop.
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;
@override
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