Skip to content

Instantly share code, notes, and snippets.

@carzacc
Last active March 29, 2020 20:06
Show Gist options
  • Save carzacc/63cbd8a313832e7e146198b032ce46d0 to your computer and use it in GitHub Desktop.
Save carzacc/63cbd8a313832e7e146198b032ce46d0 to your computer and use it in GitHub Desktop.
Example app using LayoutBuilder to get constraints
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(context) =>
MaterialApp(
home: MyHomePage()
);
}
class MyHomePage extends StatelessWidget {
@override
Widget build(context) =>
Scaffold(
body: LayoutBuilder(
builder: (context, constraints) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(
"Width: ${constraints.maxWidth}",
style: Theme.of(context).textTheme.headline4
),
Text(
"Height: ${constraints.maxHeight}",
style: Theme.of(context).textTheme.headline4
)
]
)
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment