Skip to content

Commit

Permalink
feat: 控制器加载时机优化
Browse files Browse the repository at this point in the history
  • Loading branch information
yw.hao committed Dec 3, 2024
1 parent 72c257a commit 35f1ace
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
12 changes: 7 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import 'package:netease_cloud_music_app/common/utils/log_box.dart';
import 'package:netease_cloud_music_app/http/http_utils.dart';
import 'package:netease_cloud_music_app/pages/home/home_binding.dart';
import 'package:netease_cloud_music_app/pages/login/login_controller.dart';
import 'package:netease_cloud_music_app/pages/message/message_binding.dart';
import 'package:netease_cloud_music_app/pages/message/message_controller.dart';
import 'package:netease_cloud_music_app/pages/mv_player/mv_player_controller.dart';
import 'package:netease_cloud_music_app/pages/search/searchpage_controller.dart';
import 'package:netease_cloud_music_app/pages/splash/splash_controller.dart';
import 'package:netease_cloud_music_app/pages/user/user_binding.dart';
import 'package:netease_cloud_music_app/pages/user/user_controller.dart';
Expand Down Expand Up @@ -65,11 +66,12 @@ Widget _buildMaterialApp(BuildContext context, AppRouter appRouter) {
Bindings _initializeBindings() {
return BindingsBuilder(() {
HomeBinding().dependencies();
UserBinding().dependencies();
MessageBinding().dependencies();
Get.lazyPut(() => UserController());
Get.lazyPut(() => MessageController());
Get.lazyPut(() => SplashController());
Get.lazyPut(() => MvPlayerController());
Get.lazyPut(() => LoginController()); // Add LoginController initialization
Get.lazyPut(() => LoginController());
Get.lazyPut(() => SearchpageController());
});
}

Expand Down Expand Up @@ -131,7 +133,7 @@ class MyObserver extends AutoRouterObserver {
Future<void> _initGetService(GetIt getIt) async {
// 创建一个经过优化配置的 AudioPlayer 实例
final audioPlayer = AudioPlayer(
audioLoadConfiguration: AudioLoadConfiguration(
audioLoadConfiguration: const AudioLoadConfiguration(
// Optimize buffer management
androidLoadControl: AndroidLoadControl(
// Reduce minimum buffer to prevent backup
Expand Down
1 change: 0 additions & 1 deletion lib/pages/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class _SearchState extends State<Search> {
}

void _initController() {
Get.lazyPut(() => SearchpageController());
controller = Get.find<SearchpageController>();
textEditingController.text = controller.textvalue.value;
controller.getSearchKeyWords();
Expand Down
2 changes: 0 additions & 2 deletions lib/pages/search/search_detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class _SearchDetailState extends State<SearchDetail>
Tab(text: '视频'),
Tab(text: '歌单'),
Tab(text: '歌手'),
Tab(text: '专辑'),
],
labelStyle: TextStyle(
fontSize: 32.sp,
Expand Down Expand Up @@ -163,7 +162,6 @@ class _SearchDetailState extends State<SearchDetail>
const MvList(key: PageStorageKey('Tab1')),
_buildSongList(),
const Center(child: Text('歌手')),
const Center(child: Text('专辑')),
],
);
});
Expand Down
11 changes: 8 additions & 3 deletions lib/pages/search/song_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ class SongList extends GetView<SearchpageController> {
Widget build(BuildContext context) {
return Obx(() {
final songs = controller.searchResult.value.result?.songs;
if (songs == null || songs.isEmpty) {
final searchSongs = controller.searchSongs.value;

if (songs == null || songs.isEmpty || searchSongs.isEmpty) {
return const Center(child: Text('暂无数据'));
}

return ListView.builder(
itemCount: songs.length,
itemBuilder: (context, index) {
final song = songs[index];
if (index >= searchSongs.length) {
return null;
}
return GestureDetector(
key: ValueKey(controller.searchSongs.value[index].id),
key: ValueKey(searchSongs[index].id),
onTap: () {
RoamingController.to.playByIndex(
index,
'queueTitle',
mediaItem: controller.searchSongs.value,
mediaItem: searchSongs,
);
Roaming.showBottomPlayer(context);
},
Expand Down

0 comments on commit 35f1ace

Please sign in to comment.