mirror of
https://github.com/flutter/samples.git
synced 2026-06-25 07:38:26 +00:00
Hello, I noticed that there are several image URLs that fail to load on the Activities screen of the compass_app. The image shows the default error widget right now. This PR proposes to display a placeholder with a "broken image" icon instead of the default error widget. This provides better visual feedback to the user. Current: <img width="354" height="275" alt="image" src="https://github.com/user-attachments/assets/3688e1a0-c36d-40ef-9474-001e3576d55a" /> After fix: <img width="354" height="275" alt="image" src="https://github.com/user-attachments/assets/0f853596-6b9c-4b82-b646-8a3cf01c6ad0" /> @ericwindmill, please take a look and see if it is appropriate. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I have added sample code updates to the [changelog]. - [x] I updated/added relevant documentation (doc comments with `///`). <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md [changelog]: ../CHANGELOG.md Co-authored-by: Eric Windmill <eric@ericwindmill.com>
90 lines
2.5 KiB
Dart
90 lines
2.5 KiB
Dart
// Copyright 2024 The Flutter team. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../domain/models/activity/activity.dart';
|
|
import '../../../utils/image_error_listener.dart';
|
|
import '../../core/ui/custom_checkbox.dart';
|
|
|
|
class ActivityEntry extends StatelessWidget {
|
|
const ActivityEntry({
|
|
super.key,
|
|
required this.activity,
|
|
required this.selected,
|
|
required this.onChanged,
|
|
});
|
|
|
|
final Activity activity;
|
|
final bool selected;
|
|
final ValueChanged<bool?> onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
height: 80,
|
|
child: Row(
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(8),
|
|
child: CachedNetworkImage(
|
|
errorWidget: (context, url, error) => _ActivityErrorPlaceholder(),
|
|
imageUrl: activity.imageUrl,
|
|
height: 80,
|
|
width: 80,
|
|
errorListener: imageErrorListener,
|
|
),
|
|
),
|
|
const SizedBox(width: 20),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
activity.timeOfDay.name.toUpperCase(),
|
|
style: Theme.of(context).textTheme.labelSmall,
|
|
),
|
|
Text(
|
|
activity.name,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(width: 20),
|
|
CustomCheckbox(
|
|
key: ValueKey('${activity.ref}-checkbox'),
|
|
value: selected,
|
|
onChanged: onChanged,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ActivityErrorPlaceholder extends StatelessWidget {
|
|
const _ActivityErrorPlaceholder({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: 80,
|
|
height: 80,
|
|
decoration: BoxDecoration(
|
|
color: Colors.grey[200],
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Icon(
|
|
Icons.broken_image_outlined,
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
),
|
|
);
|
|
}
|
|
}
|