mall_recommend.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_note/routers/application.dart';
  3. import 'package:flutter_note/model/home_page_model.dart';
  4. import 'package:flutter_note/routers/routers.dart';
  5. class RecommendWidget extends StatelessWidget {
  6. final List<Recommend> recommendList;
  7. RecommendWidget({Key key, @required this.recommendList}) : super(key: key);
  8. Widget _recommendTitle() {
  9. return Container(
  10. alignment: Alignment.center,
  11. padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 6.0),
  12. decoration: BoxDecoration(
  13. border:
  14. Border(bottom: BorderSide(color: Colors.black12, width: 1.0))),
  15. child: Text('商品推荐', style: TextStyle(color: Colors.pink)),
  16. );
  17. }
  18. Widget _recommendItem(BuildContext context, int index) {
  19. return InkWell(
  20. onTap: () {
  21. Application.router.navigateTo(context,
  22. Routers.generateDetailsRouterPath(recommendList[index].goodsId));
  23. },
  24. child: Container(
  25. width: MediaQuery.of(context).size.width / 3,
  26. height: 180.0,
  27. alignment: Alignment.center,
  28. decoration: BoxDecoration(
  29. border: Border(
  30. left: BorderSide(color: Colors.black12),
  31. bottom: BorderSide(color: Colors.black12),
  32. ),
  33. color: Colors.white),
  34. child: Column(
  35. mainAxisAlignment: MainAxisAlignment.center,
  36. children: [
  37. Image.network(recommendList[index].image, height: 120.0),
  38. Text('¥${recommendList[index].mallPrice}',
  39. style: TextStyle(fontSize: 16.0)),
  40. Text('¥${recommendList[index].price}',
  41. style: TextStyle(
  42. decoration: TextDecoration.lineThrough,
  43. decorationColor: Colors.black45))
  44. ]),
  45. ),
  46. );
  47. }
  48. @override
  49. Widget build(BuildContext context) {
  50. return SliverToBoxAdapter(
  51. child: Container(
  52. alignment: Alignment.center,
  53. margin: const EdgeInsets.only(top: 6.0),
  54. child: Column(
  55. mainAxisAlignment: MainAxisAlignment.center,
  56. children: [
  57. _recommendTitle(),
  58. SizedBox(
  59. height: 180.0,
  60. child: ListView.builder(
  61. itemBuilder: _recommendItem,
  62. itemCount: this.recommendList.length,
  63. scrollDirection: Axis.horizontal),
  64. )
  65. ]),
  66. ),
  67. );
  68. }
  69. }