WebRequest.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import 'dart:async';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. class WebRequest extends Object {
  4. bool ifPrd=false;
  5. bool ifIos=false;
  6. Future<Uri> generate(String path, Map<String, dynamic> params) async {
  7. final prefs = await SharedPreferences.getInstance();
  8. String hosts;
  9. String scheme;
  10. int ports;
  11. if (prefs.getBool("ifPrd")!) {
  12. hosts = prefs.getString('urlPath_p')!;
  13. scheme = prefs.getString('scheme_p')!;
  14. ports = prefs.getInt('ports_p')!;
  15. } else {
  16. if (prefs.getBool("ifIOS")!) {
  17. hosts = prefs.getString('urlPath_ios_d')!;
  18. scheme = prefs.getString('scheme_ios_d')!;
  19. ports = prefs.getInt('ports_ios_d')!;
  20. } else {
  21. hosts = prefs.getString('urlPath_and_d')!;
  22. scheme = prefs.getString('scheme_and_d')!;
  23. ports = prefs.getInt('ports_and_d')!;
  24. }
  25. }
  26. if (prefs.getBool("ifReal_d")!) {
  27. hosts = prefs.getString('urlPath_real_d')!;
  28. scheme = prefs.getString('scheme_real_d')!;
  29. ports = prefs.getInt('ports_real_d')!;
  30. }
  31. Uri url = Uri(
  32. scheme: scheme,
  33. host: hosts,
  34. port: ports,
  35. path: path,
  36. queryParameters: params);
  37. return url;
  38. }
  39. }