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

home_auth.dart 3.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'dart:convert' as convert;
  2. import 'package:cached_network_image/cached_network_image.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:provider/provider.dart';
  5. import 'package:zhiying_base_widget/widgets/home/home_auth/models/home_auth_model.dart';
  6. import 'package:zhiying_comm/zhiying_comm.dart';
  7. class HomeAuth extends StatefulWidget {
  8. final Map<String, dynamic> data;
  9. Map<String, dynamic> _json;
  10. HomeAuthModel _style;
  11. HomeAuth(this.data, {Key key}) : super(key: key) {
  12. String d = data['data'];
  13. _json = convert.jsonDecode(d);
  14. _style = HomeAuthModel.fromJson(Map<String, dynamic>.from(_json));
  15. }
  16. @override
  17. _HomeAuthState createState() => _HomeAuthState();
  18. }
  19. class _HomeAuthState extends State<HomeAuth> {
  20. UserInfoModel _user;
  21. bool _isAuth = false;
  22. @override
  23. void initState() {
  24. // TaobaoAuth.isAuth().then((isAuth) {
  25. // setState(() => this._isAuth = isAuth);
  26. // });
  27. super.initState();
  28. }
  29. @override
  30. void didChangeDependencies() {
  31. _user = Provider.of<UserInfoNotifier>(context).userInfo;
  32. _isAuth = _user?.isTBAuth ?? false;
  33. super.didChangeDependencies();
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. if (_isAuth) {
  38. // 授权过,不显示
  39. return Container();
  40. }
  41. return Container(
  42. height: 34,
  43. width: double.infinity,
  44. margin: EdgeInsets.only(left: 12, right: 12, top: 4, bottom: 4),
  45. decoration: BoxDecoration(
  46. color: HexColor.fromHex(widget._style?.taoaboTipBgColor ?? 'ffffff'),
  47. borderRadius: BorderRadius.circular(17),
  48. boxShadow: [
  49. BoxShadow(
  50. offset: Offset(2, 1), //x,y轴
  51. color: HexColor.fromHex(
  52. widget._style?.taoaboTipShadowColor ?? '767676')
  53. .withAlpha(70), //投影颜色
  54. blurRadius: 5 //投影距离
  55. )
  56. ]),
  57. child: Row(
  58. children: <Widget>[
  59. Container(
  60. margin: EdgeInsets.only(left: 10, right: 8),
  61. width: 20,
  62. height: 20,
  63. child: CachedNetworkImage(
  64. imageUrl: widget._style.taobaoAuthIcon,
  65. fit: BoxFit.contain,
  66. ),
  67. ),
  68. Expanded(
  69. child: Text(
  70. widget._style?.taoaboTipText ?? '',
  71. maxLines: 1,
  72. style: TextStyle(
  73. fontSize: 12,
  74. fontWeight: FontWeight.bold,
  75. color: HexColor.fromHex(
  76. widget._style?.taoaboTipTextColor ?? '333333'),
  77. ),
  78. ),
  79. ),
  80. GestureDetector(
  81. child: Container(
  82. padding: EdgeInsets.only(left: 12, right: 12, top: 3, bottom: 3),
  83. margin: EdgeInsets.only(left: 8, right: 8),
  84. decoration: BoxDecoration(
  85. color: HexColor.fromHex(
  86. widget._style?.taoaboTipBtnBgColor ?? 'FF4242'),
  87. borderRadius: BorderRadius.circular(20)),
  88. child: Text(
  89. widget._style?.taoaboTipBtnText ?? '',
  90. style: TextStyle(
  91. fontSize: 12,
  92. color: HexColor.fromHex(
  93. widget._style?.taoaboTipBtnTextColor ?? 'ffffff'),
  94. ),
  95. ),
  96. ),
  97. onTap: () async {
  98. if (_user?.token == null || _user.token == '') {
  99. print('need login...');
  100. RouterUtil.goLogin(context);
  101. return;
  102. }
  103. TaobaoAuth.auth(context);
  104. },
  105. ),
  106. ],
  107. ),
  108. );
  109. }
  110. }