Handle image loading errors
This commit is contained in:
parent
1d721dd682
commit
c96bd3d14d
@ -9,12 +9,14 @@ class CoverImage extends StatelessWidget {
|
|||||||
final double? width;
|
final double? width;
|
||||||
final double? height;
|
final double? height;
|
||||||
final BoxFit? fit;
|
final BoxFit? fit;
|
||||||
|
final Icon? icon;
|
||||||
|
|
||||||
const CoverImage({
|
const CoverImage({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.music,
|
required this.music,
|
||||||
this.width,
|
this.width,
|
||||||
this.height,
|
this.height,
|
||||||
|
this.icon,
|
||||||
this.fit,
|
this.fit,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@ -28,8 +30,20 @@ class CoverImage extends StatelessWidget {
|
|||||||
cacheKey: music.coverCacheKey,
|
cacheKey: music.coverCacheKey,
|
||||||
httpHeaders: {"Token": config.apiToken},
|
httpHeaders: {"Token": config.apiToken},
|
||||||
useOldImageOnUrlChange: false,
|
useOldImageOnUrlChange: false,
|
||||||
placeholder: (c, s) => const Center(child: CircularProgressIndicator()),
|
progressIndicatorBuilder: (c, s, p) => _loadingWidget(p.progress),
|
||||||
fit: fit,
|
fit: fit,
|
||||||
|
errorWidget: (c, s, e) => _loadingWidget(null),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _loadingWidget(double? progress) => Container(
|
||||||
|
color: Colors.black,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
child: Center(
|
||||||
|
child: progress == null
|
||||||
|
? icon
|
||||||
|
: CircularProgressIndicator(value: progress),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:music_web_player/api.dart';
|
import 'package:music_web_player/api.dart';
|
||||||
@ -43,6 +44,18 @@ class _MusicPlayerState extends State<MusicPlayer> {
|
|||||||
height: constraints.maxHeight,
|
height: constraints.maxHeight,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
ClipRRect(
|
||||||
|
// Clip it cleanly.
|
||||||
|
child: BackdropFilter(
|
||||||
|
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
|
||||||
|
child: Container(
|
||||||
|
color: Colors.black.withOpacity(0.3),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Container(),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
|
||||||
_buildFront(),
|
_buildFront(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user