Created
March 11, 2021 13:46
-
-
Save anoochit/50c0c38abab1ee6b68e4f5ded5de17b6 to your computer and use it in GitHub Desktop.
adaptive layout with LayoutBuilder
This file contains 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 'dart:developer'; | |
import 'package:flutter/material.dart'; | |
class HomePage extends StatefulWidget { | |
HomePage({Key key}) : super(key: key); | |
@override | |
_HomePageState createState() => _HomePageState(); | |
} | |
class _HomePageState extends State<HomePage> { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold(body: LayoutBuilder( | |
builder: (BuildContext context, BoxConstraints constraints) { | |
log(constraints.maxWidth.toString()); | |
if (constraints.maxWidth > 950) { | |
// desktop | |
return Text("desktop"); | |
} else if (constraints.maxWidth > 500) { | |
// tablet | |
return Text("tablet"); | |
} else { | |
// mobile | |
return Text("mobile"); | |
} | |
}, | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment