parameterhelper.dart 874 B

123456789101112131415161718192021222324252627282930313233
  1. import 'package:universal_html/html.dart' as html;
  2. ///获取参数类
  3. class ParameterHelper {
  4. ///参数集,第二窗口使用
  5. static Map<String, String> parameterMap = {};
  6. ///Url带的参数
  7. static String searchUrl = '';
  8. ///获取App启动参数
  9. static Map<String, String> getAppStartParameters() {
  10. Map<String, String> map = {};
  11. var url = html.window.location.toString();
  12. final parameters = url.split('?');
  13. if (parameters.length > 1) {
  14. final parameterStr = parameters[1];
  15. final keyValues = parameterStr.split('&');
  16. for (var kv in keyValues) {
  17. final keyValue = kv.split('=');
  18. map[keyValue[0]] = keyValue[1];
  19. }
  20. if (map.isNotEmpty) {
  21. parameterMap = map;
  22. searchUrl = url;
  23. html.window.history.replaceState('', '', url);
  24. return map;
  25. }
  26. }
  27. return {};
  28. }
  29. }