Pull to refresh
Pull to refresh asks for a new version of an existing list. Keep the last result visible while the update runs so the reader can tell what changed.
Update the board
#Pull down from the top of the board, or press Refresh. A completed update advances the issue number.
components/pull-to-refresh/appliance/update_board.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class UpdateBoard extends StatefulWidget {
const UpdateBoard({super.key});
@override
State<UpdateBoard> createState() => _UpdateBoardState();
}
class _UpdateBoardState extends State<UpdateBoard> {
int issue = 1;
bool loading = false;
Future<void> refresh() async {
if (loading) return;
setState(() => loading = true);
await Future<void>.delayed(const Duration(milliseconds: 350));
if (!mounted) return;
setState(() {
issue++;
loading = false;
});
}
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 90,
child: ApplianceRefresh(
onRefresh: refresh,
child: ListView(
physics: const AlwaysScrollableScrollPhysics(),
children: [ApplianceListTile(title: 'Issue $issue')],
),
),
),
const SizedBox(height: 12),
ApplianceButton(
loading ? 'Updating' : 'Refresh',
onPressed: loading ? null : refresh,
),
],
),
);
}
Parameters
ApplianceRefresh API ↗onRefresh- Returns a future that completes when the list has finished updating.
child- The scroll view.
Shared behaviour
- Keyboard and focus. Tab to Refresh and activate it to request the same update as a pull. The button is unavailable while that update runs.
- Screen readers. Look for the refresh action on the list. After either trigger, read the new issue number in the first row.
- Direction and type. Try the gesture in RTL. It still starts at the top, and the issue label uses the selected text size.