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

186 lines
4.9 KiB

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