瀏覽代碼

1.优化淘宝授权的交互

tags/0.0.5+1
“yanghuaxuan” 3 年之前
父節點
當前提交
574e0f19e3
共有 4 個檔案被更改,包括 147 行新增9 行删除
  1. +3
    -3
      lib/models/user/user_info_model_notifier.dart
  2. +133
    -0
      lib/pages/auth_page/auth_success_page/auth_success_page.dart
  3. +9
    -3
      lib/util/taobao/taobao_auth.dart
  4. +2
    -3
      pubspec.yaml

+ 3
- 3
lib/models/user/user_info_model_notifier.dart 查看文件

@@ -66,9 +66,9 @@ class UserInfoNotifier with ChangeNotifier {
void unLogin() async {
_userInfo = null;
// 清除缓存数据
await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, '');
await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_MOBILE, '');
await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_USER_INFO, '');
await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, null);
await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_MOBILE, null);
await SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_USER_INFO, null);
// 退出淘宝登录
FlutterAlibc.loginOut();
// 退出QQ登录


+ 133
- 0
lib/pages/auth_page/auth_success_page/auth_success_page.dart 查看文件

@@ -0,0 +1,133 @@
import 'package:flutter/material.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

///渠道授权成功页面
class AuthSuccessPage extends StatefulWidget {
final AuthResultType authResultType;

const AuthSuccessPage({Key key, this.authResultType}) : super(key: key);

@override
_AuthSuccessPageState createState() => _AuthSuccessPageState();
}

class _AuthSuccessPageState extends State<AuthSuccessPage> {
String title = '';
String contentTitle = '';
String content = '';
String btntext = '';

@override
void initState() {
switch (widget.authResultType) {
case AuthResultType.success:
title = '授权成功';
contentTitle = '恭喜您授权成功';
content = '前往享受超多优惠吧';
btntext = '知道了';
break;
case AuthResultType.error:
title = '授权失败';
contentTitle = '授权失败';
content = '很抱歉,您的淘宝账号已经成为了合作方,如需申请渠道授权,您可更换其他淘宝账号';
btntext = '重新授权';
break;
}
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
brightness: Brightness.light,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
color: HexColor.fromHex("#FF333333"),
size: 18,
),
),
centerTitle: true,
elevation: 1,
backgroundColor: Colors.white,
title: Text(
title,
style: TextStyle(color: HexColor.fromHex("#FF333333"), fontSize: 17),
),
),
body: Container(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: 30,
),
Image.asset(
"assets/images/auth/auth_success.png",
package: 'zhiying_base_widget',
width: 107,
height: 107,
fit: BoxFit.fill,
),
SizedBox(
height: 30,
),
Text(
contentTitle,
style: TextStyle(color: HexColor.fromHex("#FF333333"), fontSize: 15),
),
Container(
margin: EdgeInsets.only(left: 56, right: 56),
child: Text(
content,
style: TextStyle(color: HexColor.fromHex("#FF999999"), fontSize: 13),
),
),
SizedBox(
height: 30,
),
GestureDetector(
onTap: () {
onClick();
},
child: Container(
height: 46.5,
width: 265,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
boxShadow: [BoxShadow(color: HexColor.fromHex("FFFF5500"), blurRadius: 1, spreadRadius: 2, offset: Offset(1, 4))],
gradient: LinearGradient(colors: [HexColor.fromHex("#FFFF8E00"), HexColor.fromHex("#FFFF5500")], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
child: Center(
child: Text(
btntext,
style: TextStyle(color: HexColor.fromHex("#FFFFFFFF"), fontSize: 13),
),
),
),
)
],
),
),
),
);
}

///点击事件
void onClick() async {
if (widget.authResultType == AuthResultType.success) {
Navigator.maybePop(context);
} else if (widget.authResultType == AuthResultType.error) {
///继续授权
await TaobaoAuth.auth(context).then((value) {
Navigator.pop(context);
});
}
}
}

enum AuthResultType { success, error }

+ 9
- 3
lib/util/taobao/taobao_auth.dart 查看文件

@@ -5,6 +5,7 @@ import 'package:flutter_alibc/alibc_model.dart';
import 'package:flutter_alibc/flutter_alibc.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:zhiying_comm/models/profile/profile_model.dart';
import 'package:zhiying_comm/pages/auth_page/auth_success_page/auth_success_page.dart';
import 'package:zhiying_comm/util/taobao/taobao_auth_alert.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:provider/provider.dart';
@@ -13,12 +14,12 @@ class TaobaoAuth {
// static ProfileModel _profile;

// 淘宝授权
static auth(BuildContext context) async {
static Future auth(BuildContext context) async {
bool isAuth = await TaobaoAuth.isAuth();
if (isAuth) {
Fluttertoast.showToast(msg: '你已经授权过了');
Provider.of<UserInfoNotifier>(context, listen: false).updateUserAuth(true);
return;
return null;
}

bool isConfirm = await showDialog(
@@ -30,13 +31,18 @@ class TaobaoAuth {
Map<String, dynamic> data = Map<String, dynamic>.from(await NetUtil.post('/api/v1/taobao/auth', method: NetMethod.GET));
Logger.debug(data);
if (data['code'] != 1) {
return;
return null;
}
String url = data['data']['redirect_url'];
print("授权链接" + url);
TradeResult result;
if (Platform.isAndroid) {
result = await FlutterAlibc.openByUrl(url: url, backUrl: "alisdk://", isAuth: true);
if(result.errorCode=="0"){
await Navigator.push(context,MaterialPageRoute(builder: (_)=>AuthSuccessPage(authResultType: AuthResultType.success,)) );
}else{
await Navigator.push(context,MaterialPageRoute(builder: (_)=>AuthSuccessPage(authResultType: AuthResultType.error,)) );
}
} else if (Platform.isIOS) {
result = await FlutterAlibc.openByUrl(url: url);
}


+ 2
- 3
pubspec.yaml 查看文件

@@ -40,9 +40,9 @@ dependencies:
# app更新dialogUI(用于IOS,以便统一样式)
flutter_update_dialog: 1.0.0
flutter_alibc:
#path: ../zhiying_flutter_alibc
# path: ../zhiying_flutter_alibc
git:
ref: 0.0.4
ref: 0.0.5
url: http://192.168.0.138:3000/FnuoOS_ZhiYing/zhiying_flutter_alibc.git
url_launcher: ^5.6.0
#图片预览控件
@@ -74,7 +74,6 @@ dependencies:
ref: '0.0.1'
#文件夹路径管理
path_provider: ^1.4.0

#保存文件到相册
save_image:
git:


Loading…
取消
儲存