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

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