基础组件库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

202 righe
5.5 KiB

  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_item_model.dart';
  5. import 'package:zhiying_base_widget/pages/setting_page/models/setting_page_style_model.dart';
  6. import 'package:zhiying_base_widget/pages/setting_page/setting_page_bloc.dart';
  7. import 'package:zhiying_comm/util/base_bloc.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. class SettingPage extends StatefulWidget {
  10. final Map<String, dynamic> data;
  11. const SettingPage(this.data, {Key key}) : super(key: key);
  12. @override
  13. _SettingPageState createState() => _SettingPageState();
  14. }
  15. class _SettingPageState extends State<SettingPage> {
  16. @override
  17. Widget build(BuildContext context) {
  18. return BlocProvider<SettingPageBloc>(
  19. bloc: SettingPageBloc(),
  20. child: _SettingContainer(widget.data),
  21. );
  22. }
  23. }
  24. class _SettingContainer extends StatefulWidget {
  25. final Map<String, dynamic> data;
  26. const _SettingContainer(
  27. this.data, {
  28. Key key,
  29. }) : super(key: key);
  30. @override
  31. _SettingContainerState createState() => _SettingContainerState();
  32. }
  33. class _SettingContainerState extends State<_SettingContainer> {
  34. SettingPageBloc _bloc;
  35. @override
  36. void initState() {
  37. _bloc = BlocProvider.of<SettingPageBloc>(context);
  38. // if(!EmptyUtil.isEmpty(widget.data)) {
  39. _bloc.loadData(widget.data['skip_identifier']);
  40. // }
  41. super.initState();
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. return StreamBuilder<SettingPageStyleModel>(
  46. stream: _bloc.outData,
  47. builder: (BuildContext context, AsyncSnapshot snapshot) {
  48. SettingPageStyleModel style = snapshot.data;
  49. List<Widget> widgets = List();
  50. widgets.addAll(style?.settings?.map((list) {
  51. return _createSection(list);
  52. })?.toList() ??
  53. []);
  54. UserInfoModel user = Provider.of<UserInfoNotifier>(context).userInfo;
  55. if (user != null && (user.token != null && user.token != '')) {
  56. widgets.add(_createLogout());
  57. }
  58. return Scaffold(
  59. backgroundColor: Color(0xfff9f9f9),
  60. appBar: _createNav(style),
  61. body: SingleChildScrollView(
  62. child: Column(
  63. children: widgets,
  64. ),
  65. ));
  66. });
  67. }
  68. // 导航栏
  69. Widget _createNav(SettingPageStyleModel style) {
  70. return CupertinoNavigationBar(
  71. border: Border(
  72. bottom: BorderSide(
  73. width: 0.0, // One physical pixel.
  74. style: BorderStyle.none,
  75. ),
  76. ),
  77. backgroundColor: HexColor.fromHex(style?.appBarBgColor ?? '#ffffff'),
  78. leading: Navigator.canPop(context)
  79. ? GestureDetector(
  80. child: Container(
  81. padding: EdgeInsets.zero,
  82. child: Icon(
  83. Icons.arrow_back_ios,
  84. size: 20,
  85. ),
  86. ),
  87. onTap: () {
  88. if (Navigator.canPop(context)) {
  89. Navigator.pop(context);
  90. }
  91. },
  92. )
  93. : Container(),
  94. middle: Text(
  95. style?.appBarName ?? '设置',
  96. style: TextStyle(
  97. fontSize: 15,
  98. color: HexColor.fromHex(style?.appBarNameColor ?? '#333333'),
  99. ),
  100. ),
  101. );
  102. }
  103. Widget _createSection(List<SettingPageStyleItemModel> sections) {
  104. return Container(
  105. margin: EdgeInsets.only(top: 8),
  106. child: Column(
  107. children: sections.map((item) {
  108. return _createItem(item);
  109. }).toList(),
  110. ),
  111. );
  112. }
  113. Widget _createItem(SettingPageStyleItemModel item) {
  114. return GestureDetector(
  115. child: Container(
  116. padding: EdgeInsets.only(left: 12.5, right: 12.5),
  117. width: double.infinity,
  118. height: 50,
  119. color: Colors.white,
  120. child: Row(
  121. children: <Widget>[
  122. Expanded(
  123. child: Text(
  124. item.name,
  125. style: TextStyle(
  126. fontSize: 13,
  127. color: HexColor.fromHex(item?.nameColor ?? '#333333'),
  128. fontWeight: FontWeight.bold,
  129. ),
  130. ),
  131. ),
  132. Expanded(
  133. child: Text(
  134. item.desc,
  135. textAlign: TextAlign.right,
  136. style: TextStyle(
  137. fontSize: 13,
  138. color: HexColor.fromHex(item?.descColor ?? '#333333'),
  139. ),
  140. ),
  141. ),
  142. Icon(
  143. Icons.arrow_forward_ios,
  144. size: 14,
  145. color: Color(0xff999999),
  146. )
  147. ],
  148. ),
  149. ),
  150. onTap: () {
  151. RouterUtil.route(item, item.toJson(), context).then((value) {
  152. if(value!=null&&value){
  153. Navigator.maybePop(context);
  154. }
  155. });
  156. },
  157. );
  158. }
  159. Widget _createLogout() {
  160. return GestureDetector(
  161. child: Container(
  162. color: Colors.white,
  163. width: double.infinity,
  164. height: 50,
  165. margin: EdgeInsets.only(top: 10),
  166. child: Center(
  167. child: Text(
  168. '退出登录',
  169. style: TextStyle(
  170. fontSize: 13,
  171. color: Color(0xffff4242),
  172. fontWeight: FontWeight.bold,
  173. ),
  174. ),
  175. ),
  176. ),
  177. onTap: () async{
  178. Logger.debug('退出登录');
  179. await Provider.of<UserInfoNotifier>(context, listen: false).unLogin();
  180. Navigator.maybePop(context);
  181. },
  182. );
  183. }
  184. }