基础组件库
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

security_page.dart 4.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. }