基础组件库
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.
 
 
 
 
 

155 lines
4.3 KiB

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