Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Created January 7, 2019 08:20
Show Gist options
  • Save xsahil03x/693f771360ce78b198c8348117d23a3b to your computer and use it in GitHub Desktop.
Save xsahil03x/693f771360ce78b198c8348117d23a3b to your computer and use it in GitHub Desktop.
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