Skip to content

Instantly share code, notes, and snippets.

@anoochit

anoochit/home.dart

Created Mar 11, 2021
Embed
What would you like to do?
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