实现代码如下
static Future<String> getUrlLangJson(String url) async {
try {
final res = await Dio().get(
url,
options: Options(responseType: ResponseType.bytes),
);
final sss = utf8.decode(res.data);
return sss;
} catch (e) {
return "";
}
}
因为web端没有文件系统 没有办法实现app的方式 (下面的)因为没有文件系统
"[多语言] 获取网络数据".w();
final r = await Api.languageVersion();
final data = r["data"] ?? {};
// int version = data["version"];
String url = data["url"] ?? "";
String curCacheDirectoryPath = await getCacheDirectory();
String savePath = '$curCacheDirectoryPath/langs.json';
// 将下载的文件写入文件里面去
await Dio(
BaseOptions(
connectTimeout: const Duration(seconds: 5),
receiveTimeout: const Duration(seconds: 5),
sendTimeout: const Duration(seconds: 5),
),
).download(url, savePath);
setCacheJson(File(savePath));