shop_detail.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:sport/provider/lib/provider_widget.dart';
  4. import 'package:sport/provider/lib/view_state_lifecycle.dart';
  5. import 'package:sport/provider/shop_model.dart';
  6. import 'package:sport/widgets/appbar.dart';
  7. import 'package:sport/widgets/error.dart';
  8. import 'package:sport/widgets/space.dart';
  9. class ShopDetailPage extends StatefulWidget {
  10. @override
  11. State<StatefulWidget> createState() {
  12. return _ShopDetailPageState();
  13. }
  14. }
  15. class _ShopDetailPageState
  16. extends ViewStateLifecycle<ShopDetailPage, ScoreModel> {
  17. Widget _buildListItem(String name, String create, int score) {
  18. return Padding(
  19. padding: EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 12.0),
  20. child: Column(
  21. children: <Widget>[
  22. Row(
  23. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  24. children: <Widget>[
  25. Column(
  26. crossAxisAlignment: CrossAxisAlignment.start,
  27. children: <Widget>[
  28. Text(
  29. "$name",
  30. style:
  31. TextStyle(fontSize: 16.0, color: Color(0xff333333)),
  32. ),
  33. Space(
  34. height: 5.0,
  35. ),
  36. Text(
  37. "$create",
  38. style:
  39. TextStyle(color: Color(0xff999999), fontSize: 12.0),
  40. )
  41. ],
  42. ),
  43. Text(score > 0 ? "+$score 积分" : "-$score 积分",
  44. style: TextStyle(
  45. fontSize: 16.0,
  46. color: score < 0 ? Theme.of(context).accentColor : Color(0xffFF5B1D),
  47. )),
  48. ],
  49. ),
  50. Space(
  51. height: 10,
  52. ),
  53. Divider(),
  54. ],
  55. ));
  56. }
  57. @override
  58. Widget build(BuildContext context) {
  59. return Scaffold(
  60. appBar: buildAppBar(context, title: "积分明细"),
  61. backgroundColor: Colors.white,
  62. body: ProviderWidget<ScoreModel>(
  63. model: model,
  64. onModelReady: (v) => v.refresh(),
  65. builder: (_, model, __) {
  66. return CustomScrollView(slivers: [
  67. if (model.isIdle)
  68. SliverList(
  69. delegate: SliverChildBuilderDelegate(
  70. (context, index) {
  71. return _buildListItem(
  72. model.scoreList[index].detail ??"",
  73. model.scoreList[index].createdAt ??"",
  74. model.scoreList[index].score ??0);
  75. },
  76. childCount: model.scoreList.length,
  77. ),
  78. ),
  79. if (model.isEmpty)
  80. SliverFillRemaining(
  81. child: Center(
  82. child: RequestErrorWidget(
  83. null,
  84. msg: "暂无明细~",
  85. assets: RequestErrorWidget.ASSETS_NO_INVITATION,
  86. ),
  87. ),
  88. ),
  89. ]);
  90. },
  91. ));
  92. }
  93. @override
  94. ScoreModel createModel() {
  95. return new ScoreModel();
  96. }
  97. }