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

security_page.dart 4.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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/security_page/models/security_style_model.dart';
  5. import 'package:zhiying_base_widget/pages/security_page/security_page_bloc.dart';
  6. import 'package:zhiying_comm/util/base_bloc.dart';
  7. import 'package:zhiying_comm/zhiying_comm.dart';
  8. class SecurityPage extends StatefulWidget {
  9. final Map<String, dynamic> data;
  10. const SecurityPage(this.data, {Key key}) : super(key: key);
  11. @override
  12. _SecurityPageState createState() => _SecurityPageState();
  13. }
  14. class _SecurityPageState extends State<SecurityPage> {
  15. @override
  16. Widget build(BuildContext context) {
  17. return BlocProvider<SecurityPageBloc>(
  18. bloc: SecurityPageBloc(),
  19. child: _SecurityContainer(widget.data),
  20. );
  21. }
  22. }
  23. class _SecurityContainer extends StatefulWidget {
  24. final Map<String, dynamic> data;
  25. const _SecurityContainer(
  26. this.data, {
  27. Key key,
  28. }) : super(key: key);
  29. @override
  30. _SecurityContainerState createState() => _SecurityContainerState();
  31. }
  32. class _SecurityContainerState extends State<_SecurityContainer> {
  33. SecurityPageBloc _bloc;
  34. @override
  35. void initState() {
  36. _bloc = BlocProvider.of<SecurityPageBloc>(context);
  37. _bloc.loadData(widget.data['skip_identifier']);
  38. super.initState();
  39. }
  40. @override
  41. Widget build(BuildContext context) {
  42. return StreamBuilder<SecurityStyleModel>(
  43. stream: _bloc.outData,
  44. builder: (BuildContext context, AsyncSnapshot snapshot) {
  45. SecurityStyleModel style = snapshot.data;
  46. List<Widget> widgets = List();
  47. widgets.addAll(style?.settings?.map((item) {
  48. return _createItem(item);
  49. })?.toList() ??
  50. []);
  51. widgets.add(Provider.of<UserInfoNotifier>(context).userInfo == null
  52. ? Container()
  53. : _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: () {
  137. RouterUtil.route(item, item.toJson(), context);
  138. },
  139. );
  140. }
  141. Widget _createLogout() {
  142. return GestureDetector(
  143. child: Container(
  144. color: Colors.white,
  145. width: double.infinity,
  146. height: 50,
  147. margin: EdgeInsets.only(top: 10),
  148. child: Center(
  149. child: Text(
  150. '账号注销',
  151. style: TextStyle(
  152. fontSize: 13,
  153. color: Color(0xffff4242),
  154. fontWeight: FontWeight.bold,
  155. ),
  156. ),
  157. ),
  158. ),
  159. onTap: () {
  160. Logger.debug('账号注销');
  161. },
  162. );
  163. }
  164. }