fix: add proper placeholder images to the local repository and a fallback image

This commit is contained in:
Jacques 2025-02-18 11:40:59 +01:00
parent c1b74e97f3
commit 6273a9e686
5 changed files with 33 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -35,6 +35,7 @@ class TimelineOptions {
this.onTapCategory,
this.onTapOverview,
this.onTapCreatePostInOverview,
this.placeholderImageAssetUrl,
});
// Builders
@ -71,6 +72,7 @@ class TimelineOptions {
final ImagePickerTheme? imagePickerTheme;
final Widget? timelineScreenDrawer;
final AppBarBuilder? timelineScreenAppBarBuilder;
final String? placeholderImageAssetUrl;
}
Widget _defaultFloatingActionButton(

View file

@ -29,6 +29,8 @@ class TimelinePostWidget extends StatefulWidget {
}
class _TimelinePostWidgetState extends State<TimelinePostWidget> {
bool imageError = false;
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
@ -110,8 +112,27 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
height: 250,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
image: DecorationImage(
image: CachedNetworkImageProvider(widget.post.imageUrl!),
image: imageError
? DecorationImage(
image: options.placeholderImageAssetUrl != null
? AssetImage(
options.placeholderImageAssetUrl!,
)
: const AssetImage(
"assets/error_image.png",
package: "flutter_timeline",
),
fit: BoxFit.cover,
)
: DecorationImage(
onError: (exception, stackTrace) {
setState(() {
imageError = true;
});
},
image: CachedNetworkImageProvider(
widget.post.imageUrl!,
),
fit: BoxFit.cover,
),
),

View file

@ -19,7 +19,7 @@ class LocalPostRepository implements PostRepositoryInterface {
userId: "1",
firstName: "Jane",
lastName: "Doe",
imageUrl: "https://via.placeholder.com/150",
imageUrl: "https://placehold.co/150.png?text=Jane",
);
final List<TimelinePost> _posts = List.generate(
@ -47,7 +47,7 @@ class LocalPostRepository implements PostRepositoryInterface {
userId: "2",
firstName: "John",
lastName: "Doe",
imageUrl: "https://via.placeholder.com/150",
imageUrl: "https://placehold.co/150.png?text=John",
),
),
],
@ -56,9 +56,9 @@ class LocalPostRepository implements PostRepositoryInterface {
userId: "1",
firstName: "Jane",
lastName: "Doe",
imageUrl: "https://via.placeholder.com/150",
imageUrl: "https://placehold.co/150.png?text=Jane",
),
imageUrl: "https://via.placeholder.com/1000",
imageUrl: "https://placehold.co/1000.png?text=$index",
),
);

View file

@ -8,13 +8,13 @@ class LocalTimelineUserRepository implements TimelineUserRepositoryInterface {
userId: "1",
firstName: "john",
lastName: "doe",
imageUrl: "https://via.placeholder.com/150",
imageUrl: "https://placehold.co/150.png?text=John",
),
const TimelineUser(
userId: "2",
firstName: "jane",
lastName: "doe",
imageUrl: "https://via.placeholder.com/150",
imageUrl: "https://placehold.co/150.png?text=Jane",
),
];