Created
January 7, 2019 08:20
-
-
Save xsahil03x/693f771360ce78b198c8348117d23a3b to your computer and use it in GitHub Desktop.
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
Widget makeItemList(JweleryKartBloc bloc) => StreamBuilder( | |
stream: bloc.menOffers, | |
builder: (BuildContext context, AsyncSnapshot<List<OfferBrief>> snapshot) { | |
if (!snapshot.hasData) { | |
return Center( | |
child: CircularProgressIndicator(), | |
); | |
} | |
return GridView.builder( | |
shrinkWrap: true, | |
scrollDirection: Axis.horizontal, | |
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( | |
crossAxisCount: 2, | |
mainAxisSpacing: 16.0, | |
crossAxisSpacing: 4.0, | |
), | |
itemCount: snapshot.data?.length, | |
itemBuilder: (BuildContext context, int position) => | |
makeItem(snapshot.data[position]), | |
); | |
}); | |
Widget makeItem(OfferBrief data) => Stack( | |
fit: StackFit.expand, | |
children: <Widget>[ | |
imageStack(data.productImageURL), | |
descStack(data.productName, data.productPrice), | |
ratingStack(5.0), | |
], | |
); | |
Widget imageStack(String img) => Image.network( | |
img, | |
fit: BoxFit.cover, | |
); | |
Widget descStack(String name, String price) => Positioned( | |
bottom: 0.0, | |
left: 0.0, | |
right: 0.0, | |
child: Container( | |
decoration: BoxDecoration(color: Colors.black.withOpacity(0.5)), | |
child: Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: <Widget>[ | |
Expanded( | |
child: Text( | |
name, | |
softWrap: true, | |
overflow: TextOverflow.ellipsis, | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
Text(price, | |
style: TextStyle( | |
color: Colors.yellow, | |
fontSize: 18.0, | |
fontWeight: FontWeight.bold)) | |
], | |
), | |
), | |
), | |
); | |
Widget ratingStack(double rating) => Positioned( | |
top: 0.0, | |
left: 0.0, | |
child: Container( | |
padding: EdgeInsets.all(4.0), | |
decoration: BoxDecoration( | |
color: Colors.black.withOpacity(0.9), | |
borderRadius: BorderRadius.only( | |
topRight: Radius.circular(10.0), | |
bottomRight: Radius.circular(10.0))), | |
child: Row( | |
children: <Widget>[ | |
Icon( | |
Icons.star, | |
color: Colors.cyanAccent, | |
size: 10.0, | |
), | |
SizedBox( | |
width: 2.0, | |
), | |
Text( | |
rating.toString(), | |
style: TextStyle(color: Colors.white, fontSize: 10.0), | |
) | |
], | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment