Skip to content

Instantly share code, notes, and snippets.

@anoochit
Created March 11, 2021 13:46
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 anoochit/50c0c38abab1ee6b68e4f5ded5de17b6 to your computer and use it in GitHub Desktop.
Save anoochit/50c0c38abab1ee6b68e4f5ded5de17b6 to your computer and use it in GitHub Desktop.
adaptive layout with LayoutBuilder
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