基础组件库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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