Skip to content

Commit

Permalink
Merge pull request #65 from Hao-yiwen/fix/initdataslowly
Browse files Browse the repository at this point in the history
Fix/initdataslowly
  • Loading branch information
Hao-yiwen authored Nov 29, 2024
2 parents 9d16c2e + b6a3ecc commit 1d18b8f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@
"type": "dart",
"flutterMode": "release"
}
{
"name": "Flutter: Attach to Device",
"type": "dart",
"request": "attach"
}
]
}
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
#base-application-name=?????
android.suppressUnsupportedCompileSdk=34
7 changes: 7 additions & 0 deletions contrbuite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Android 运行错误修复

直接在android studio设置jdk版本是可以的,但是flutter运行并不会生效,需要在终端设置jdk版本

```bash
flutter config --jdk-dir /Users/yw.hao/Library/Java/JavaVirtualMachines/corretto-17.0.9/Contents/Home
```
4 changes: 2 additions & 2 deletions lib/common/constants/url.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
final NETEASE_INFO_LIST =
"https://fn.music.163.com/g/xrn/12cdffe6499557a8b53a8c5c0cca4b01?userid=265031418&dlt=0846&app_version=9.1.50";

final BASE_URL = 'http://192.168.1.8:3000';
// final BASE_URL = 'http://39.105.115.83:1231/';
// final BASE_URL = 'http://192.168.0.102:3000';
// final BASE_URL = 'http://39.105.115.83:3000/';
final BASE_URL = 'http://127.0.0.1:3000/';

final PLACE_IMAGE_HOLDER = 'https://picsum.photos/100/100';
2 changes: 1 addition & 1 deletion lib/http/api/message/message_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class MessageApi {
final res = await HttpUtils.get("/msg/private");
return PrivateMessage.fromJson(res);
}
}
}
7 changes: 6 additions & 1 deletion lib/http/http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ class Http {
requestOptions = requestOptions.copyWith(extra: {
"refresh": refresh,
});
Map<String, dynamic> queryParams = {
...?params,
// "realIP": "116.25.146.177",
};
Response response;
// 拼接 &realIP=116.25.146.177
response = await _dio.get(
path,
queryParameters: params,
queryParameters: queryParams,
options: requestOptions,
);
return response.data;
Expand Down
27 changes: 15 additions & 12 deletions lib/pages/found/found_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,21 @@ class FoundController extends GetxController {
@override
void onInit() {
super.onInit();
_getBanner();
_getHomeBlock();
_getMvList();
}

initData() async {
try {
loading.value = true;
await Future.wait([
_getBanner(),
_getHomeBlock(),
_getMvList(),
] as Iterable<Future>);
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

refreshHome() {
Expand All @@ -50,35 +62,28 @@ class FoundController extends GetxController {

_getBanner() async {
try {
loading.value = true;
if (Platform.isIOS) {
banner.value = await FoundApi.getBanner(BannerType.IPHONE.value);
} else {
banner.value = await FoundApi.getBanner(BannerType.ANDROID.value);
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

Future<void> _getMvList() async {
try {
loading.value = true;
mvList.value = await FoundApi.getAllMvList();
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

static FoundController get to => Get.find<FoundController>();

_getHomeBlock({bool isRefresh = false}) async {
try {
loading.value = true;
homeBlock.value = await FoundApi.getHomeBlock(isRefresh: isRefresh);

// HOMEPAGE_SLIDE_SONGLIST_ALIGN获取mediaItem列表
Expand All @@ -88,8 +93,6 @@ class FoundController extends GetxController {
await _buildNewSongNewAlbum();
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

Expand Down
65 changes: 27 additions & 38 deletions lib/pages/main/main_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,43 +77,49 @@ class MainController extends GetxController {
super.onReady();
}

refreshMainPage() {
// 获取私人雷达
_getPrivateRadar();
// 获取推荐歌曲
_getRecommandSongs();
// 从喜欢的音乐中选择多首音乐,然后生成相似音乐 从相似音乐分别选择6首音译额,共计需要18首音乐
_getSameSongsFromSomeRadomMusic();
// 获取私人fm音乐
_getPersonalFm();
// 获取网友推荐顶级歌单
_getRandomTopPlayList();
// 获取推荐歌单
_getPersonalizedPlayLists();
// 获取个人歌单
_getOwnPlayList();
// 获取推荐播客
getPersonalizedDjProgram();
refreshMainPage() async {
try {
loading.value = true;

await Future.wait([
// 获取私人雷达
_getPrivateRadar(),
// 获取推荐歌曲
_getRecommandSongs(),
// 从喜欢的音乐中选择多首音乐,然后生成相似音乐 从相似音乐分别选择6首音译额,共计需要18首音乐
_getSameSongsFromSomeRadomMusic(),
// 获取私人fm音乐
_getPersonalFm(),
// 获取网友推荐顶级歌单
_getRandomTopPlayList(),
// 获取推荐歌单
_getPersonalizedPlayLists(),
// 获取个人歌单
_getOwnPlayList(),
// 获取推荐播客
getPersonalizedDjProgram(),
] as Iterable<Future>);
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

_getRecommandSongs() async {
try {
loading.value = true;
recommendSongsDto?.value = await MainApi.getRecommendSongs();
if (recommendSongsDto.value.dailySongs?.isNotEmpty ?? false) {
dailySongs.value = RoamingController.to
.song2ToMedia(recommendSongsDto.value!.dailySongs!);
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

_getPrivateRadar() async {
try {
loading.value = true;
// 首先先从推荐资源拿到私人雷达的歌单id
recommendResourceDto.value = await MainApi.getRecommendResource();
int privateRadarId = recommendResourceDto.value.recommend?[0]?.id ?? 0;
Expand All @@ -127,8 +133,6 @@ class MainController extends GetxController {
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

Expand Down Expand Up @@ -158,7 +162,6 @@ class MainController extends GetxController {
*/
_getSameSongsFromSomeRadomMusic() async {
try {
loading.value = true;
// 获取喜欢的音乐
await _getLikeSongs();
// 从喜欢的音乐中选择多首音乐
Expand Down Expand Up @@ -204,8 +207,6 @@ class MainController extends GetxController {
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

Expand Down Expand Up @@ -235,7 +236,6 @@ class MainController extends GetxController {

_getRandomTopPlayList() async {
try {
loading.value = true;
// 获取网友推荐顶级歌单
TopPlaylistsDto topPlaylistsDto = await MainApi.getTopPlayList();
if (topPlaylistsDto != null && topPlaylistsDto.playlists != null) {
Expand All @@ -258,14 +258,11 @@ class MainController extends GetxController {
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

_getPersonalizedPlayLists() async {
try {
loading.value = true;
PersonalizedPlayLists personalizedPlayLists =
await MainApi.getPersonalizedPlaylists();
if (personalizedPlayLists != null &&
Expand All @@ -274,14 +271,11 @@ class MainController extends GetxController {
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

_getOwnPlayList() async {
try {
loading.value = true;
if (HomeController.to.userData.value.profile != null) {
UserPlaylists userPlaylists = await MainApi.getUserPlaylists(
HomeController.to.userData.value.profile!.userId!);
Expand All @@ -291,19 +285,14 @@ class MainController extends GetxController {
}
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}

getPersonalizedDjProgram() async {
try {
loading.value = true;
personalizedDjprogramDto.value = await MainApi.getDjProgramRecommend();
} catch (e) {
LogBox.error(e);
} finally {
loading.value = false;
}
}
}

0 comments on commit 1d18b8f

Please sign in to comment.