feat:参照研听的基础工程
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
class AppConfig {
|
||||
const AppConfig({required this.apiBaseUrl});
|
||||
final String apiBaseUrl;
|
||||
factory AppConfig.fromEnvironment() {
|
||||
const url = String.fromEnvironment(
|
||||
'JINZHI_API_BASE_URL',
|
||||
defaultValue: 'https://jinzhi.api.local',
|
||||
);
|
||||
return const AppConfig(apiBaseUrl: url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
class AppH5Urls {
|
||||
const AppH5Urls._();
|
||||
|
||||
static const baseUrl = String.fromEnvironment(
|
||||
'JINZHI_H5_BASE_URL',
|
||||
defaultValue: 'https://jinzhi.h5.local',
|
||||
);
|
||||
|
||||
static String get privacyUrl => '$baseUrl/beginner/privacyPolicy.html';
|
||||
static String get userProtocolUrl => '$baseUrl/beginner/user_agreement.html';
|
||||
}
|
||||
|
||||
class AppH5UrlsHelper {
|
||||
const AppH5UrlsHelper._();
|
||||
|
||||
static String buildUrl(String url, [Map<String, dynamic>? params]) {
|
||||
if (params == null || params.isEmpty) return url;
|
||||
final uri = Uri.parse(url);
|
||||
final merged = <String, String>{
|
||||
...uri.queryParameters,
|
||||
...params.map((key, value) => MapEntry(key, value.toString())),
|
||||
};
|
||||
return uri.replace(queryParameters: merged).toString();
|
||||
}
|
||||
|
||||
static String buildUrlWithNight(String url, bool isDark) {
|
||||
if (!isDark) return url;
|
||||
return buildUrl(url, {'isNight': '1'});
|
||||
}
|
||||
|
||||
static String withCacheBuster(String url) {
|
||||
final uri = Uri.parse(url);
|
||||
final params = Map<String, String>.from(uri.queryParameters);
|
||||
params['_cb'] = DateTime.now().microsecondsSinceEpoch.toString();
|
||||
return uri.replace(queryParameters: params).toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shorebird_code_push/shorebird_code_push.dart';
|
||||
|
||||
class ShorebirdService {
|
||||
ShorebirdService._();
|
||||
|
||||
static final ShorebirdService instance = ShorebirdService._();
|
||||
final ShorebirdUpdater _updater = ShorebirdUpdater();
|
||||
Patch? currentPatch;
|
||||
|
||||
bool get isAvailable => _updater.isAvailable;
|
||||
|
||||
Future<Patch?> readCurrentPatch() => _updater.readCurrentPatch();
|
||||
|
||||
Future<void> initCurrentPatch() async {
|
||||
try {
|
||||
currentPatch = await _updater.readCurrentPatch();
|
||||
} catch (error) {
|
||||
debugPrint('Error reading current patch: $error');
|
||||
}
|
||||
}
|
||||
|
||||
Future<UpdateStatus> checkForUpdate({
|
||||
UpdateTrack track = UpdateTrack.stable,
|
||||
}) {
|
||||
return _updater.checkForUpdate(track: track);
|
||||
}
|
||||
|
||||
Future<void> downloadUpdate({UpdateTrack track = UpdateTrack.stable}) {
|
||||
return _updater.update(track: track).then((_) async {
|
||||
await initCurrentPatch();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> checkForUpdateInBackground({
|
||||
UpdateTrack track = UpdateTrack.stable,
|
||||
}) async {
|
||||
if (!isAvailable) return;
|
||||
try {
|
||||
await _updater.checkForUpdate(track: track);
|
||||
} catch (error) {
|
||||
debugPrint('Shorebird background check failed: $error');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// lib/common/config/umeng_config.dart
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
class UmengConfig {
|
||||
// Keys loaded from .env file
|
||||
static String _androidAppKey =
|
||||
'6a27b1f46f259537c7b616be'; // Default placeholder
|
||||
static String _iosAppKey = '6a27b24e6f259537c7b617a8'; // Default placeholder
|
||||
static String _androidPushSecret = 'xxx'; // Default placeholder
|
||||
|
||||
static Future<void> load() async {
|
||||
await dotenv.load(
|
||||
fileName: "assets/env/.env",
|
||||
); // Load from packaged asset path
|
||||
|
||||
_androidAppKey = dotenv.env['UMENG_ANDROID_APP_KEY'] ?? _androidAppKey;
|
||||
_iosAppKey = dotenv.env['UMENG_IOS_APP_KEY'] ?? _iosAppKey;
|
||||
_androidPushSecret =
|
||||
dotenv.env['UMENG_ANDROID_PUSH_SECRET'] ?? _androidPushSecret;
|
||||
}
|
||||
|
||||
static String get androidAppKey => _androidAppKey;
|
||||
static String get iosAppKey => _iosAppKey;
|
||||
static String get androidPushSecret => _androidPushSecret;
|
||||
}
|
||||
Reference in New Issue
Block a user