Last active
March 29, 2020 20:06
-
-
Save carzacc/63cbd8a313832e7e146198b032ce46d0 to your computer and use it in GitHub Desktop.
Example app using LayoutBuilder to get constraints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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