基础组件库
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

119 linhas
4.1 KiB

  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 _model;
  11. HomeAuth(this.data, {Key key}) : super(key: key) {
  12. String d = data['data'];
  13. _json = convert.jsonDecode(d);
  14. _model = 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(!_isAuth ? widget._model?.listStyle?.before?.bgColor ?? 'ffffff' : widget?._model?.listStyle?.after?.bgColor ?? 'ffffff'),
  47. borderRadius: BorderRadius.circular(17),
  48. boxShadow: [
  49. BoxShadow(
  50. offset: Offset(2, 1), //x,y轴
  51. color: HexColor.fromHex('767676')
  52. .withAlpha(70), //投影颜色
  53. blurRadius: 5 //投影距离
  54. )
  55. ]),
  56. child: Row(
  57. children: <Widget>[
  58. Container(
  59. margin: EdgeInsets.only(left: 10, right: 8),
  60. width: 20,
  61. height: 20,
  62. child: CachedNetworkImage(
  63. imageUrl: !_isAuth ? widget._model?.listStyle?.before?.auditImg ?? '' : widget?._model?.listStyle?.after?.auditImg ?? '',
  64. fit: BoxFit.contain,
  65. ),
  66. ),
  67. Expanded(
  68. child: Text(
  69. !_isAuth ? widget._model?.listStyle?.before?.contentText ?? '' : widget?._model?.listStyle?.after?.contentText ?? '',
  70. maxLines: 1,
  71. style: TextStyle(
  72. fontSize: 12,
  73. fontWeight: FontWeight.bold,
  74. color: HexColor.fromHex(
  75. !_isAuth ? widget._model?.listStyle?.before?.contentTextColor ?? '333333' : widget?._model?.listStyle?.after?.contentTextColor ?? '333333'),
  76. ),
  77. ),
  78. ),
  79. GestureDetector(
  80. child: Container(
  81. padding: EdgeInsets.only(left: 12, right: 12, top: 3, bottom: 3),
  82. margin: EdgeInsets.only(left: 8, right: 8),
  83. decoration: BoxDecoration(
  84. color: HexColor.fromHex(
  85. !_isAuth ? widget._model?.listStyle?.before?.btnBgColor ?? 'FF4242' : widget?._model?.listStyle?.after?.btnBgColor ?? 'FF4242' ),
  86. borderRadius: BorderRadius.circular(20)),
  87. child: Text(
  88. !_isAuth ? widget._model?.listStyle?.before?.btnText ?? '' : widget?._model?.listStyle?.after?.btnText ?? '',
  89. style: TextStyle(
  90. fontSize: 12,
  91. color: HexColor.fromHex(
  92. !_isAuth ? widget._model?.listStyle?.before?.btnTextColor ?? 'ffffff' : widget?._model?.listStyle?.after?.btnTextColor ?? ''),
  93. ),
  94. ),
  95. ),
  96. onTap: () async {
  97. if (_user?.token == null || _user.token == '') {
  98. print('need login...');
  99. RouterUtil.goLogin(context);
  100. return;
  101. }
  102. TaobaoAuth.auth(context);
  103. },
  104. ),
  105. ],
  106. ),
  107. );
  108. }
  109. }