Created
September 30, 2020 17:50
-
-
Save Maddoxx88/c6f541675179cc54f36573218d1b5762 to your computer and use it in GitHub Desktop.
Responsive Media Query Widget
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 '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