|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import 'package:flutter/material.dart';
- import 'package:zhiying_comm/util/dialog/loading/loading.dart';
- import 'package:zhiying_comm/util/pdd_auth/pdd_auth_dialog.dart';
- import 'package:zhiying_comm/zhiying_comm.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:url_launcher/url_launcher.dart';
-
- import 'pdd_auth_model.dart';
- import 'pdd_auth_repository.dart';
-
- class PddAuth {
- ///
- /// 进行拼多多授权 (无参数授权,需要请求接口)
- /// bool = true 需要授权,bool = false 不需要授权
- ///
- static Future<bool> auth(BuildContext context, {String isShare = '1'}) async {
- // 开启loading
- Loading.show(context);
- PddAuthModel model = await PddAuthRepository().fetchNetData(isShare: isShare);
- Loading.dismiss();
- if (!EmptyUtil.isEmpty(model)) {
- return await PddAuth.authParam(context, model.toJson());
- }
- return false;
- }
-
- ///
- /// 进行拼多多授权(有参数授权)
- ///
- static Future<bool> authParam(context, Map<String, dynamic> data) async {
- try {
- if (EmptyUtil.isEmpty(context) || EmptyUtil.isEmpty(data)) return false;
- PddAuthModel model = PddAuthModel.fromJson(data);
- if (EmptyUtil.isEmpty(model) || EmptyUtil.isEmpty(model.noOpenAppUrl) || EmptyUtil.isEmpty(model.schemaUrl) || (model?.isPop ?? '0') == '0') return false;
- bool isConfirm = await showDialog(context: context, builder: (_) => PddAuthDialog());
- /// 前往授权
- if (isConfirm) {
- // 1. 判断是否安装
- bool launched = await canLaunch(model.schemaUrl);
- if (launched) {
- launched = await launch(model.schemaUrl);
- }
- if (!launched) {
- RouterUtil.openWebview(model.noOpenAppUrl, context);
- }
- }
- } catch (e, s) {
- Logger.error(e, s);
- }
- return true;
- }
- }
|