enum Environment { production, } class AppConfig { static const Environment currentEnvironment = Environment.production; static const String appName = '本地打包'; static const String appLogo = ''; static final Map> _environmentHosts = { Environment.production: [ 'h5-im.imharry.work', ], }; static List get environmentHosts { return _environmentHosts[currentEnvironment] ?? const []; } static String homeUrl({String? appName, String? appLogo}) { final host = environmentHosts.isNotEmpty ? environmentHosts.first : 'h5-im.imharry.work'; final uri = Uri.parse(_normalizeHomeUrl(host)); final queryParameters = Map.from(uri.queryParameters) ..['_h5_t'] = DateTime.now().millisecondsSinceEpoch.toString(); return uri.replace(queryParameters: queryParameters).toString(); } static String withFreshShellParams(String url) { final uri = Uri.parse(url); final queryParameters = Map.from(uri.queryParameters); queryParameters.remove('flutter_shell'); queryParameters.remove('shell_cache_bust'); queryParameters.remove('shell_app_name'); queryParameters.remove('shell_app_logo'); final fragmentParameters = Uri.splitQueryString(uri.fragment); fragmentParameters.remove('shell_app_name'); fragmentParameters.remove('shell_app_logo'); return uri .replace( queryParameters: queryParameters, fragment: fragmentParameters.isEmpty ? '' : Uri(queryParameters: fragmentParameters).query, ) .toString(); } static String _normalizeHomeUrl(String host) { final value = host.trim(); final normalized = value.startsWith('http://') || value.startsWith('https://') ? value : 'https://$value'; final uri = Uri.parse(normalized); final path = uri.path.isEmpty ? '/' : uri.path; return uri.replace(path: path).toString(); } }