OfflineActivityPage.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import '../util/NetUtils.dart';
  4. import '../api/Api.dart';
  5. import '../pages/CommonWebPage.dart';
  6. // 线下活动
  7. class OfflineActivityPage extends StatefulWidget {
  8. @override
  9. State<StatefulWidget> createState() {
  10. return new OfflineActivityPageState();
  11. }
  12. }
  13. class OfflineActivityPageState extends State<OfflineActivityPage> {
  14. String eventTypeLatest = "latest";
  15. String eventTypeYch = "ych";
  16. String eventTypeRec = "recommend";
  17. int curPage = 1;
  18. TextStyle titleTextStyle = new TextStyle(color: Colors.black, fontSize: 18.0);
  19. List recData, latestData, ychData;
  20. @override
  21. void initState() {
  22. super.initState();
  23. getData(eventTypeRec);
  24. getData(eventTypeLatest);
  25. getData(eventTypeYch);
  26. }
  27. void getData(String type) {
  28. String url = Api.EVENT_LIST;
  29. url += "$type?pageIndex=$curPage&pageSize=5";
  30. NetUtils.get(url).then((data) {
  31. if (data != null) {
  32. var obj = json.decode(data);
  33. if (obj != null && obj['code'] == 0) {
  34. print(obj);
  35. setState(() {
  36. if (type == eventTypeRec) {
  37. recData = obj['msg'];
  38. } else if (type == eventTypeLatest) {
  39. latestData = obj['msg'];
  40. } else {
  41. ychData = obj['msg'];
  42. }
  43. });
  44. }
  45. }
  46. });
  47. }
  48. Widget getRecBody() {
  49. if (recData == null) {
  50. return new Center(child: new CircularProgressIndicator());
  51. } else if (recData.length == 0) {
  52. return new Center(child: new Text("暂无数据"));
  53. } else {
  54. return new ListView.builder(itemBuilder: _renderRecRow, itemCount: recData.length);
  55. }
  56. }
  57. Widget getLatestBody() {
  58. if (latestData == null) {
  59. return new Center(child: new CircularProgressIndicator());
  60. } else if (latestData.length == 0) {
  61. return new Center(child: new Text("暂无数据"));
  62. } else {
  63. return new ListView.builder(itemBuilder: _renderLatestRow, itemCount: latestData.length);
  64. }
  65. }
  66. Widget getYchBody() {
  67. if (ychData == null) {
  68. return new Center(child: new CircularProgressIndicator());
  69. } else if (ychData.length == 0) {
  70. return new Center(child: new Text("暂无数据"));
  71. } else {
  72. return new ListView.builder(itemBuilder: _renderYchRow, itemCount: ychData.length);
  73. }
  74. }
  75. Widget getCard(itemData) {
  76. return new Card(
  77. child: new Column(
  78. children: <Widget>[
  79. new Image.network(itemData['cover'], fit: BoxFit.cover,),
  80. new Container(
  81. margin: const EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
  82. alignment: Alignment.centerLeft,
  83. child: new Text(itemData['title'], style: titleTextStyle,),
  84. ),
  85. new Container(
  86. margin: const EdgeInsets.fromLTRB(10.0, 0.0, 10.0, 5.0),
  87. child: new Row(
  88. children: <Widget>[
  89. new Expanded(child: new Text(itemData['authorName']), flex: 1,),
  90. new Text(itemData['timeStr'])
  91. ],
  92. )
  93. )
  94. ],
  95. ),
  96. );
  97. }
  98. Widget _renderRecRow(BuildContext ctx, int i) {
  99. Map itemData = recData[i];
  100. return new InkWell(
  101. child: getCard(itemData),
  102. onTap: () {
  103. _showDetail(itemData['detailUrl']);
  104. },
  105. );
  106. }
  107. Widget _renderLatestRow(BuildContext ctx, int i) {
  108. Map itemData = latestData[i];
  109. return new InkWell(
  110. child: getCard(itemData),
  111. onTap: () {
  112. _showDetail(itemData['detailUrl']);
  113. },
  114. );
  115. }
  116. Widget _renderYchRow(BuildContext ctx, int i) {
  117. Map itemData = ychData[i];
  118. return new InkWell(
  119. child: getCard(itemData),
  120. onTap: () {
  121. _showDetail(itemData['detailUrl']);
  122. },
  123. );
  124. }
  125. _showDetail(detailUrl) {
  126. Navigator.of(context).push(new MaterialPageRoute(
  127. builder: (ctx) {
  128. return new CommonWebPage(title: '活动详情', url: detailUrl);
  129. }
  130. ));
  131. }
  132. @override
  133. Widget build(BuildContext context) {
  134. return new Scaffold(
  135. appBar: new AppBar(
  136. title: new Text("线下活动", style: new TextStyle(color: Colors.white)),
  137. iconTheme: new IconThemeData(color: Colors.white),
  138. ),
  139. body: new DefaultTabController(
  140. length: 3,
  141. child: new Scaffold(
  142. appBar: new TabBar(
  143. tabs: <Widget>[
  144. new Tab(
  145. text: "强力推荐",
  146. ),
  147. new Tab(
  148. text: "最新活动",
  149. ),
  150. new Tab(
  151. text: "源创会",
  152. )
  153. ],
  154. ),
  155. body: new TabBarView(
  156. children: <Widget>[
  157. getRecBody(),
  158. getLatestBody(),
  159. getYchBody()
  160. ],
  161. )),
  162. ),
  163. );
  164. }
  165. }