|
...
|
...
|
@@ -18,6 +18,7 @@ import 'package:one_key/models/store_info.dart'; |
|
|
|
import 'package:one_key/net/dio_util.dart';
|
|
|
|
import 'package:one_key/provider/create_store_model.dart';
|
|
|
|
import 'package:one_key/provider/other_login_provider.dart';
|
|
|
|
import 'package:one_key/pages/login/huawei_login_view.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/route/navigate_service.dart';
|
|
...
|
...
|
@@ -57,6 +58,7 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
String errorText = ""; //错误提示
|
|
|
|
|
|
|
|
bool _check = false;
|
|
|
|
HuaweiLoginViewController? _huaweiLoginViewController;
|
|
|
|
|
|
|
|
OtherLoginProvider? otherLoginProvider;
|
|
|
|
late CreateStoreModel createStoreModel;
|
|
...
|
...
|
@@ -89,6 +91,7 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
//当页面离开时要清除监听器
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_huaweiLoginViewController?.dispose();
|
|
|
|
super.dispose();
|
|
|
|
if (responseListener != null) {
|
|
|
|
fluwx.removeSubscriber(responseListener!);
|
|
...
|
...
|
@@ -186,6 +189,88 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
///华为账号一键登录按钮
|
|
|
|
_onHuaweiLoginViewCreated(HuaweiLoginViewController controller) {
|
|
|
|
_huaweiLoginViewController = controller;
|
|
|
|
controller.events.listen((event) {
|
|
|
|
if (!mounted) return;
|
|
|
|
final method = event['method']?.toString();
|
|
|
|
switch (method) {
|
|
|
|
case 'loginStart':
|
|
|
|
setState(() {});
|
|
|
|
break;
|
|
|
|
case 'loginEnd':
|
|
|
|
setState(() {});
|
|
|
|
break;
|
|
|
|
case 'agreementNotAccepted':
|
|
|
|
_showHuaweiAgreementDialog();
|
|
|
|
break;
|
|
|
|
case 'loginSuccess':
|
|
|
|
_handleHuaweiLoginResultFromNative(event['data']);
|
|
|
|
break;
|
|
|
|
case 'loginError':
|
|
|
|
final err = event['data']?.toString() ?? '';
|
|
|
|
print('HuaweiLoginError: $err');
|
|
|
|
Utils.showToast('华为账号登录失败:$err');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
controller.setAgreementStatus(_check);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _showHuaweiAgreementDialog() {
|
|
|
|
if (_check) return;
|
|
|
|
DialogUtil.openAlertDialogLogin(context, 530, onTap: () {
|
|
|
|
if (Navigator.canPop(context)) {
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
_check = true;
|
|
|
|
});
|
|
|
|
_huaweiLoginViewController?.setAgreementStatus(true);
|
|
|
|
_huaweiLoginViewController?.continueLogin();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleHuaweiLoginResultFromNative(dynamic data) {
|
|
|
|
Map<String, String> result = {};
|
|
|
|
if (data is String && data.isNotEmpty) {
|
|
|
|
try {
|
|
|
|
final decoded = jsonDecode(data);
|
|
|
|
if (decoded is Map) {
|
|
|
|
decoded.forEach((key, value) {
|
|
|
|
result[key.toString()] = value?.toString() ?? '';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (_) {}
|
|
|
|
}
|
|
|
|
_handleHuaweiLoginResult(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleHuaweiLoginResult(Map<String, String> data) {
|
|
|
|
String openId = data['openID'] ?? '';
|
|
|
|
String unionId = data['unionID'] ?? '';
|
|
|
|
if (unionId.isEmpty) {
|
|
|
|
Utils.showToast('华为账号授权失败,请稍后重试');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
App.sp!.setString('openid', openId);
|
|
|
|
App.sp!.setString('unionid', unionId);
|
|
|
|
String authorizationCode = data['authorizationCode'] ?? '';
|
|
|
|
if (authorizationCode.isNotEmpty) {
|
|
|
|
App.sp!.setString('huawei_authorization_code', authorizationCode);
|
|
|
|
}
|
|
|
|
String idToken = data['idToken'] ?? '';
|
|
|
|
if (idToken.isNotEmpty) {
|
|
|
|
App.sp!.setString('huawei_id_token', idToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
createStoreModel.storeInfo = StoreInfo();
|
|
|
|
NavigatorUtil.goIfNeedCreateStorePage(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
///获取微信登录code
|
|
|
|
_getWxCode() {
|
|
|
|
responseListener = (res) {
|
|
...
|
...
|
@@ -734,6 +819,8 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
setState(() {
|
|
|
|
_check = !_check;
|
|
|
|
});
|
|
|
|
_huaweiLoginViewController
|
|
|
|
?.setAgreementStatus(_check);
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.topCenter,
|
|
...
|
...
|
@@ -750,48 +837,68 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
width: ScreenUtil().setWidth(26),
|
|
|
|
height: ScreenUtil().setWidth(26)),
|
|
|
|
)),
|
|
|
|
// HEmptyView(30),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: ScreenUtil().setWidth(2)),
|
|
|
|
child: Text(
|
|
|
|
'已阅读并同意',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
NavigatorUtil.goWebPage(context, '软件服务协议', "xy");
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(top: ScreenUtil().setWidth(2)),
|
|
|
|
child: Text(
|
|
|
|
'《软件服务协议》',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_333333),
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: ScreenUtil().setWidth(2)),
|
|
|
|
child: Text('及',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999))),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
NavigatorUtil.goWebPage(context, '隐私政策', "zc");
|
|
|
|
},
|
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(top: ScreenUtil().setWidth(2)),
|
|
|
|
child: Text('《隐私政策》',
|
|
|
|
padding:
|
|
|
|
EdgeInsets.only(top: ScreenUtil().setWidth(2)),
|
|
|
|
child: Wrap(
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
runSpacing: ScreenUtil().setWidth(2),
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
'已阅读并同意',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_333333))),
|
|
|
|
)
|
|
|
|
color: MyColours.color_999999),
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
NavigatorUtil.goWebPage(
|
|
|
|
context, '软件服务协议', "xy");
|
|
|
|
},
|
|
|
|
child: Text(
|
|
|
|
'《软件服务协议》',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_333333),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text('及',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999)),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
NavigatorUtil.goWebPage(
|
|
|
|
context, '隐私政策', "zc");
|
|
|
|
},
|
|
|
|
child: Text('《隐私政策》',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_333333)),
|
|
|
|
),
|
|
|
|
if (Platform.isOhos) ...[
|
|
|
|
Text('和',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_999999)),
|
|
|
|
InkWell(
|
|
|
|
onTap: () {
|
|
|
|
NavigatorUtil.goWebUrl(
|
|
|
|
context,
|
|
|
|
'华为账号用户认证协议',
|
|
|
|
'https://privacy.consumer.huawei.com/legal/id/authentication-terms.htm?code=CN&language=zh-CN');
|
|
|
|
},
|
|
|
|
child: Text('《华为账号用户认证协议》',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(24),
|
|
|
|
color: MyColours.color_333333)),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
...
|
...
|
@@ -876,6 +983,20 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
NavigatorUtil.goAccountLoginPage(context);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
// 华为账号登录
|
|
|
|
Platform.isOhos
|
|
|
|
? Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: ScreenUtil().setWidth(90),
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
bottom: ScreenUtil().setWidth(30),
|
|
|
|
right: ScreenUtil().setWidth(80),
|
|
|
|
left: ScreenUtil().setWidth(80)),
|
|
|
|
child: HuaweiLoginView(
|
|
|
|
onViewCreated: _onHuaweiLoginViewCreated,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Text(''),
|
|
|
|
// ios登录
|
|
|
|
Platform.isAndroid || Platform.isOhos
|
|
|
|
? Text('')
|
|
...
|
...
|
@@ -941,4 +1062,3 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
));
|
|
|
|
}
|
|
|
|
} |
|
|
|
|
...
|
...
|
|