Skip to content

Instantly share code, notes, and snippets.

@vladnicula
Last active May 26, 2021 05:14
Show Gist options
  • Save vladnicula/d4edbf7256e7c6cdc6ffaad45f2d32f3 to your computer and use it in GitHub Desktop.
Save vladnicula/d4edbf7256e7c6cdc6ffaad45f2d32f3 to your computer and use it in GitHub Desktop.
Flutter Basic Responsiveness
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Layout(),
),
);
}
}
class Box extends StatelessWidget {
@override
Widget build(BuildContext context) {
var screenWidth = MediaQuery.of(context).size.width;
double boxSize = 132;
Color boxColor = Color.fromRGBO(133, 162, 163, 1);
if (screenWidth > 600) {
boxSize = 264;
boxColor = Color.fromRGBO(23, 114, 117, 1);
}
return Container(
child: Text("Box"), width: boxSize, height: boxSize, color: boxColor);
}
}
class Layout extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [Box()]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment