54 lines
1.4 KiB
Dart
54 lines
1.4 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}) {
|
|
final host = environmentHosts.isNotEmpty
|
|
? environmentHosts.first
|
|
: 'h5-im.imharry.work';
|
|
return _withShellBranding(
|
|
_normalizeHomeUrl(host),
|
|
appName: appName,
|
|
);
|
|
}
|
|
|
|
static String _normalizeHomeUrl(String host) {
|
|
final value = host.trim();
|
|
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
return value.endsWith('/') ? value : '$value/';
|
|
}
|
|
return 'https://$value/';
|
|
}
|
|
|
|
static String _withShellBranding(
|
|
String url, {
|
|
String? appName,
|
|
}) {
|
|
final uri = Uri.parse(url);
|
|
final queryParameters = Map<String, String>.from(uri.queryParameters)
|
|
..['flutter_shell'] = '1';
|
|
|
|
final trimmedName = (appName ?? AppConfig.appName).trim();
|
|
if (trimmedName.isNotEmpty) {
|
|
queryParameters['shell_app_name'] = trimmedName;
|
|
}
|
|
|
|
return uri.replace(queryParameters: queryParameters).toString();
|
|
}
|
|
}
|