privilege.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:flutter_swiper/flutter_swiper.dart';
  5. import 'package:liftmanager/internal/account/provider/user_provider.dart';
  6. import 'package:liftmanager/internal/wode/model/privilege_model.dart';
  7. import 'package:liftmanager/net/api_service.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/utils/toast.dart';
  10. import 'package:liftmanager/widgets/app_bar.dart';
  11. import 'package:liftmanager/widgets/load_image.dart';
  12. import 'package:provider/provider.dart';
  13. class Privilege extends StatefulWidget {
  14. Privilege(this.id, this.index);
  15. final String id;
  16. String index;
  17. @override
  18. State<StatefulWidget> createState() {
  19. return PrivilegeState();
  20. }
  21. }
  22. class PrivilegeState extends State<Privilege>
  23. with AutomaticKeepAliveClientMixin {
  24. UserProvider provider = UserProvider();
  25. List<MenuList> privilegeList = [];
  26. MenuList _currentModel = MenuList();
  27. ScrollController _scrollController = ScrollController();
  28. @override
  29. void initState() {
  30. // getAllMenu();
  31. super.initState();
  32. }
  33. @override
  34. void dispose() {
  35. super.dispose();
  36. }
  37. void getAllMenu() {
  38. NewApiService().getAllMenu(widget.id, onSuccess: (res) {
  39. setState(() {
  40. privilegeList = res;
  41. if (widget.index != null) {
  42. for (MenuList item in privilegeList) {
  43. if (item.id == int.parse(widget.index)) {
  44. _currentModel = item;
  45. int index = privilegeList.indexOf(_currentModel);
  46. double width = MediaQuery.of(context).size.width;
  47. if (index * 80 > width - 60) {
  48. _scrollController.animateTo(
  49. _scrollController.position.maxScrollExtent,
  50. duration: const Duration(milliseconds: 500),
  51. curve: Curves.easeOut);
  52. } else {
  53. _scrollController.animateTo(0,
  54. duration: const Duration(milliseconds: 500),
  55. curve: Curves.easeOut);
  56. }
  57. }
  58. }
  59. // _currentModel = privilegeList[0];
  60. } else {
  61. _currentModel = privilegeList[0];
  62. }
  63. });
  64. }, onError: (code, msg) {
  65. privilegeList = [];
  66. toasts(msg);
  67. });
  68. }
  69. List<Widget> listWidget(context) => privilegeList.map((item) {
  70. // double width = MediaQuery.of(context).size.width;
  71. double width = MediaQuery.of(context).size.width;
  72. return GestureDetector(
  73. child: Container(
  74. // margin: EdgeInsets.only(right: 10),
  75. padding: EdgeInsets.only(top: 20, bottom: 20),
  76. child: Row(
  77. children: <Widget>[
  78. // SizedBox(width: ScreenUtil().setWidth( 10)),
  79. Container(
  80. width: 80,
  81. // padding: EdgeInsets.only(top: 10, bottom: 10),
  82. // decoration: BoxDecoration(
  83. // color: ThemeUtils.getTabsBg(context),
  84. // borderRadius: BorderRadius.circular(5),
  85. // boxShadow: [
  86. // BoxShadow(
  87. // offset: Offset(0, 0), //x,y轴
  88. // color: Colors.grey[300], //投影颜色
  89. // blurRadius: 5, //投影距离
  90. // )
  91. // ],
  92. // ),
  93. child: Column(
  94. crossAxisAlignment: CrossAxisAlignment.center,
  95. children: <Widget>[
  96. // Icon(
  97. // IconData(initList[i]['icon'], fontFamily: "Iconfont"),
  98. // size: 24.0,
  99. // color: Color.fromRGBO(51, 51, 51, 1),
  100. // ),
  101. Container(
  102. // margin: EdgeInsets.only(bottom:0),
  103. child: LoadNetworkImage(
  104. item.image,
  105. width: 55,
  106. height: 55,
  107. fit: BoxFit.fitHeight,
  108. ),
  109. ),
  110. Text(
  111. item.name ?? '',
  112. textAlign: TextAlign.start,
  113. style: TextStyle(
  114. color: _currentModel.name == item.name
  115. ? Color(0xffCC9E63)
  116. : Colours.text_gray_c,
  117. fontSize: ScreenUtil().setSp(12),
  118. ),
  119. ),
  120. // Text(
  121. // item.descr ?? '',
  122. // textAlign: TextAlign.start,
  123. // style: TextStyle(
  124. // fontSize: ScreenUtil().setSp(14),
  125. // color: Color(0xff999999),
  126. // ),
  127. // overflow: TextOverflow.ellipsis,
  128. // ),
  129. ],
  130. ),
  131. ),
  132. ],
  133. ),
  134. ),
  135. onTap: () {
  136. setState(() {
  137. _currentModel = item;
  138. });
  139. },
  140. );
  141. }).toList();
  142. @override
  143. Widget build(BuildContext context) {
  144. double width = MediaQuery.of(context).size.width;
  145. double height = MediaQuery.of(context).size.height;
  146. return ChangeNotifierProvider<UserProvider>(
  147. create: (_) {
  148. getAllMenu();
  149. return provider;
  150. },
  151. child: Container(
  152. child: Scaffold(
  153. resizeToAvoidBottomPadding: false,
  154. appBar: MyAppBar(
  155. centerTitle: "会员特权",
  156. ),
  157. body: Consumer<UserProvider>(
  158. builder: (_, provider, __) {
  159. return Container(
  160. child: Column(
  161. children: [
  162. Container(
  163. height: 120,
  164. child: ScrollConfiguration(
  165. behavior: CusBehavior(),
  166. child: ListView(
  167. controller: _scrollController,
  168. scrollDirection: Axis.horizontal,
  169. padding: EdgeInsets.all(0.0),
  170. children: listWidget(context),
  171. ),
  172. )),
  173. Container(
  174. child: SwipeWidget(
  175. // banners: privilegeList,
  176. defultModel: _currentModel,
  177. privilegeList: privilegeList,
  178. onChangItem: (int index, MenuList model) {
  179. setState(() {
  180. _currentModel = model;
  181. });
  182. print(_scrollController.offset);
  183. if (index * 80 > width - 60) {
  184. _scrollController.animateTo(
  185. _scrollController.position.maxScrollExtent,
  186. duration: const Duration(milliseconds: 500),
  187. curve: Curves.easeOut);
  188. } else {
  189. _scrollController.animateTo(0,
  190. duration: const Duration(milliseconds: 500),
  191. curve: Curves.easeOut);
  192. }
  193. },
  194. onClickItem: (int index, MenuList model) {
  195. setState(() {
  196. _currentModel = model;
  197. });
  198. },
  199. ),
  200. )
  201. ],
  202. ),
  203. );
  204. },
  205. ),
  206. ),
  207. ),
  208. );
  209. }
  210. @override
  211. bool get wantKeepAlive => true;
  212. }
  213. class SwipeWidget extends StatelessWidget {
  214. SwipeWidget({
  215. Key key,
  216. this.privilegeList,
  217. this.banners,
  218. this.onClickItem,
  219. this.onChangItem,
  220. this.defultModel,
  221. }) : super(key: key);
  222. final List<dynamic> banners;
  223. final List<MenuList> privilegeList;
  224. final Function onClickItem;
  225. final Function onChangItem;
  226. final MenuList defultModel;
  227. @override
  228. Widget build(BuildContext context) {
  229. double width = MediaQuery.of(context).size.width;
  230. double height = 420;
  231. return Container(
  232. width: width,
  233. height: height,
  234. child: Swiper(
  235. itemBuilder: (BuildContext context, index) {
  236. return Container(
  237. width: width,
  238. height: height,
  239. child: Stack(
  240. children: [
  241. Container(
  242. // alignment: Alignment.center,
  243. width: 328,
  244. height: height,
  245. child: LoadAssetImage('img_viptag_bigbg', fit: BoxFit.fill),
  246. ),
  247. Container(
  248. height: 40,
  249. alignment: Alignment.center,
  250. child: Text(
  251. privilegeList[index].name,
  252. style: TextStyle(color: Color(0xffFEEFE5), fontSize: 18),
  253. ),
  254. ),
  255. Positioned(
  256. left: 23,
  257. top: 84,
  258. right: 23,
  259. child: Column(
  260. crossAxisAlignment: CrossAxisAlignment.start,
  261. // mainAxisAlignment: MainAxisAlignment.start,
  262. children: [
  263. Row(
  264. children: [
  265. Container(
  266. height: 11,
  267. width: 2,
  268. color: Color(0xffDAB47E),
  269. margin: EdgeInsets.only(right: 10),
  270. ),
  271. Text(
  272. '权益介绍',
  273. style: TextStyle(
  274. color: Color(0xff222222), fontSize: 14),
  275. )
  276. ],
  277. ),
  278. SizedBox(
  279. height: 15,
  280. ),
  281. Row(
  282. // mainAxisAlignment: MainAxisAlignment.start,
  283. crossAxisAlignment: CrossAxisAlignment.start,
  284. children: [
  285. Container(
  286. height: 6,
  287. width: 6,
  288. margin: EdgeInsets.only(right: 5, top: 6),
  289. decoration: BoxDecoration(
  290. //背景
  291. color: Colours.text_gray,
  292. //设置四周圆角 角度
  293. borderRadius:
  294. BorderRadius.all(Radius.circular(3.0)),
  295. //设置四周边框
  296. ),
  297. ),
  298. Container(
  299. width: 242,
  300. child: Text(
  301. privilegeList[index].descr,
  302. style: TextStyle(
  303. color: Colours.text_gray, fontSize: 14),
  304. ),
  305. )
  306. ],
  307. ),
  308. SizedBox(
  309. height: 15,
  310. ),
  311. // Row(
  312. // crossAxisAlignment: CrossAxisAlignment.start,
  313. // // mainAxisAlignment: MainAxisAlignment.start,
  314. // children: [
  315. // Container(
  316. // height: 6,
  317. // width: 6,
  318. // margin: EdgeInsets.only(right: 7, top: 6),
  319. // decoration: BoxDecoration(
  320. // //背景
  321. // color: Colours.text_gray,
  322. // //设置四周圆角 角度
  323. // borderRadius:
  324. // BorderRadius.all(Radius.circular(3.0)),
  325. // //设置四周边框
  326. // ),
  327. // ),
  328. // Container(
  329. // width: 240,
  330. // child: Text(
  331. // '其他权益描述文本',
  332. // maxLines: 5,
  333. // style: TextStyle(
  334. // color: Colours.text_gray, fontSize: 14),
  335. // ),
  336. // )
  337. // ],
  338. // )
  339. ],
  340. )),
  341. Positioned(
  342. bottom: 35,
  343. left: -10,
  344. child: GestureDetector(
  345. onTap: () {
  346. Navigator.pop(context);
  347. },
  348. child: Container(
  349. height: 40,
  350. width: 328,
  351. // color: Colors.red,
  352. alignment: Alignment.center,
  353. child: Text(
  354. '立即开通',
  355. style: TextStyle(
  356. color: Color(0xffFEEFE5), fontSize: 16),
  357. ),
  358. // InkWell(
  359. // child: Text('data'),
  360. // ),
  361. )))
  362. ],
  363. ));
  364. },
  365. // pagination: SwiperPagination(
  366. // builder: DotSwiperPaginationBuilder(
  367. // color: Colors.grey,
  368. // activeColor: Colors.white,
  369. // size: 6,
  370. // activeSize: 6,
  371. // ),
  372. // ),
  373. key: UniqueKey(),
  374. viewportFraction: 0.8, //
  375. scale: 0.9,
  376. itemCount: privilegeList.length,
  377. scrollDirection: Axis.horizontal,
  378. loop: false,
  379. autoplay: false,
  380. index: privilegeList.indexOf(defultModel),
  381. //
  382. // autoplayDisableOnInteraction: false,
  383. // onTap: (index) {
  384. // onClickItem(index, privilegeList[index]);
  385. // },
  386. onIndexChanged: (index) {
  387. onChangItem(index, privilegeList[index]);
  388. },
  389. ),
  390. );
  391. }
  392. }
  393. class CusBehavior extends ScrollBehavior {
  394. @override
  395. Widget buildViewportChrome(
  396. BuildContext context, Widget child, AxisDirection axisDirection) {
  397. return child;
  398. // if (Platform.isAndroid || Platform.isIOS) return child;
  399. // return super.buildViewportChrome(context, child, axisDirection);
  400. }
  401. }