基础组件库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

216 satır
5.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. import 'package:provider/provider.dart';
  8. ///
  9. /// 账号安全
  10. ///
  11. class SecurityPage extends StatefulWidget {
  12. final Map<String, dynamic> data;
  13. const SecurityPage(this.data, {Key key}) : super(key: key);
  14. @override
  15. _SecurityPageState createState() => _SecurityPageState();
  16. }
  17. class _SecurityPageState extends State<SecurityPage> {
  18. @override
  19. Widget build(BuildContext context) {
  20. return BlocProvider<SecurityPageBloc>(
  21. bloc: SecurityPageBloc(),
  22. child: _SecurityContainer(widget.data),
  23. );
  24. }
  25. }
  26. class _SecurityContainer extends StatefulWidget {
  27. final Map<String, dynamic> data;
  28. const _SecurityContainer(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. UserInfoModel _user;
  37. @override
  38. void didChangeDependencies() {
  39. _user = Provider
  40. .of<UserInfoNotifier>(context)
  41. .userInfo;
  42. super.didChangeDependencies();
  43. }
  44. @override
  45. void initState() {
  46. _bloc = BlocProvider.of<SecurityPageBloc>(context);
  47. _bloc.loadData(widget.data['skip_identifier']);
  48. super.initState();
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. return StreamBuilder<SecurityStyleModel>(
  53. stream: _bloc.outData,
  54. builder: (BuildContext context, AsyncSnapshot snapshot) {
  55. SecurityStyleModel style = snapshot.data;
  56. List<Widget> widgets = List();
  57. widgets.addAll(style?.settings?.map((item) {
  58. return _createItem(item);
  59. })?.toList() ??
  60. []);
  61. if((style?.accountDelete?.isShow??"0")=="1"){
  62. widgets.add(_createLogout(style));
  63. }
  64. return Scaffold(
  65. backgroundColor: Color(0xfff9f9f9),
  66. appBar: _createNav(style),
  67. body: SingleChildScrollView(
  68. child: Column(
  69. children: widgets,
  70. ),
  71. ));
  72. });
  73. }
  74. // 导航栏
  75. Widget _createNav(SecurityStyleModel style) {
  76. return CupertinoNavigationBar(
  77. border: Border(
  78. bottom: BorderSide(
  79. width: 0.0, // One physical pixel.
  80. style: BorderStyle.none,
  81. ),
  82. ),
  83. backgroundColor: HexColor.fromHex(style?.appBarBgColor ?? '#ffffff'),
  84. leading: Navigator.canPop(context)
  85. ? GestureDetector(
  86. child: Container(
  87. padding: EdgeInsets.zero,
  88. child: Icon(
  89. Icons.arrow_back_ios,
  90. size: 20,
  91. ),
  92. ),
  93. onTap: () {
  94. if (Navigator.canPop(context)) {
  95. Navigator.pop(context);
  96. }
  97. },
  98. )
  99. : Container(),
  100. middle: Text(
  101. style?.appBarName ?? '账号安全',
  102. style: TextStyle(
  103. fontSize: 15,
  104. color: HexColor.fromHex(style?.appBarNameColor ?? '#333333'),
  105. ),
  106. ),
  107. );
  108. }
  109. Widget _createItem(SecurityStyleItemModel item) {
  110. return GestureDetector(
  111. child: Container(
  112. padding: EdgeInsets.only(left: 12.5, right: 12.5),
  113. width: double.infinity,
  114. height: 50,
  115. color: Colors.white,
  116. child: Row(
  117. children: <Widget>[
  118. Expanded(
  119. child: Text(
  120. item.name,
  121. style: TextStyle(
  122. fontSize: 13,
  123. color: HexColor.fromHex(item?.nameColor ?? '#333333'),
  124. fontWeight: FontWeight.bold,
  125. ),
  126. ),
  127. ),
  128. Expanded(
  129. child: Text(
  130. item.desc ?? '',
  131. textAlign: TextAlign.right,
  132. style: TextStyle(
  133. fontSize: 13,
  134. color: HexColor.fromHex(item?.descColor ?? '#333333'),
  135. ),
  136. ),
  137. ),
  138. Icon(
  139. Icons.arrow_forward_ios,
  140. size: 14,
  141. color: Color(0xff999999),
  142. )
  143. ],
  144. ),
  145. ),
  146. onTap: () async {
  147. // 淘宝授权不跳转
  148. if (item.skipIdentifier == 'pub.flutter.account_security_toabao_auth') {
  149. if (_user == null || EmptyUtil.isEmpty(_user.token)) {
  150. RouterUtil.goLogin(context);
  151. return;
  152. }
  153. if (!(_user?.isTBAuth ?? false)) {
  154. // 淘宝授权
  155. await TaobaoAuth.auth(context);
  156. }
  157. return;
  158. }
  159. await RouterUtil.route(
  160. item,
  161. Map<String, dynamic>.from(
  162. {'status': _bloc.securityStatus, 'data': item.toJson()}),
  163. context);
  164. _bloc.loadData(widget.data['skip_identifier']);
  165. },
  166. );
  167. }
  168. Widget _createLogout([SecurityStyleModel style]) {
  169. return GestureDetector(
  170. child: Container(
  171. color: HexColor.fromHex("#FFFFFF"),
  172. width: double.infinity,
  173. height: 50,
  174. margin: EdgeInsets.only(top: 10),
  175. child: Center(
  176. child: Text(
  177. style?.accountDelete?.text ?? "",
  178. style: TextStyle(
  179. fontSize: 13,
  180. color: HexColor.fromHex(style?.accountDelete?.textColor ?? ""),
  181. fontWeight: FontWeight.bold,
  182. ),
  183. ),
  184. ),
  185. ),
  186. onTap: () {
  187. Logger.debug('账号注销');
  188. RouterUtil.route(SkipModel(skipIdentifier: style?.accountDelete?.skipIdentifier ?? ""), style?.accountDelete?.toJson(), context).then((value) {
  189. if(value!=null&&value){
  190. Navigator.pop(context,true);
  191. }
  192. } );
  193. },
  194. );
  195. }
  196. }