Media with fallback
A media frame reserves space for a picture while it is unavailable. Give the image a meaningful description and choose a shape that suits the content.
Resize a missing cover
#A route guide has no cover image. Switch between a wide and a square frame to see how the look draws its fallback at each size.
components/media/appliance/resize_cover.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class ResizeCover extends StatefulWidget {
const ResizeCover({super.key});
@override
State<ResizeCover> createState() => _ResizeCoverState();
}
class _ResizeCoverState extends State<ResizeCover> {
bool square = false;
@override
Widget build(BuildContext context) {
final aspect = square ? 1.0 : 16 / 9;
return ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 156,
child: ApplianceMedia(
slotId: 'route-guide',
semanticLabel: 'Route guide cover',
aspectRatio: aspect,
),
),
const SizedBox(height: 12),
ApplianceButton(
square ? 'Wide cover' : 'Square cover',
onPressed: () => setState(() => square = !square),
),
],
),
),
);
}
}
Parameters
ApplianceMedia API ↗slotId- The picture's media slot.
semanticLabel- What it shows, for a screen reader.
aspectRatio- Its width over its height.
placeholder- What stands in until it comes.
style- Overrides the component’s themed appearance for this instance.
Shared behaviour
- Keyboard and focus. Tab to Square cover or Wide cover and activate it to change the frame.
- Screen readers. Read the missing cover’s description and the resize action. The description stays the same when the shape changes.
- Direction and type. The empty image slot keeps its proportions in either direction. Its label and the resize action use the selected text size.