Music app
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
flutter run --release --dart-define=APP_ENV=prod
启动时通过 --dart-define=APP_ENV=
指定环境,若不指定则默认 dev
config_service.dart:14
static Future<void> init() async {
const env = String.fromEnvironment('APP_ENV');
await GetStorage.init();
await ConfigCache.setEnvironment(env.isNotEmpty ? env : Environment.dev);
initHttpClient(env.isNotEmpty ? env : Environment.dev);
...
}
配置不同环境的域名 _hostProd
_hostDev
music_dao.dart:27
static const _hostProd = 'https://brook.vercel.app';
static const _hostDev = 'http://192.168.8.27:3000';
static const _search = '/cloudsearch';
static const _personalized = '/personalized';
static const _playlistDetail = '/playlist/detail';
static const _songUrl = '/song/url/v1';
static init(String env) {
client = summer.Client(
baseURL: env == Environment.prod ? _hostProd : _hostDev,
udBeforeRequest: onBeforeRequest,
afterResponse: onAfterResponse,
);
}
Api 用的是NeteaseCloudMusicApi,建议你自行部署。 演示地址(https://brook.vercel.app) 部署在 vercel 上,可能需要科学上网才能访问。
get generate locales assets/locales