Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(MyApp());
  4.  
  5. class MyApp extends StatelessWidget {
  6. @override
  7. Widget build(BuildContext context) {
  8. return MaterialApp(
  9. title: 'Flutter Demo',
  10. theme: ThemeData(
  11. primarySwatch: Colors.blue,
  12. ),
  13. home: MyHomePage(title: 'Flutter Demo Home Page'),
  14. );
  15. }
  16. }
  17.  
  18. class MyHomePage extends StatefulWidget {
  19. MyHomePage({Key key, this.title}) : super(key: key);
  20. final String title;
  21.  
  22. @override
  23. _MyHomePageState createState() => _MyHomePageState();
  24. }
  25.  
  26. class _MyHomePageState extends State<MyHomePage> {
  27. @override
  28. Widget build(BuildContext context) {
  29. return Scaffold(
  30. appBar: AppBar(
  31. title: Text(widget.title),
  32. ),
  33. body: ListView.builder(
  34. itemBuilder: (c, i) {
  35. return _buildItem(i);
  36. },
  37. itemCount: 7,
  38. ),
  39. );
  40. }
  41.  
  42. Widget _buildItem(int i) {
  43. switch (i) {
  44. case 0:
  45. return AspectRatio(
  46. aspectRatio: 872 / 370,
  47. child: Text(
  48. i.toString(),
  49. textAlign: TextAlign.center,
  50. ),
  51. );
  52. break;
  53. case 1:
  54. return GridView.builder(
  55. gridDelegate:
  56. SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4, childAspectRatio: 1 / 1),
  57. itemBuilder: (c, i) {
  58. return Text(
  59. i.toString(),
  60. textAlign: TextAlign.center,
  61. );
  62. },
  63. itemCount: 4,
  64. shrinkWrap: true,
  65. physics: NeverScrollableScrollPhysics(),
  66. );
  67. break;
  68. default:
  69. return GridView.builder(
  70. gridDelegate:
  71. SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 6 / 5),
  72. itemBuilder: (c, i) {
  73. return Text(
  74. i.toString(),
  75. textAlign: TextAlign.center,
  76. );
  77. },
  78. itemCount: 4,
  79. shrinkWrap: true,
  80. physics: NeverScrollableScrollPhysics(),
  81. );
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement