Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:scoped_model/scoped_model.dart';
  3. import 'package:scoped/models/product_model.dart';
  4.  
  5. class ProductList extends StatelessWidget {
  6. @override
  7. Widget build(BuildContext context) {
  8. return ScopedModelDescendant<ProductsModel>(
  9. builder: (context, child, model) => GridView.count(
  10. padding: EdgeInsets.all(4.0),
  11. crossAxisCount: 2,
  12. children: List.generate(model.productList.length, (index) {
  13. final product = model.productList[index];
  14. return (ProductItemCard(product: product));
  15. }),
  16. )
  17. );
  18. }
  19. }
  20.  
  21. class ProductItemCard extends StatelessWidget {
  22. final Product product;
  23.  
  24. ProductItemCard({@required this.product});
  25.  
  26. @override
  27. Widget build(BuildContext context) {
  28. return ScopedModelDescendant<ProductsModel>(
  29. builder: (context, child, model) => Card(
  30. child: Stack(
  31. children: <Widget>[
  32. Column(
  33. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  34. crossAxisAlignment: CrossAxisAlignment.start,
  35. children: <Widget>[
  36. Container(
  37. color: Colors.grey,
  38. height: 150,
  39. ),
  40. Column(
  41. crossAxisAlignment: CrossAxisAlignment.start,
  42. children: <Widget>[
  43. Text(product.name),
  44. Text(product.price.toString() + " yen"),
  45. ]),
  46. ],
  47. ),
  48. Positioned(
  49. right: 0.0,
  50. top: 130.0,
  51. child: RawMaterialButton(
  52. onPressed: () => model.addCartItem(product),
  53. shape: CircleBorder(),
  54. elevation: 2.0,
  55. fillColor: Colors.yellow,
  56. child: Icon(
  57. Icons.shopping_cart,
  58. size: 20,
  59. ),
  60. )
  61. )
  62. ],
  63. )
  64. )
  65. );
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement