mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
fix: add proper placeholder images to the local repository and a fallback image
This commit is contained in:
parent
c1b74e97f3
commit
6273a9e686
5 changed files with 33 additions and 10 deletions
BIN
packages/flutter_timeline/assets/error_image.png
Normal file
BIN
packages/flutter_timeline/assets/error_image.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
|
@ -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(
|
||||
|
|
|
@ -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,10 +112,29 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
|
|||
height: 250,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
image: DecorationImage(
|
||||
image: CachedNetworkImageProvider(widget.post.imageUrl!),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (post.image != null)
|
||||
|
|
|
@ -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",
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -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",
|
||||
),
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue