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

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. _isAuth = isAuth;
  26. setState(() {});
  27. });
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. _user = Provider.of<UserInfoNotifier>(context).userInfo;
  33. if (_isAuth) {
  34. // 授权过,不显示
  35. return Container();
  36. }
  37. return Container(
  38. height: 34,
  39. width: double.infinity,
  40. margin: EdgeInsets.only(left: 12, right: 12, top: 4, bottom: 4),
  41. decoration: BoxDecoration(
  42. color: HexColor.fromHex(widget._style?.taoaboTipBgColor ?? 'ffffff'),
  43. borderRadius: BorderRadius.circular(17),
  44. boxShadow: [
  45. BoxShadow(
  46. offset: Offset(2, 1), //x,y轴
  47. color: HexColor.fromHex(
  48. widget._style?.taoaboTipShadowColor ?? '767676')
  49. .withAlpha(70), //投影颜色
  50. blurRadius: 5 //投影距离
  51. )
  52. ]),
  53. child: Row(
  54. children: <Widget>[
  55. Container(
  56. margin: EdgeInsets.only(left: 10, right: 8),
  57. width: 20,
  58. height: 20,
  59. child: CachedNetworkImage(
  60. imageUrl: widget._style.taobaoAuthIcon,
  61. fit: BoxFit.contain,
  62. ),
  63. ),
  64. Expanded(
  65. child: Text(
  66. widget._style?.taoaboTipText ?? '',
  67. maxLines: 1,
  68. style: TextStyle(
  69. fontSize: 12,
  70. fontWeight: FontWeight.bold,
  71. color: HexColor.fromHex(
  72. widget._style?.taoaboTipTextColor ?? '333333'),
  73. ),
  74. ),
  75. ),
  76. GestureDetector(
  77. child: Container(
  78. padding: EdgeInsets.only(left: 12, right: 12, top: 3, bottom: 3),
  79. margin: EdgeInsets.only(left: 8, right: 8),
  80. decoration: BoxDecoration(
  81. color: HexColor.fromHex(
  82. widget._style?.taoaboTipBtnBgColor ?? 'FF4242'),
  83. borderRadius: BorderRadius.circular(20)),
  84. child: Text(
  85. widget._style?.taoaboTipBtnText ?? '',
  86. style: TextStyle(
  87. fontSize: 12,
  88. color: HexColor.fromHex(
  89. widget._style?.taoaboTipBtnTextColor ?? 'ffffff'),
  90. ),
  91. ),
  92. ),
  93. onTap: () async {
  94. if (_user?.token == null || _user.token == '') {
  95. print('need login...');
  96. RouterUtil.goLogin(context);
  97. return;
  98. }
  99. TaobaoAuth.auth(context);
  100. },
  101. ),
  102. ],
  103. ),
  104. );
  105. }
  106. }