基础组件库
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

home_auth.dart 4.0 KiB

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 _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. super.initState();
  25. }
  26. @override
  27. void didChangeDependencies() {
  28. _user = Provider.of<UserInfoNotifier>(context).userInfo;
  29. _isAuth = _user?.isTBAuth ?? false;
  30. super.didChangeDependencies();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. if (_isAuth) {
  35. // 授权过,不显示
  36. return Container();
  37. }
  38. return Container(
  39. height: 34,
  40. width: double.infinity,
  41. margin: EdgeInsets.only(left: 12, right: 12, top: 4, bottom: 4),
  42. decoration: BoxDecoration(
  43. color: HexColor.fromHex(!_isAuth ? widget._model?.listStyle?.before?.bgColor ?? 'ffffff' : widget?._model?.listStyle?.after?.bgColor ?? 'ffffff'),
  44. borderRadius: BorderRadius.circular(17),
  45. boxShadow: [
  46. BoxShadow(
  47. offset: Offset(2, 1), //x,y轴
  48. color: HexColor.fromHex('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: !_isAuth ? widget._model?.listStyle?.before?.auditImg ?? '' : widget?._model?.listStyle?.after?.auditImg ?? '',
  61. fit: BoxFit.contain,
  62. ),
  63. ),
  64. Expanded(
  65. child: Text(
  66. !_isAuth ? widget._model?.listStyle?.before?.contentText ?? '' : widget?._model?.listStyle?.after?.contentText ?? '',
  67. maxLines: 1,
  68. style: TextStyle(
  69. fontSize: 12,
  70. fontWeight: FontWeight.bold,
  71. color: HexColor.fromHex(
  72. !_isAuth ? widget._model?.listStyle?.before?.contentTextColor ?? '333333' : widget?._model?.listStyle?.after?.contentTextColor ?? '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. !_isAuth ? widget._model?.listStyle?.before?.btnBgColor ?? 'FF4242' : widget?._model?.listStyle?.after?.btnBgColor ?? 'FF4242' ),
  83. borderRadius: BorderRadius.circular(20)),
  84. child: Text(
  85. !_isAuth ? widget._model?.listStyle?.before?.btnText ?? '' : widget?._model?.listStyle?.after?.btnText ?? '',
  86. style: TextStyle(
  87. fontSize: 12,
  88. color: HexColor.fromHex(
  89. !_isAuth ? widget._model?.listStyle?.before?.btnTextColor ?? 'ffffff' : widget?._model?.listStyle?.after?.btnTextColor ?? ''),
  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. }