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

View file

@ -29,6 +29,8 @@ class TimelinePostWidget extends StatefulWidget {
} }
class _TimelinePostWidgetState extends State<TimelinePostWidget> { class _TimelinePostWidgetState extends State<TimelinePostWidget> {
bool imageError = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var theme = Theme.of(context); var theme = Theme.of(context);
@ -110,10 +112,29 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
height: 250, height: 250,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
image: DecorationImage( image: imageError
image: CachedNetworkImageProvider(widget.post.imageUrl!), ? DecorationImage(
fit: BoxFit.cover, 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,
),
), ),
), ),
if (post.image != null) if (post.image != null)

View file

@ -19,7 +19,7 @@ class LocalPostRepository implements PostRepositoryInterface {
userId: "1", userId: "1",
firstName: "Jane", firstName: "Jane",
lastName: "Doe", lastName: "Doe",
imageUrl: "https://via.placeholder.com/150", imageUrl: "https://placehold.co/150.png?text=Jane",
); );
final List<TimelinePost> _posts = List.generate( final List<TimelinePost> _posts = List.generate(
@ -47,7 +47,7 @@ class LocalPostRepository implements PostRepositoryInterface {
userId: "2", userId: "2",
firstName: "John", firstName: "John",
lastName: "Doe", 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", userId: "1",
firstName: "Jane", firstName: "Jane",
lastName: "Doe", 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", userId: "1",
firstName: "john", firstName: "john",
lastName: "doe", lastName: "doe",
imageUrl: "https://via.placeholder.com/150", imageUrl: "https://placehold.co/150.png?text=John",
), ),
const TimelineUser( const TimelineUser(
userId: "2", userId: "2",
firstName: "jane", firstName: "jane",
lastName: "doe", lastName: "doe",
imageUrl: "https://via.placeholder.com/150", imageUrl: "https://placehold.co/150.png?text=Jane",
), ),
]; ];