Skip to content

Instantly share code, notes, and snippets.

@Maddoxx88
Created September 30, 2020 17:50
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 Maddoxx88/c6f541675179cc54f36573218d1b5762 to your computer and use it in GitHub Desktop.
Save Maddoxx88/c6f541675179cc54f36573218d1b5762 to your computer and use it in GitHub Desktop.
Responsive Media Query Widget
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final List<String> entries = <String>['A', 'B', 'C', 'D', 'E', 'F'];
final List<Color> colorS = <Color>[Colors.amber, Colors.green, Colors.red, Colors.blue, Colors.orange, Colors.purple];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: ListView.builder(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width / 15,
vertical: MediaQuery.of(context).size.height / 15
),
itemCount: entries.length,
itemBuilder: (_, int index) {
return Container(
margin: EdgeInsets.symmetric(vertical: MediaQuery.of(context).size.height/ 30),
height: MediaQuery.of(context).size.height / 5,
color: colorS[index],
child: Center(child: Text('Container ${entries[index]}',
style: TextStyle(
fontSize: 28.0,
fontWeight: FontWeight.bold
),)),
);
}
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment