|
- import 'dart:convert' as convert;
-
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/material.dart';
- import 'package:provider/provider.dart';
- import 'package:zhiying_base_widget/widgets/home/home_auth/models/home_auth_model.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
-
- class HomeAuth extends StatefulWidget {
- final Map<String, dynamic> data;
- Map<String, dynamic> _json;
- HomeAuthModel _style;
-
- HomeAuth(this.data, {Key key}) : super(key: key) {
- String d = data['data'];
- _json = convert.jsonDecode(d);
- _style = HomeAuthModel.fromJson(Map<String, dynamic>.from(_json));
- }
-
- @override
- _HomeAuthState createState() => _HomeAuthState();
- }
-
- class _HomeAuthState extends State<HomeAuth> {
- UserInfoModel _user;
- bool _isAuth = false;
-
- @override
- void initState() {
- TaobaoAuth.isAuth().then((isAuth) {
- _isAuth = isAuth;
- setState(() {});
- });
-
- super.initState();
- }
-
- @override
- Widget build(BuildContext context) {
- _user = Provider.of<UserInfoNotifier>(context).userInfo;
- if (_isAuth) {
- // 授权过,不显示
- return Container();
- }
- return Container(
- height: 34,
- width: double.infinity,
- margin: EdgeInsets.only(left: 12, right: 12, top: 4, bottom: 4),
- decoration: BoxDecoration(
- color: HexColor.fromHex(widget._style?.taoaboTipBgColor ?? 'ffffff'),
- borderRadius: BorderRadius.circular(17),
- boxShadow: [
- BoxShadow(
- offset: Offset(2, 1), //x,y轴
- color: HexColor.fromHex(
- widget._style?.taoaboTipShadowColor ?? '767676')
- .withAlpha(70), //投影颜色
- blurRadius: 5 //投影距离
- )
- ]),
- child: Row(
- children: <Widget>[
- Container(
- margin: EdgeInsets.only(left: 10, right: 8),
- width: 20,
- height: 20,
- child: CachedNetworkImage(
- imageUrl: widget._style.taobaoAuthIcon,
- fit: BoxFit.contain,
- ),
- ),
- Expanded(
- child: Text(
- widget._style?.taoaboTipText ?? '',
- maxLines: 1,
- style: TextStyle(
- fontSize: 12,
- fontWeight: FontWeight.bold,
- color: HexColor.fromHex(
- widget._style?.taoaboTipTextColor ?? '333333'),
- ),
- ),
- ),
- GestureDetector(
- child: Container(
- padding: EdgeInsets.only(left: 12, right: 12, top: 3, bottom: 3),
- margin: EdgeInsets.only(left: 8, right: 8),
- decoration: BoxDecoration(
- color: HexColor.fromHex(
- widget._style?.taoaboTipBtnBgColor ?? 'FF4242'),
- borderRadius: BorderRadius.circular(20)),
- child: Text(
- widget._style?.taoaboTipBtnText ?? '',
- style: TextStyle(
- fontSize: 12,
- color: HexColor.fromHex(
- widget._style?.taoaboTipBtnTextColor ?? 'ffffff'),
- ),
- ),
- ),
- onTap: () async {
- if (_user?.token == null || _user.token == '') {
- print('need login...');
- RouterUtil.goLogin(context);
- return;
- }
- TaobaoAuth.auth(context);
- },
- ),
- ],
- ),
- );
- }
- }
|