brand_page.dart 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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:flutter_screenutil/flutter_screenutil.dart';
  13. import 'package:flutter_spinkit/flutter_spinkit.dart';
  14. import 'dart:math';
  15. import 'dart:convert';
  16. import 'package:liftmanager/utils/url.dart';
  17. import 'package:liftmanager/utils/theme_utils.dart';
  18. class BrandPage extends StatefulWidget {
  19. BrandPage(this.index);
  20. final String index;
  21. @override
  22. State<StatefulWidget> createState() {
  23. return BrandPageState();
  24. }
  25. }
  26. class BrandPageState extends State<BrandPage> {
  27. // NewsDetailItem item = NewsDetailItem();
  28. ScrollController _scrollController = new ScrollController();
  29. @override
  30. void initState() {
  31. super.initState();
  32. getBrandList();
  33. }
  34. var changeList;
  35. List<dynamic> brandListPage;
  36. String title;
  37. int indexNow;
  38. Future getBrandList() async {
  39. await NewApiService().getBrandListType(title,onSuccess: (res) {
  40. // brandListPage = res.records;
  41. print(jsonEncode(res));
  42. changeList = res;
  43. print(456);
  44. // changeList = res.where((item)=>(item["listBrand"] as List).length>0);
  45. setState(() {});
  46. }, onError: (code, msg) {
  47. toasts(msg);
  48. });
  49. }
  50. @override
  51. void dispose() {
  52. _scrollController.dispose();
  53. super.dispose();
  54. }
  55. static bool isChinese(String value) {
  56. return RegExp(
  57. r"^[\u4e00-\u9fa5]+$")
  58. .hasMatch(value);
  59. }
  60. // 文本编辑控制
  61. TextEditingController _textEditingController = new TextEditingController();
  62. // 焦点控制
  63. FocusNode _focusNode1 = new FocusNode();
  64. @override
  65. Widget build(BuildContext context) {
  66. double width = MediaQuery.of(context).size.width;
  67. double height = MediaQuery.of(context).size.height;
  68. // 监听FocusNode
  69. _focusNode1.addListener((){
  70. // _focusNode1.hasFocus 是否聚焦
  71. print(_focusNode1.hasFocus);
  72. });
  73. return Scaffold(
  74. appBar: SearchAppBar2(
  75. onPressed: (text) {
  76. title = text;
  77. getBrandList();
  78. },
  79. ),
  80. body:changeList!=null?Container(
  81. child: Stack(
  82. children: <Widget>[
  83. // Positioned(
  84. // left: 0,
  85. // top: 0,
  86. // child: FlatButton(
  87. // padding: EdgeInsets.symmetric(horizontal: 0),
  88. // child: Container(
  89. // width: width,
  90. // height: ScreenUtil().setWidth(48),
  91. // padding: EdgeInsets.only(top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10),left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15)),
  92. // // color: Color(0xFFF1F4FC),
  93. // color: ThemeUtils.getDialogTextFieldColor(context),
  94. // child:Row(
  95. // children: <Widget>[
  96. // Container(
  97. // padding: EdgeInsets.only(right:ScreenUtil().setWidth(10)),
  98. // child: Icon(
  99. // IconData(
  100. // 0xe6dd,
  101. // fontFamily:"myfont"
  102. // ),
  103. // size: 24.0,
  104. // color:Color(0xffcccccc),
  105. // ),
  106. // ),
  107. // Text(
  108. // "自定义品牌",
  109. // style: TextStyle(
  110. // fontSize:ScreenUtil().setSp(16)
  111. // ),
  112. // textAlign:TextAlign.start,
  113. // ),
  114. // ],
  115. // )
  116. // ),
  117. // onPressed: (){
  118. // showDialog(
  119. // context: context,
  120. // barrierDismissible: true, // 是否可以点击底部遮罩层取消dialog
  121. // // child: Text('data')
  122. // builder: (context) {
  123. // return Container(
  124. // child: AlertDialog(
  125. // backgroundColor:ThemeUtils.getDialogTextFieldColor(context),
  126. // title: Text('品牌名称:'),
  127. // titlePadding: EdgeInsets.fromLTRB(24.0, 24.0, 0.0, 0.0),
  128. // titleTextStyle: TextStyle( fontSize: ScreenUtil().setSp(16)),
  129. // content: Container(
  130. // height: ScreenUtil().setWidth(30),
  131. // child: TextField(
  132. // /*
  133. // * _textEditingController.text是当前文本
  134. // * initialValue + onChanged 也可以实现获取当前文本
  135. // *
  136. // * onChanged是专门用于监听文本变化
  137. // * 而controller 除了能监听文本变化外,它还可以设置默认值、选择文本
  138. // */
  139. // controller: _textEditingController,
  140. // // textInputAction: TextInputAction.go, // 输入框的确定按钮
  141. // focusNode: _focusNode1,
  142. // decoration: InputDecoration(
  143. // contentPadding: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(5),),
  144. // border: OutlineInputBorder(
  145. // borderRadius: BorderRadius.circular(2.0),
  146. // // borderSide: BorderSide(color: Colors.red, width: 3.0, style: BorderStyle.solid)//没什么卵效果
  147. // ),
  148. // // labelText: 'TextField', // 上标
  149. // // icon: Icon(Icons.ac_unit), // Field外部
  150. // hintText: '请输入', // hint 暗示
  151. // // helperText: '左下角', // helper 帮手
  152. // hasFloatingPlaceholder: false, // labelText是否漂浮
  153. // // errorText: '错误文本',
  154. // errorBorder: InputBorder.none, // 当error时的border
  155. // // prefixIcon: Icon(Icons.phone_iphone), // Field前边
  156. // // 后缀和前缀在focus时显示
  157. // // prefixText: '前缀', // 前缀
  158. // // prefix: Text('prefix'),
  159. // // suffixText: '后缀', // 后缀
  160. // // counterText: '右下角', // 计数器
  161. // filled: false, // 背景色
  162. // // fillColor: Colors.cyan.withAlpha(35),
  163. // focusedBorder: OutlineInputBorder(), // 当focus时的border
  164. // // semanticCounterText: '222'
  165. // ),
  166. // // keyboardType: TextInputType.numberWithOptions(),
  167. // cursorColor: Color(0xFF999999),
  168. // obscureText: false, // 输入变成**
  169. // onChanged: (val) {
  170. // // xxx
  171. // },
  172. // ),
  173. // ),
  174. // contentPadding: EdgeInsets.fromLTRB(24.0, 20.0, 24.0, 24.0),
  175. // contentTextStyle: TextStyle(fontSize: ScreenUtil().setSp(14)),
  176. // actions: <Widget>[
  177. // Container(
  178. // height:36,
  179. // decoration: BoxDecoration(
  180. // gradient: const LinearGradient(
  181. // colors: [Color(0xFF00D9FF), Color(0xFF0287FF)]),
  182. // ),
  183. // child: FlatButton(
  184. // child: Text('确认',style: TextStyle(color:Colors.white),),
  185. // onPressed: (){
  186. // print(_textEditingController.text);
  187. // if(_textEditingController.text.trim()== null){
  188. // toasts("请输入");
  189. // return;
  190. // }
  191. // if(!isChinese(_textEditingController.text)){
  192. // toasts("请输入中文");
  193. // return;
  194. // }
  195. // NewApiService().addBrand(_textEditingController.text, onSuccess: (res) {
  196. // toasts("自定义品牌成功");
  197. // getBrandList();
  198. // setState(() {});
  199. // _textEditingController.text = "";
  200. // Navigator.maybePop(context);
  201. // }, onError: (code, msg) {
  202. // toasts(msg);
  203. // _textEditingController.text = "";
  204. // Navigator.maybePop(context);
  205. // });
  206. // },
  207. // ),
  208. // ),
  209. // FlatButton(
  210. // color: Color(0xffcccccc),
  211. // child: Text('取消',style: TextStyle(color:Colors.white),),
  212. // onPressed: (){
  213. // Navigator.maybePop(context);
  214. // _textEditingController.text = "";
  215. // },
  216. // ),
  217. // ],
  218. // semanticLabel: 'semanticLabel',
  219. // shape: Border.all(color: Colors.white),
  220. // elevation: 22
  221. // ),
  222. // );
  223. // }
  224. // );
  225. // },
  226. // )
  227. // ),
  228. Container(
  229. // padding: EdgeInsets.only(top:ScreenUtil().setWidth(48)),
  230. child:ListView(
  231. controller:_scrollController,
  232. children:<Widget>[
  233. Brand(initList:(changeList.toList()),getIndex:widget.index)
  234. ]
  235. ),
  236. ),
  237. Positioned(
  238. right: 0,
  239. top: ScreenUtil().setWidth(50),
  240. child: Container(
  241. width:ScreenUtil().setWidth(40),
  242. // color: Colors.grey,
  243. height: height*0.8,
  244. child:Azlist(initList:(changeList.toList()),new_scrollController:_scrollController,indexNow: indexNow,fun:(i){
  245. setState(() {
  246. indexNow = i;
  247. });
  248. }),
  249. )
  250. ),
  251. ],
  252. )
  253. ):Center(
  254. child: Text("正在加载..."),
  255. ),
  256. );
  257. }
  258. Widget loadCircle() {
  259. return Container(
  260. padding: EdgeInsets.only(top: 10, bottom: 10),
  261. color: ThemeUtils.getTabsBg(context),
  262. child: Center(
  263. child: SpinKitFadingCircle(
  264. color: Colors.blueAccent,
  265. size: 30.0,
  266. ),
  267. ),
  268. );
  269. }
  270. }
  271. class Azlist extends StatelessWidget {
  272. Azlist({Key key,this.initList,this.new_scrollController,this.indexNow,this.fun}) : super(key: key);
  273. List<dynamic> initList;
  274. ScrollController new_scrollController;
  275. int indexNow;
  276. Function fun;
  277. static const word = ["热门","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","#"];
  278. List<Widget> list(context) => word.asMap().keys.map((i){
  279. double width = MediaQuery.of(context).size.width;
  280. return Expanded(
  281. // height: 16,
  282. child: GestureDetector(
  283. child: Container(
  284. width: ScreenUtil().setWidth(33),
  285. // padding: EdgeInsets.only(left:15,top:5,bottom:5),
  286. // color:Colors.red,
  287. child: Text(
  288. word[i],
  289. style: TextStyle(
  290. // color:Color(0xffff0000),
  291. color:Color(0xff0288FF),
  292. // color:indexNow == i?Color(0xffff0000):Color(0xff0288FF),
  293. fontSize:i==0?ScreenUtil().setSp(13):ScreenUtil().setSp(14)
  294. ),
  295. textAlign:TextAlign.center,
  296. ),
  297. ),
  298. onTap: (){
  299. print(i);
  300. fun(i);
  301. print(1 ~/ 2);
  302. double nums = 0.0;
  303. for(var k = 0; k< initList.length; k++){
  304. if(initList[k].name == word[i]){
  305. double lastNums = nums + 30.0*k;
  306. print(lastNums);
  307. double numsFinal = ScreenUtil().setWidth(lastNums);
  308. new_scrollController.animateTo(numsFinal,
  309. duration: Duration(milliseconds: 500),
  310. curve: Curves.decelerate);
  311. }
  312. int a = ((initList[k].listBrand as List).length ~/ 4);
  313. int b;
  314. if((initList[k].listBrand as List).length % 4 == 0){
  315. b = 0;
  316. }else {
  317. b = 1;
  318. }
  319. nums += (a+b) * 100.0;
  320. }
  321. },
  322. ),
  323. );
  324. }).toList();
  325. @override
  326. Widget build(BuildContext context) {
  327. return Container(
  328. padding: EdgeInsets.only(bottom:5),
  329. child: Column(
  330. crossAxisAlignment: CrossAxisAlignment.center,
  331. children:list(context),
  332. ),
  333. );
  334. }
  335. }
  336. class Brand extends StatelessWidget {
  337. Brand({Key key,this.initList,this.getIndex}) : super(key: key);
  338. List<dynamic> initList;
  339. String getIndex;
  340. List<Widget> brandList(context) => initList.map((i){
  341. double width = MediaQuery.of(context).size.width;
  342. return Column(
  343. crossAxisAlignment: CrossAxisAlignment.start,
  344. children:<Widget>[
  345. Container(
  346. width: width,
  347. height: ScreenUtil().setWidth(30),
  348. color:ThemeUtils.getDialogTextFieldColor(context),
  349. padding: EdgeInsets.only(left:ScreenUtil().setWidth(15)),
  350. child: Row(
  351. crossAxisAlignment: CrossAxisAlignment.center,
  352. children:<Widget>[
  353. Text(
  354. i.name,
  355. style: TextStyle(
  356. fontSize:ScreenUtil().setSp(16)
  357. ),
  358. textAlign:TextAlign.start,
  359. ),
  360. ]
  361. )
  362. ),
  363. Container(
  364. // color: Colors.yellow,
  365. // height: ScreenUtil().setWidth(200),
  366. child:Wrap(
  367. // spacing: 16,
  368. alignment: WrapAlignment.start,
  369. crossAxisAlignment: WrapCrossAlignment.center,
  370. children: (i.listBrand as List).map((item){
  371. return Container(
  372. // color:Colors.yellow,
  373. height: ScreenUtil().setWidth(100),
  374. child: FlatButton(
  375. padding: EdgeInsets.all(0),
  376. highlightColor:Colors.white,
  377. splashColor: Colors.white,
  378. child:Container(
  379. width: width/4,
  380. height: ScreenUtil().setWidth(100),
  381. // color: Colors.red,
  382. padding: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(10),top:ScreenUtil().setWidth(10)),
  383. child: Column(
  384. mainAxisAlignment: MainAxisAlignment.start,
  385. children:<Widget>[
  386. Container(
  387. // height: 70,
  388. // color: Colors.red,
  389. child: LoadNetworkImage(
  390. item.logo,
  391. width: ScreenUtil().setWidth(60),
  392. height:ScreenUtil().setWidth(50),
  393. fit:BoxFit.contain
  394. // alignment: Alignment.centerLeft,
  395. )
  396. ),
  397. Container(
  398. child: Text(
  399. item.name,
  400. style: TextStyle(
  401. color:Color(0xff666666),
  402. fontSize:ScreenUtil().setSp(15)
  403. ),
  404. textAlign:TextAlign.start,
  405. maxLines: 1,
  406. overflow: TextOverflow.ellipsis,
  407. ),
  408. ),
  409. ]
  410. ),
  411. ),
  412. onPressed: (){
  413. print(999);
  414. print(getIndex);
  415. if(getIndex == "0"){
  416. print(item.name);
  417. print(item.id);
  418. NavigatorUtils.push(context, "${BbsRouter.interrogationPage}?brandName=${Uri.encodeComponent(item.name)}&brandId=${item.id.toString()}");
  419. }else if (getIndex == "1"){
  420. // NavigatorUtils.push(context, BbsRouter.visitPage);
  421. NavigatorUtils.push(context, "${BbsRouter.visitPage}?brandName=${Uri.encodeComponent(item.name)}&brandId=${item.id.toString()}");
  422. }
  423. },
  424. ),
  425. );
  426. }).toList()
  427. )
  428. )
  429. ]
  430. );
  431. }).toList();
  432. @override
  433. Widget build(BuildContext context) {
  434. return Container(
  435. padding: EdgeInsets.only(top:ScreenUtil().setWidth(5)),
  436. child: Column(
  437. children: <Widget>[
  438. Column(
  439. children: brandList(context),
  440. )
  441. ],
  442. )
  443. );
  444. }
  445. }