Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Flutter Gridview builder example

 Create gridview in flutter


import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage()
)
);

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends StateHomePage
> {

final ListString> _listItem = [
'assets/images1.jpeg',
'assets/images2.jpeg',
'assets/images3.jpeg',
'assets/images4.jpeg',
'assets/images5.jpeg',
'assets/images6.jpeg',
'assets/images7.jpeg',
'assets/frame8.jpeg',
'assets/frame9.jpeg',
];

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[600],
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: Icon(Icons.menu),
title: Text("Home"),
actions: Widget>[
Padding(
padding: EdgeInsets.all(10.0),
child: Container(
width: 36,
height: 30,
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: BorderRadius.circular(10)
),
child: Center(child: Text("0")),
),
)
],
),
body: SafeArea(
child: Container(
padding: EdgeInsets.all(20.0),
child: Column(
children: Widget>[
Container(
width: double.infinity,
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage('assets/images.jpeg'),
fit: BoxFit.cover
)
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
gradient: LinearGradient(
begin: Alignment.bottomRight,
colors: [
Colors.black.withOpacity(.4),
Colors.black.withOpacity(.2),
]
)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: Widget>[
Text("Lifestyle Sale", style: TextStyle(color: Colors.white, fontSize: 35, fontWeight: FontWeight.bold),),
SizedBox(height: 30,),
Container(
height: 50,
margin: EdgeInsets.symmetric(horizontal: 40),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white
),
child: Center(child: Text("Shop Now", style: TextStyle(color: Colors.grey[900], fontWeight: FontWeight.bold),)),
),
SizedBox(height: 30,),
],
),
),
),
SizedBox(height: 20,),
Expanded(
child: GridView.count(
crossAxisCount: 2,
crossAxisSpacing: 10, //row spacing
mainAxisSpacing: 10,
children: _listItem.map((item) => Card(
color: Colors.transparent,
elevation: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage(item),
fit: BoxFit.cover
)
),
child: Transform.translate(
offset: Offset(50, -50),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 65, vertical: 63),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white
),
child: Icon(Icons.bookmark_border, size: 15,),
),
),
),
)).toList(),
)
)
],
),
),
),
);
}
}


This post first appeared on AR Programming, please read the originial post: here

Share the post

Flutter Gridview builder example

×

Subscribe to Ar Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×