Files
Flutter_Shell/lib/config/app_config.dart

67 lines
2.1 KiB
Dart

enum Environment {
production,
}
class AppConfig {
static const Environment currentEnvironment = Environment.production;
static const String appName = '本地打包';
static const String appLogo = '';
static final Map<Environment, List<String>> _environmentHosts = {
Environment.production: [
'h5-im.imharry.work',
],
};
static List<String> get environmentHosts {
return _environmentHosts[currentEnvironment] ?? const [];
}
static String homeUrl({String? appName, String? appLogo}) {
final host = environmentHosts.isNotEmpty
? environmentHosts.first
: 'h5-im.imharry.work';
return _normalizeHomeUrl(host);
}
static String withFreshShellParams(String url) {
final uri = Uri.parse(url);
final queryParameters = Map<String, String>.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 withFreshShellCacheBust(String url) {
final uri = Uri.parse(url);
final queryParameters = Map<String, String>.from(uri.queryParameters)
..['shell_cache_bust'] = DateTime.now().millisecondsSinceEpoch.toString();
return uri.replace(queryParameters: queryParameters).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();
}
}