Skip to content

Commit

Permalink
优化磨砂玻璃切换效果
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferry-200 committed Oct 7, 2024
1 parent be621e1 commit c9f18c4
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions lib/page/now_playing_page/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@ class NowPlayingPage extends StatefulWidget {

class _NowPlayingPageState extends State<NowPlayingPage> {
final playbackService = PlayService.instance.playbackService;
Future<ImageProvider<Object>?>? nowPlayingCover;
ImageProvider<Object>? nowPlayingCover;

void updateCover() {
setState(() {
nowPlayingCover = playbackService.nowPlaying?.cover;
playbackService.nowPlaying?.cover.then((cover) {
if (mounted) {
setState(() {
nowPlayingCover = cover;
});
}
});
}

@override
void initState() {
super.initState();
playbackService.addListener(updateCover);
nowPlayingCover = playbackService.nowPlaying?.cover;
updateCover();
}

@override
Expand Down Expand Up @@ -95,26 +99,21 @@ class _NowPlayingPageState extends State<NowPlayingPage> {
fit: StackFit.expand,
alignment: AlignmentDirectional.center,
children: [
FutureBuilder(
future: nowPlayingCover,
builder: (context, snapshot) {
if (snapshot.data == null) return const SizedBox.shrink();

return Image(
image: snapshot.data!,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const SizedBox.shrink(),
);
if (nowPlayingCover != null) ...[
Image(
image: nowPlayingCover!,
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const SizedBox.shrink(),
),
switch (brightness) {
Brightness.dark => const ColoredBox(color: Colors.black45),
Brightness.light => const ColoredBox(color: Colors.white54),
},
),
switch (brightness) {
Brightness.dark => const ColoredBox(color: Colors.black45),
Brightness.light => const ColoredBox(color: Colors.white54),
},
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 250, sigmaY: 250),
child: const ColoredBox(color: Colors.transparent),
),
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 250, sigmaY: 250),
child: const ColoredBox(color: Colors.transparent),
),
],
ChangeNotifierProvider.value(
value: PlayService.instance.playbackService,
builder: (context, _) {
Expand Down

0 comments on commit c9f18c4

Please sign in to comment.