Skip to content

Commit

Permalink
[Feat] Add toast;
Browse files Browse the repository at this point in the history
[Change] Add retry in display2PlayMusic.
  • Loading branch information
canxin121 committed May 11, 2024
1 parent cb03b32 commit 34e4cd8
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 113 deletions.
25 changes: 16 additions & 9 deletions lib/comp/card/music_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:glassmorphism_ui/glassmorphism_ui.dart';

class MusicCard extends StatefulWidget {
final dynamic music;
final Color fontColor;
final bool darkFontColor;
final VoidCallback? onClick;
final Future<bool>? hasCache;
final Padding? padding;
Expand All @@ -29,8 +29,8 @@ class MusicCard extends StatefulWidget {
this.padding,
this.showQualityBackGround = true,
this.height = 60,
this.fontColor = CupertinoColors.black,
this.titleBold = true});
this.titleBold = true,
this.darkFontColor = false});

@override
MusicCardState createState() => MusicCardState();
Expand Down Expand Up @@ -95,7 +95,9 @@ class MusicCardState extends State<MusicCard> {
info.name,
style: TextStyle(
fontSize: 14.0,
color: widget.fontColor,
color: widget.darkFontColor
? CupertinoColors.systemGrey6
: CupertinoColors.black,
fontWeight: widget.titleBold ? FontWeight.bold : null,
).useSystemChineseFont(),
overflow: TextOverflow.ellipsis,
Expand All @@ -105,7 +107,9 @@ class MusicCardState extends State<MusicCard> {
info.artist.join(", "),
style: TextStyle(
fontSize: 12.0,
color: widget.fontColor,
color: widget.darkFontColor
? CupertinoColors.systemGrey5
: CupertinoColors.black,
fontWeight: FontWeight.w500)
.useSystemChineseFont(),
overflow: TextOverflow.ellipsis,
Expand All @@ -114,7 +118,7 @@ class MusicCardState extends State<MusicCard> {
),
),
),
if (info.duration != null)
if (info.defaultQuality != null || info.duration != null)
Row(
children: [
// 显示音质
Expand All @@ -136,8 +140,9 @@ class MusicCardState extends State<MusicCard> {
info.defaultQuality!.short,
style: TextStyle(
fontSize: 10.0,
color: widget.fontColor,
fontWeight: FontWeight.bold,
color: widget.darkFontColor
? CupertinoColors.systemGrey6
: CupertinoColors.black,
).useSystemChineseFont(),
),
),
Expand All @@ -148,7 +153,9 @@ class MusicCardState extends State<MusicCard> {
formatDuration(info.duration!),
style: TextStyle(
fontSize: 10.0,
color: widget.fontColor,
color: widget.darkFontColor
? CupertinoColors.systemGrey5
: CupertinoColors.black,
).useSystemChineseFont(),
),
// 音乐总时长和是否下载图标的间隙
Expand Down
5 changes: 2 additions & 3 deletions lib/comp/card/playing_music_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ class PlayingMusicCardState extends State<PlayingMusicCard> {
() => Text(
playingMusicName,
style: const TextStyle(
color: CupertinoColors.white,
color: CupertinoColors.systemGrey6,
fontSize: 14.0,
fontWeight: FontWeight.bold,
).useSystemChineseFont(),
overflow: TextOverflow.ellipsis,
),
Expand All @@ -93,7 +92,7 @@ class PlayingMusicCardState extends State<PlayingMusicCard> {
playingMusicArtist,
style: const TextStyle(
fontSize: 12.0,
color: CupertinoColors.white,
color: CupertinoColors.systemGrey5,
fontWeight: FontWeight.w500)
.useSystemChineseFont(),
overflow: TextOverflow.ellipsis,
Expand Down
13 changes: 11 additions & 2 deletions lib/comp/form/music_list_table_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:app_rhyme/src/rust/api/cache.dart';
import 'package:app_rhyme/src/rust/api/mirror.dart';
import 'package:app_rhyme/util/default.dart';
import 'package:app_rhyme/util/helper.dart';
import 'package:chinese_font_library/chinese_font_library.dart';
import 'package:flutter/cupertino.dart';
import 'package:image_picker/image_picker.dart';

Expand Down Expand Up @@ -103,7 +104,11 @@ class MusicListDialogState extends State<MusicListDialog> {
),
actions: <CupertinoDialogAction>[
CupertinoDialogAction(
child: const Text('取消'),
child: Text(
'取消',
style: const TextStyle(color: CupertinoColors.black)
.useSystemChineseFont(),
),
onPressed: () {
Navigator.of(context).pop();
},
Expand All @@ -119,7 +124,11 @@ class MusicListDialogState extends State<MusicListDialog> {
));
}
},
child: const Text('完成'),
child: Text(
'完成',
style: const TextStyle(color: CupertinoColors.black)
.useSystemChineseFont(),
),
),
],
);
Expand Down
13 changes: 12 additions & 1 deletion lib/comp/play_page_comp/music_list.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:app_rhyme/comp/card/music_card.dart';
import 'package:app_rhyme/comp/form/music_list_table_form.dart';
import 'package:app_rhyme/main.dart';
import 'package:app_rhyme/page/home.dart';
import 'package:app_rhyme/page/in_music_album.dart';
import 'package:app_rhyme/src/rust/api/cache.dart';
import 'package:app_rhyme/src/rust/api/mirror.dart';
import 'package:app_rhyme/types/music.dart';
Expand Down Expand Up @@ -41,7 +43,7 @@ class PlayMusicList extends StatelessWidget {
),
itemBuilder: (context, index) => MusicCard(
titleBold: false,
fontColor: CupertinoColors.white,
darkFontColor: true,
height: itemHeight,
showQualityBackGround: false,
padding: Padding(padding: picPadding),
Expand Down Expand Up @@ -177,4 +179,13 @@ List<PullDownMenuEntry> displayListMusicCardPullDown(
},
icon: CupertinoIcons.create,
),
PullDownMenuItem(
onTap: () async {
globalTopUiController.updateWidget(InMusicAlbumListPage(
key: UniqueKey(),
music: DisplayMusic(music.ref, info_: music.info)));
},
title: "查看专辑",
icon: CupertinoIcons.music_albums,
),
];
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MyApp extends StatelessWidget {
title: 'AppRhyme',
theme: CupertinoThemeData(
brightness: Brightness.light,
primaryColor: CupertinoColors.white,
primaryColor: CupertinoColors.black,
textTheme: CupertinoTextThemeData(
textStyle: const TextStyle(color: CupertinoColors.black)
.useSystemChineseFont()),
Expand Down
87 changes: 56 additions & 31 deletions lib/page/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ class FloatWidgetController extends GetxController {

class TopUiController extends GetxController {
var currentIndex = 0.obs;
Rx<Widget> currentWidget = Rx<Widget>(const MusicTablesPage());

Rx<Widget> currentWidget = Rx<Widget>(const MusicListsPage());
Widget musicListsPageWidget = const MusicListsPage();
Widget searchPageWidget = const SearchPage();
void changeTabIndex(int index) {
currentIndex.value = index;
update();
switch (index) {
case 0:
currentWidget.value = const MusicTablesPage();
currentWidget.value = musicListsPageWidget;
break;
case 1:
currentWidget.value = const SearchPage();
currentWidget.value = searchPageWidget;
break;
case 2:
currentWidget.value = const SettingsPage();
Expand All @@ -65,11 +67,30 @@ class TopUiController extends GetxController {
}

void updateWidget(Widget widget) {
currentWidget.value = widget;
update();
switch (currentIndex.value) {
case 0:
musicListsPageWidget = widget;
break;
case 1:
searchPageWidget = widget;
break;
default:
currentWidget.value = widget;
}
changeTabIndex(currentIndex.value);
}

void backToOriginWidget() {
switch (currentIndex.value) {
case 0:
musicListsPageWidget = const MusicListsPage();
break;
case 1:
searchPageWidget = const SearchPage();
break;
default:
}

changeTabIndex(currentIndex.value);
}
}
Expand Down Expand Up @@ -104,40 +125,44 @@ class HomePageState extends State<HomePage> {
child: Stack(
children: [
SafeArea(
child: Obx(() => globalTopUiController.currentWidget.value),
child: Obx(() {
return globalTopUiController.currentWidget.value;
}),
),

// 使用MediaQuery检测键盘是否可见
Align(
alignment: Alignment.bottomLeft,
alignment: Alignment.bottomCenter,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// 用来指示是否有异步任务在进行中
Obx(() => Visibility(
// Use Obx to listen to changes.
visible: globalFloatWidgetContoller.isVisible.value,
child: GestureDetector(
child: Container(
constraints: const BoxConstraints(
maxWidth: 50, maxHeight: 50),
decoration: BoxDecoration(
color: CupertinoColors.black.withOpacity(0.2),
borderRadius: BorderRadius.circular(15),
),
alignment: Alignment.center,
padding: const EdgeInsets.all(5),
child: const Icon(CupertinoIcons
.square_stack_3d_down_right_fill)),
onTapDown: (details) {
var position = details.globalPosition & Size.zero;
showPullDownMenu(
context: context,
items: floatWidgetPullDown(position),
position: position);
},
),
)),
visible: globalFloatWidgetContoller.isVisible.value,
child: Row(
children: [
GestureDetector(
child: Container(
margin: const EdgeInsets.only(left: 5, bottom: 5),
constraints: const BoxConstraints(
maxWidth: 50, maxHeight: 50),
decoration: BoxDecoration(
color: CupertinoColors.black.withOpacity(0.2),
borderRadius: BorderRadius.circular(15),
),
alignment: Alignment.center,
child: const Icon(CupertinoIcons
.square_stack_3d_down_right_fill)),
onTapDown: (details) {
var position = details.globalPosition & Size.zero;
showPullDownMenu(
context: context,
items: floatWidgetPullDown(position),
position: position);
},
),
],
))),
// 音乐播放控制栏
MusicPlayBar(
maxHeight: min(60, MediaQuery.of(context).size.height * 0.1),
Expand Down
18 changes: 13 additions & 5 deletions lib/page/in_music_album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import 'package:app_rhyme/util/default.dart';
import 'package:app_rhyme/util/helper.dart';
import 'package:app_rhyme/util/other.dart';
import 'package:app_rhyme/util/pull_down_selection.dart';
import 'package:app_rhyme/util/toast.dart';
import 'package:chinese_font_library/chinese_font_library.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pull_down_button/pull_down_button.dart';
import 'package:toastification/toastification.dart';

class InMusicAlbumListPage extends StatefulWidget {
final DisplayMusic music;
Expand Down Expand Up @@ -158,8 +160,8 @@ class InMusicAlbumListPageState extends State<InMusicAlbumListPage> {
label: '播放全部',
onPressed: () {
if (pagingController.itemList == null) return;
globalAudioHandler
.clearReplaceMusicAll(pagingController.itemList!);
globalAudioHandler.clearReplaceMusicAll(
context, pagingController.itemList!);
},
),
_buildButton(
Expand All @@ -169,7 +171,7 @@ class InMusicAlbumListPageState extends State<InMusicAlbumListPage> {
onPressed: () {
if (pagingController.itemList == null) return;
globalAudioHandler.clearReplaceMusicAll(
shuffleList(pagingController.itemList!));
context, shuffleList(pagingController.itemList!));
},
),
],
Expand Down Expand Up @@ -420,7 +422,10 @@ List<PullDownMenuEntry> musicAlbumActionPullDown(
talker.info("[MusicList Search] succeed to add musiclist");
}
} catch (e) {
// TODO: toast错误
if (context.mounted) {
toast(
context, "Music Album", "添加失败: $e", ToastificationType.error);
}
} finally {
globalFloatWidgetContoller.delMsg(index);
}
Expand All @@ -447,7 +452,10 @@ List<PullDownMenuEntry> musicAlbumActionPullDown(
position: position);
}
} catch (e) {
// TODO: 这里需要toast错误
if (context.mounted) {
toast(
context, "Music Album", "添加失败: $e", ToastificationType.error);
}
} finally {
globalFloatWidgetContoller.delMsg(index);
}
Expand Down
11 changes: 6 additions & 5 deletions lib/page/in_music_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class InMusicListPageState extends State<InMusicListPage> {
icon: CupertinoIcons.play_fill,
label: '播放全部',
onPressed: () {
globalAudioHandler.clearReplaceMusicAll(musics);
globalAudioHandler.clearReplaceMusicAll(
context, musics);
},
),
_buildButton(
Expand All @@ -116,8 +117,8 @@ class InMusicListPageState extends State<InMusicListPage> {
onPressed: () {
var musics_ = musics.toList();
musics_.shuffle();
globalAudioHandler
.clearReplaceMusicAll(shuffleList(musics_));
globalAudioHandler.clearReplaceMusicAll(
context, shuffleList(musics_));
},
),
],
Expand Down Expand Up @@ -370,8 +371,8 @@ List<PullDownMenuEntry> inListMusicCardPullDown(
const PullDownMenuDivider.large(),
PullDownMenuItem(
onTap: () async {
globalTopUiController
.updateWidget(InMusicAlbumListPage(music: music));
globalTopUiController.updateWidget(
InMusicAlbumListPage(key: UniqueKey(), music: music));
},
title: "查看专辑",
icon: CupertinoIcons.music_albums,
Expand Down
Loading

0 comments on commit 34e4cd8

Please sign in to comment.