WebRequest.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import 'dart:async';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. class WebRequest extends Object {
  4. bool ifPrd;
  5. bool ifIos;
  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. //http https
  34. host: hosts,
  35. port: ports,
  36. path: path,
  37. queryParameters: params);
  38. return url;
  39. }
  40. }