基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

53 lines
1.8 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_comm/util/dialog/loading/loading.dart';
  3. import 'package:zhiying_comm/util/pdd_auth/pdd_auth_dialog.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. import 'package:flutter/cupertino.dart';
  6. import 'package:url_launcher/url_launcher.dart';
  7. import 'pdd_auth_model.dart';
  8. import 'pdd_auth_repository.dart';
  9. class PddAuth {
  10. ///
  11. /// 进行拼多多授权 (无参数授权,需要请求接口)
  12. /// bool = true 需要授权,bool = false 不需要授权
  13. ///
  14. static Future<bool> auth(BuildContext context, {String isShare = '1'}) async {
  15. // 开启loading
  16. Loading.show(context);
  17. PddAuthModel model = await PddAuthRepository().fetchNetData(isShare: isShare);
  18. Loading.dismiss();
  19. if (!EmptyUtil.isEmpty(model)) {
  20. return await PddAuth.authParam(context, model.toJson());
  21. }
  22. return false;
  23. }
  24. ///
  25. /// 进行拼多多授权(有参数授权)
  26. ///
  27. static Future<bool> authParam(context, Map<String, dynamic> data) async {
  28. try {
  29. if (EmptyUtil.isEmpty(context) || EmptyUtil.isEmpty(data)) return false;
  30. PddAuthModel model = PddAuthModel.fromJson(data);
  31. if (EmptyUtil.isEmpty(model) || EmptyUtil.isEmpty(model.noOpenAppUrl) || EmptyUtil.isEmpty(model.schemaUrl) || (model?.isPop ?? '0') == '0') return false;
  32. bool isConfirm = await showDialog(context: context, builder: (_) => PddAuthDialog());
  33. /// 前往授权
  34. if (isConfirm) {
  35. // 1. 判断是否安装
  36. bool launched = await canLaunch(model.schemaUrl);
  37. if (launched) {
  38. launched = await launch(model.schemaUrl);
  39. }
  40. if (!launched) {
  41. RouterUtil.openWebview(model.noOpenAppUrl, context);
  42. }
  43. }
  44. } catch (e, s) {
  45. Logger.error(e, s);
  46. }
  47. return true;
  48. }
  49. }