question_list.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/gaps.dart';
  3. import 'package:liftmanager/net/api_service.dart';
  4. import 'package:liftmanager/utils/toast.dart';
  5. import 'package:liftmanager/widgets/app_bar.dart';
  6. import 'package:liftmanager/internal/search/search_router.dart';
  7. import 'package:liftmanager/widgets/app_search_bar.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/widgets/load_image.dart';
  11. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  12. import 'package:liftmanager/widgets/bbs_content.dart';
  13. import 'package:flutter_screenutil/flutter_screenutil.dart';
  14. import 'package:liftmanager/mvp/base_page_state.dart';
  15. import 'package:liftmanager/internal/bbs/presenter/question_list_presenter.dart';
  16. import 'package:liftmanager/internal/bbs/model/mix_model.dart';
  17. import 'package:liftmanager/utils/time_format.dart';
  18. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  19. import 'package:liftmanager/widgets/state_layout.dart';
  20. import 'package:provider/provider.dart';
  21. import 'package:liftmanager/widgets/my_refresh_list.dart';
  22. import 'package:liftmanager/utils/url.dart';
  23. import 'package:flutter_spinkit/flutter_spinkit.dart';
  24. import 'dart:convert';
  25. import 'package:liftmanager/utils/theme_utils.dart';
  26. class QuestionList extends StatefulWidget {
  27. // QuestionList(this.index);
  28. // final String index;
  29. @override
  30. QuestionListState createState() => QuestionListState();
  31. }
  32. class QuestionListState
  33. extends BasePageState<QuestionList, QuestionListPresenterSeconds> {
  34. // NewsDetailItem item = NewsDetailItem();
  35. BaseListProvider<Records> provider = BaseListProvider<Records>();
  36. ScrollController _scrollController = new ScrollController();
  37. int _page = 1;
  38. int brandIdss;
  39. int exprtyIdss;
  40. String expertName;
  41. bool sortBool = true;
  42. String checkTypeName;
  43. String checkType;
  44. String brandName = "品牌";
  45. String masterName = "专家";
  46. String searchWord;
  47. @override
  48. void initState() {
  49. provider.setStateTypeNotNotify(StateType.loading);
  50. super.initState();
  51. _onRefresh();
  52. print(66666);
  53. }
  54. List<dynamic> typeList;
  55. List<dynamic> brandList;
  56. Future getBrandList() async {
  57. await NewApiService().getBrandListNoPage(
  58. onSuccess: (res) {
  59. if (res != null) {
  60. brandList = res;
  61. typeList = brandList;
  62. setState(() {});
  63. }
  64. }, onError: (code, msg) {
  65. toasts(msg);
  66. });
  67. }
  68. List<dynamic> expertList;
  69. Future getExpertList() async {
  70. await NewApiService().getExpertListNoPage(
  71. onSuccess: (res) {
  72. if (res != null) {
  73. expertList = res;
  74. typeList = expertList;
  75. setState(() {});
  76. }
  77. }, onError: (code, msg) {
  78. toasts(msg);
  79. });
  80. }
  81. @override
  82. void dispose() {
  83. _scrollController.dispose();
  84. super.dispose();
  85. }
  86. @override
  87. Widget build(BuildContext context) {
  88. double width = MediaQuery.of(context).size.width;
  89. double height = MediaQuery.of(context).size.height;
  90. return ChangeNotifierProvider<BaseListProvider<Records>>(
  91. create: (_) => provider,
  92. child: Scaffold(
  93. appBar: SearchAppBar2(
  94. onPressed: (text) {
  95. searchWord = text;
  96. _onRefresh();
  97. },
  98. ),
  99. body: Container(
  100. child: Stack(
  101. children: <Widget>[
  102. Column(
  103. children: <Widget>[
  104. Container(
  105. width: width,
  106. height: ScreenUtil().setWidth(50),
  107. decoration: BoxDecoration(
  108. border: Border(
  109. bottom: BorderSide(width: 0.5, color: Colours.line),
  110. ),
  111. ),
  112. padding: EdgeInsets.only(
  113. left: ScreenUtil().setWidth(15),
  114. right: ScreenUtil().setWidth(15)),
  115. // color: Color(0xFFF1F4FC),
  116. child: Row(
  117. children: <Widget>[
  118. GestureDetector(
  119. onTap: (){
  120. typeList = [];
  121. getBrandList();
  122. setState(() {
  123. sortBool = false;
  124. checkTypeName = "品牌";
  125. checkType = "brand";
  126. });
  127. },
  128. child: Row(
  129. children: <Widget>[
  130. Text(
  131. brandName,
  132. style: TextStyle(
  133. fontSize: ScreenUtil().setSp(16)),
  134. textAlign: TextAlign.start,
  135. ),
  136. Container(
  137. padding: EdgeInsets.only(top: 3),
  138. child: Icon(
  139. Icons.keyboard_arrow_down,
  140. size: 26.0,
  141. ),
  142. )
  143. ],
  144. ),
  145. ),
  146. SizedBox(width: ScreenUtil().setWidth(30)),
  147. GestureDetector(
  148. onTap: (){
  149. typeList = [];
  150. getExpertList();
  151. setState(() {
  152. sortBool = false;
  153. checkTypeName = "专家";
  154. checkType = "master";
  155. });
  156. },
  157. child: Row(
  158. children: <Widget>[
  159. Text(
  160. masterName,
  161. style: TextStyle(
  162. fontSize: ScreenUtil().setSp(16)),
  163. textAlign: TextAlign.start,
  164. ),
  165. Container(
  166. padding: EdgeInsets.only(top: 3),
  167. child: Icon(
  168. Icons.keyboard_arrow_down,
  169. size: 26.0,
  170. ),
  171. )
  172. ],
  173. ),
  174. ),
  175. ],
  176. )),
  177. Expanded(
  178. flex: 1,
  179. child: Consumer<BaseListProvider<Records>>(
  180. builder: (_, provider, __) {
  181. return MyListView(
  182. key: Key('question_list'),
  183. itemCount: provider.list.length,
  184. stateType: provider.stateType,
  185. onRefresh: _onRefresh,
  186. pageSize: 10,
  187. loadMore: _loadMore,
  188. hasMore: provider.hasMore,
  189. itemBuilder: (_, index) {
  190. return GestureDetector(
  191. child: Container(
  192. padding: EdgeInsets.only(
  193. left: ScreenUtil().setWidth(15),
  194. right: ScreenUtil().setWidth(10),
  195. top: ScreenUtil().setHeight(10),
  196. bottom: ScreenUtil().setHeight(10)),
  197. decoration: BoxDecoration(
  198. border: Border(
  199. bottom: BorderSide(
  200. width: 0.5, color: Colours.line),
  201. ),
  202. ),
  203. child: Column(
  204. crossAxisAlignment: CrossAxisAlignment.start,
  205. children: <Widget>[
  206. Text(
  207. "[${provider.list[index].brandName??""}]${provider.list[index].title??""}",
  208. textAlign: TextAlign.left,
  209. style: TextStyle(
  210. fontSize: ScreenUtil().setSp(15)),
  211. ),
  212. Container(
  213. padding: EdgeInsets.only(
  214. top: ScreenUtil().setHeight(10),
  215. bottom: ScreenUtil().setHeight(10)),
  216. child: Row(
  217. children: <Widget>[
  218. ClipRRect(
  219. borderRadius:
  220. BorderRadius.circular(
  221. ScreenUtil()
  222. .setWidth(18)),
  223. child: Container(
  224. child: LoadNetworkImage(
  225. provider.list[index].avatarUrl,
  226. // fit: BoxFit.fitWidth,
  227. width:
  228. ScreenUtil().setWidth(34),
  229. height:
  230. ScreenUtil().setWidth(34),
  231. ),
  232. )),
  233. Container(
  234. padding: EdgeInsets.only(
  235. left:
  236. ScreenUtil().setWidth(10)),
  237. child: Column(
  238. crossAxisAlignment:
  239. CrossAxisAlignment.start,
  240. children: <Widget>[
  241. Text(
  242. provider.list[index].userName??"",
  243. style: TextStyle(
  244. fontSize: ScreenUtil()
  245. .setSp(14),
  246. ),
  247. ),
  248. Text(
  249. DateUtils.instance
  250. .getFormartData(
  251. timeSamp: provider
  252. .list[index]
  253. .createTime,
  254. format: "yyyy-MM-dd"),
  255. style: TextStyle(
  256. fontSize: ScreenUtil()
  257. .setSp(12),
  258. color: Color(0xffaaaaaa)),
  259. ),
  260. ],
  261. ),
  262. )
  263. ],
  264. ),
  265. ),
  266. Text(
  267. provider.list[index].expression,
  268. textAlign: TextAlign.left,
  269. style: TextStyle(
  270. color: Color(0xff666666),
  271. fontSize: ScreenUtil().setSp(14),
  272. ),
  273. maxLines: 2,
  274. overflow: TextOverflow.ellipsis,
  275. ),
  276. Container(
  277. padding: EdgeInsets.only(
  278. top: ScreenUtil().setHeight(5),
  279. bottom: ScreenUtil().setHeight(5)),
  280. child: Row(
  281. mainAxisAlignment:
  282. MainAxisAlignment.start,
  283. children: provider.list[index].imgs !=
  284. null &&
  285. provider.list[index].imgs
  286. .isNotEmpty
  287. ? List<Widget>.from(provider
  288. .list[index].imgs
  289. .split(",")
  290. .asMap().keys.map((subindex) {
  291. // print(item);
  292. return subindex<3?Container(
  293. padding:subindex<provider
  294. .list[index].imgs.split(",").length-1?EdgeInsets.only(right:6):EdgeInsets.only(right:0),
  295. // color:Colors.red,
  296. // decoration: BoxDecoration(
  297. // borderRadius: BorderRadius.circular(20.0),
  298. // ),
  299. child: ClipRRect(
  300. borderRadius:
  301. BorderRadius.circular(
  302. 10),
  303. child: LoadNetworkImage(
  304. provider
  305. .list[index].imgs.split(",")[subindex],
  306. // height: width/375*75,
  307. height: ScreenUtil()
  308. .setWidth(80),
  309. width: ScreenUtil()
  310. .setWidth(110),
  311. isWater: true,
  312. ),
  313. ),
  314. ):Container(child: null,);
  315. }).toList())
  316. : <Widget>[]),
  317. ),
  318. Row(
  319. children: <Widget>[
  320. Row(
  321. crossAxisAlignment: CrossAxisAlignment.start,
  322. children: <Widget>[
  323. Text(
  324. "${provider.list[index].likeNum??"0"}",
  325. style: TextStyle(
  326. color: Color(0xff999999),
  327. fontSize: ScreenUtil().setSp(14)),
  328. textAlign: TextAlign.start,
  329. ),
  330. SizedBox(
  331. width:3
  332. ),
  333. Icon(
  334. IconData(0xe7cd,
  335. fontFamily: "myfont"),
  336. size: 14.0,
  337. color: Color(0xff999999),
  338. ),
  339. ],
  340. ),
  341. SizedBox(
  342. width:15
  343. ),
  344. Row(
  345. crossAxisAlignment: CrossAxisAlignment.start,
  346. children: <Widget>[
  347. Text(
  348. "${provider.list[index].browseNum??"0"}",
  349. style: TextStyle(
  350. color: Color(0xff999999),
  351. fontSize: ScreenUtil().setSp(14)),
  352. textAlign: TextAlign.start,
  353. ),
  354. SizedBox(
  355. width:3
  356. ),
  357. Icon(
  358. IconData(0xe610,
  359. fontFamily: "myfont"),
  360. size: 14.0,
  361. color: Color(0xff999999),
  362. ),
  363. ],
  364. ),
  365. ],
  366. )
  367. ]),
  368. ),
  369. onTap: () {
  370. // print(item);
  371. NavigatorUtils.push(context,
  372. "${BbsRouter.questionDetail}?id=${provider.list[index].id.toString()}");
  373. },
  374. );
  375. },
  376. );
  377. }))
  378. ],
  379. ),
  380. !sortBool?
  381. Positioned(
  382. top:0,
  383. left:0,
  384. child: GestureDetector(
  385. onTap: (){
  386. setState(() {
  387. sortBool = true;
  388. });
  389. },
  390. child: Container(
  391. width:width,
  392. height:height,
  393. color: Color.fromRGBO(0, 0, 0, 0.5)
  394. ),
  395. )
  396. )
  397. :Container(
  398. child:null
  399. ),
  400. !sortBool?
  401. Positioned(
  402. top:0,
  403. left:0,
  404. child:Container(
  405. width: width,
  406. height:height/2,
  407. color: ThemeUtils.getDialogTextFieldColor(context),
  408. padding: EdgeInsets.all(10),
  409. child:ListView(
  410. children:<Widget>[
  411. GestureDetector(
  412. onTap: (){
  413. if(checkType=="brand"){
  414. setState(() {
  415. brandIdss = null;
  416. brandName = '品牌';
  417. sortBool = true;
  418. _onRefresh();
  419. });
  420. }else if (checkType=="master"){
  421. setState(() {
  422. exprtyIdss = null;
  423. masterName = '专家';
  424. expertName = null;
  425. sortBool = true;
  426. _onRefresh();
  427. });
  428. }
  429. },
  430. child:Container(
  431. padding: EdgeInsets.only(left:5,top:5,bottom:10),
  432. child:Text(
  433. checkTypeName,
  434. style: TextStyle(
  435. color:Color(0xff666666),
  436. fontSize:ScreenUtil().setSp(16)
  437. ),
  438. textAlign:TextAlign.start,
  439. ),
  440. )
  441. ),
  442. typeList!=null&&typeList!=[]?Container(
  443. child: Wrap(
  444. alignment: WrapAlignment.start,
  445. crossAxisAlignment: WrapCrossAlignment.center,
  446. children: typeList.asMap().keys.map((index){
  447. return InkWell(
  448. onTap: (){
  449. print("666");
  450. setState(() {
  451. sortBool = true;
  452. if(checkType=="brand"){
  453. brandName = typeList[index].name??"";
  454. brandIdss = typeList[index].id;
  455. provider.setStateTypeNotNotify(StateType.loading);
  456. _onRefresh();
  457. }else if(checkType=="master"){
  458. masterName= typeList[index].name??'';
  459. exprtyIdss= int.parse(typeList[index].userId);
  460. expertName= typeList[index].name;
  461. provider.setStateTypeNotNotify(StateType.loading);
  462. _onRefresh();
  463. }
  464. });
  465. },
  466. child: Container(
  467. width: width/4-15,
  468. padding: EdgeInsets.only(bottom:ScreenUtil().setWidth(10),top:ScreenUtil().setWidth(10)),
  469. margin: EdgeInsets.only(left:5,right:5,bottom:5,top:5),
  470. decoration: BoxDecoration(
  471. // border: Border(
  472. // bottom: BorderSide(width: 0.5, color: Colours.line),
  473. // ),
  474. color: Color(0xfff5f5f5)
  475. ),
  476. child:Text(
  477. typeList[index].name??"",
  478. style: TextStyle(
  479. color:checkThis(checkType=="brand"?typeList[index].id:typeList[index].userId)?Color(0xffff0000):Color(0xff666666),
  480. fontSize:ScreenUtil().setSp(15)
  481. ),
  482. textAlign:TextAlign.center,
  483. maxLines: 1,
  484. overflow: TextOverflow.ellipsis,
  485. ),
  486. ),
  487. );
  488. }).toList(),
  489. )
  490. ):loadCircle()
  491. ],
  492. )
  493. )
  494. ):
  495. Container(
  496. child:null
  497. ),
  498. ],
  499. )
  500. )
  501. ));
  502. }
  503. checkThis(id){
  504. bool isName = false;
  505. if((checkType == "brand" && brandIdss == id) || (checkType == "master" && exprtyIdss == int.parse(id))){
  506. isName = true;
  507. }
  508. return isName;
  509. }
  510. Widget loadCircle() {
  511. return Container(
  512. padding: EdgeInsets.only(top: 10, bottom: 10),
  513. color: ThemeUtils.getTabsBg(context),
  514. child: Center(
  515. child: SpinKitFadingCircle(
  516. color: Colors.blueAccent,
  517. size: 30.0,
  518. ),
  519. ),
  520. );
  521. }
  522. Future _onRefresh() async {
  523. _page = 1;
  524. await presenter.getQuestionList(_page,brandIdss,expertName,searchWord);
  525. }
  526. Future _loadMore() async {
  527. _page++;
  528. await presenter.getQuestionList(_page,brandIdss,expertName,searchWord);
  529. }
  530. @override
  531. QuestionListPresenterSeconds createPresenter() {
  532. return QuestionListPresenterSeconds();
  533. }
  534. }