|
...
|
...
|
@@ -17,10 +17,12 @@ import 'package:one_key/provider/create_store_model.dart'; |
|
|
|
import 'package:one_key/provider/other_login_provider.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/route/navigate_service.dart';
|
|
|
|
import 'package:one_key/utils/navigator_util.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
|
|
import 'package:one_key/widgets/MyDivider.dart';
|
|
|
|
import 'package:one_key/widgets/h_empty_view.dart';
|
|
|
|
import 'package:one_key/widgets/loading.dart';
|
|
|
|
import 'package:one_key/widgets/round_button.dart';
|
|
|
|
import 'package:one_key/widgets/v_empty_view.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
...
|
...
|
@@ -50,7 +52,7 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
String errorText = ""; //错误提示
|
|
|
|
|
|
|
|
bool _check = true;
|
|
|
|
StreamSubscription<BaseWeChatResponse> _wxlogin;
|
|
|
|
StreamSubscription<BaseWeChatResponse> streamSubscription;
|
|
|
|
OtherLoginProvider otherLoginProvider;
|
|
|
|
CreateStoreModel createStoreModel;
|
|
|
|
|
|
...
|
...
|
@@ -58,7 +60,7 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
super.initState();
|
|
|
|
_initFluwx();
|
|
|
|
_checkWechat();
|
|
|
|
isLogin();
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
...
|
...
|
@@ -74,13 +76,23 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//初始化微信SDK
|
|
|
|
_initFluwx() async {
|
|
|
|
await registerWxApi(
|
|
|
|
appId: "wx85aa3cdd0f791e65",
|
|
|
|
doOnAndroid: true,
|
|
|
|
doOnIOS: true,
|
|
|
|
universalLink: "https://xt04.colorcun.com/link/OneKey/");
|
|
|
|
//当页面离开时要清除监听器
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
if (streamSubscription != null) {
|
|
|
|
streamSubscription.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//微信是否安装
|
|
|
|
_checkWechat() async {
|
|
|
|
// await registerWxApi(
|
|
|
|
// appId: "wx85aa3cdd0f791e65",
|
|
|
|
// doOnAndroid: true,
|
|
|
|
// doOnIOS: true,
|
|
|
|
// universalLink: "https://xt04.colorcun.com/link/OneKey/");
|
|
|
|
var result = await isWeChatInstalled;
|
|
|
|
if (result != null && result) {
|
|
|
|
App.isInstallWx = true;
|
|
...
|
...
|
@@ -102,13 +114,6 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
super.didChangeDependencies();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
// TODO: implement dispose
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
//监听输入框,设置登录按钮状态
|
|
|
|
setActivate() {
|
|
|
|
if (_sellerCodeController.text.isNotEmpty &&
|
|
...
|
...
|
@@ -148,11 +153,12 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
|
|
|
|
///获取微信登录code
|
|
|
|
_getWxCode() {
|
|
|
|
_wxlogin = fluwx.weChatResponseEventHandler
|
|
|
|
streamSubscription = fluwx.weChatResponseEventHandler
|
|
|
|
.distinct((a, b) => a == b)
|
|
|
|
.listen((res) {
|
|
|
|
if (res is fluwx.WeChatAuthResponse && res.errCode == 0) {
|
|
|
|
LogUtil.v("code:" + res.code);
|
|
|
|
// Loading.showLoading(context);
|
|
|
|
_getAccessToken(res.code);
|
|
|
|
} else {
|
|
|
|
// Utils.showToast(res.errStr??"登录失败,请稍后重试");
|
|
...
|
...
|
@@ -167,7 +173,8 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
LogUtil.v("access_token:${response.toString()}");
|
|
|
|
Map<String, dynamic> responseData = json.decode(response.data.toString());
|
|
|
|
if (responseData["errcode"] != null) {
|
|
|
|
// Utils.showToast(responseData["errmsg"]??"登录,请稍后重试");
|
|
|
|
Utils.showToast(responseData["errmsg"] ?? "登录,请稍后重试");
|
|
|
|
// Loading.hideLoading(context);
|
|
|
|
} else {
|
|
|
|
App.sp.setString("openid", responseData["openid"]);
|
|
|
|
App.sp.setString("unionid", responseData["unionid"]);
|
|
...
|
...
|
@@ -179,9 +186,11 @@ class LoginState extends State<LoginPage> with WidgetsBindingObserver { |
|
|
|
Map<String, String> params = {
|
|
|
|
"unionid": responseData["unionid"],
|
|
|
|
};
|
|
|
|
|
|
|
|
BuildContext contextTemp =
|
|
|
|
App.getIt<NavigateService>().key.currentState.overlay.context;
|
|
|
|
CheckbindPhoneSunModel model =
|
|
|
|
await otherLoginProvider.checkbindPhone(context, params);
|
|
|
|
await otherLoginProvider.checkbindPhone(contextTemp, params);
|
|
|
|
// Loading.hideLoading(context);
|
|
|
|
if (model != null) {
|
|
|
|
createStoreModel.storeInfo = StoreInfo();
|
|
|
|
createStoreModel.storeInfo.phone = model.phone;
|
...
|
...
|
|