基础组件库
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

196 строки
5.4 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. _bloc.loadData(widget.data['skip_identifier']);
  39. super.initState();
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. return StreamBuilder<SettingPageStyleModel>(
  44. stream: _bloc.outData,
  45. builder: (BuildContext context, AsyncSnapshot snapshot) {
  46. SettingPageStyleModel style = snapshot.data;
  47. List<Widget> widgets = List();
  48. widgets.addAll(style?.settings?.map((list) {
  49. return _createSection(list);
  50. })?.toList() ??
  51. []);
  52. UserInfoModel user = Provider.of<UserInfoNotifier>(context).userInfo;
  53. if (user != null && (user.token != null && user.token != '')) {
  54. widgets.add(_createLogout());
  55. }
  56. return Scaffold(
  57. backgroundColor: Color(0xfff9f9f9),
  58. appBar: _createNav(style),
  59. body: SingleChildScrollView(
  60. child: Column(
  61. children: widgets,
  62. ),
  63. ));
  64. });
  65. }
  66. // 导航栏
  67. Widget _createNav(SettingPageStyleModel style) {
  68. return CupertinoNavigationBar(
  69. border: Border(
  70. bottom: BorderSide(
  71. width: 0.0, // One physical pixel.
  72. style: BorderStyle.none,
  73. ),
  74. ),
  75. backgroundColor: HexColor.fromHex(style?.appBarBgColor ?? '#ffffff'),
  76. leading: Navigator.canPop(context)
  77. ? GestureDetector(
  78. child: Container(
  79. padding: EdgeInsets.zero,
  80. child: Icon(
  81. Icons.arrow_back_ios,
  82. size: 20,
  83. ),
  84. ),
  85. onTap: () {
  86. if (Navigator.canPop(context)) {
  87. Navigator.pop(context);
  88. }
  89. },
  90. )
  91. : Container(),
  92. middle: Text(
  93. style?.appBarName ?? '设置',
  94. style: TextStyle(
  95. fontSize: 15,
  96. color: HexColor.fromHex(style?.appBarNameColor ?? '#333333'),
  97. ),
  98. ),
  99. );
  100. }
  101. Widget _createSection(List<SettingPageStyleItemModel> sections) {
  102. return Container(
  103. margin: EdgeInsets.only(top: 8),
  104. child: Column(
  105. children: sections.map((item) {
  106. return _createItem(item);
  107. }).toList(),
  108. ),
  109. );
  110. }
  111. Widget _createItem(SettingPageStyleItemModel item) {
  112. return GestureDetector(
  113. child: Container(
  114. padding: EdgeInsets.only(left: 12.5, right: 12.5),
  115. width: double.infinity,
  116. height: 50,
  117. color: Colors.white,
  118. child: Row(
  119. children: <Widget>[
  120. Expanded(
  121. child: Text(
  122. item.name,
  123. style: TextStyle(
  124. fontSize: 13,
  125. color: HexColor.fromHex(item?.nameColor ?? '#333333'),
  126. fontWeight: FontWeight.bold,
  127. ),
  128. ),
  129. ),
  130. Expanded(
  131. child: Text(
  132. item.desc,
  133. textAlign: TextAlign.right,
  134. style: TextStyle(
  135. fontSize: 13,
  136. color: HexColor.fromHex(item?.descColor ?? '#333333'),
  137. ),
  138. ),
  139. ),
  140. Icon(
  141. Icons.arrow_forward_ios,
  142. size: 14,
  143. color: Color(0xff999999),
  144. )
  145. ],
  146. ),
  147. ),
  148. onTap: () {
  149. RouterUtil.route(item, item.toJson(), context);
  150. },
  151. );
  152. }
  153. Widget _createLogout() {
  154. return GestureDetector(
  155. child: Container(
  156. color: Colors.white,
  157. width: double.infinity,
  158. height: 50,
  159. margin: EdgeInsets.only(top: 10),
  160. child: Center(
  161. child: Text(
  162. '退出登录',
  163. style: TextStyle(
  164. fontSize: 13,
  165. color: Color(0xffff4242),
  166. fontWeight: FontWeight.bold,
  167. ),
  168. ),
  169. ),
  170. ),
  171. onTap: () async{
  172. Logger.debug('退出登录');
  173. await Provider.of<UserInfoNotifier>(context, listen: false).unLogin();
  174. Navigator.maybePop(context);
  175. },
  176. );
  177. }
  178. }