Intermediate
RefreshIndicator: How to Do Pull-to-Refresh Right
· 7 min read

What Is RefreshIndicator?
Pulling a list down from the top to refresh it is one of the most familiar interactions in mobile apps. In Flutter, the Material version of this behavior is RefreshIndicator. It wraps a scrollable widget, shows a spinning indicator when the user pulls down at the top of the list and runs the onRefresh function you provide.
The indicator stays on screen until the Future returned by onRefresh completes. This means you don't have to manage a separate loading state. When the Future finishes, the indicator disappears on its own.

Basic Usage
class MessagesPage extends StatefulWidget {
const MessagesPage({super.key});
@override
State<MessagesPage> createState() => _MessagesPageState();
}
class _MessagesPageState extends State<MessagesPage> {
final List<Message> _messages = [];
Future<void> _refresh() async {
final latest = await messageRepository.fetchLatest();
if (!mounted) return;
setState(() {
_messages
..clear()
..addAll(latest);
});
}
@override
Widget build(BuildContext context) {
return RefreshIndicator(
onRefresh: _refresh,
child: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: _messages.length,
itemBuilder: (context, index) => MessageTile(message: _messages[index]),
),
);
}
}Here, Message, MessageTile and messageRepository are classes from your own app. Two things matter: onRefresh must return a Future<void>, and the indicator stays visible until the await completes. Since the widget may have been removed from the tree after the await, mounted is checked before calling setState.
Why Doesn't the Indicator Show? AlwaysScrollableScrollPhysics
RefreshIndicator listens for overscroll at the top of the scrollable inside it. If the list doesn't fill the screen, there is nothing to scroll, so there is no overscroll and the indicator never appears. This is the most common problem with RefreshIndicator.
The fix is to give the scrollable physics: const AlwaysScrollableScrollPhysics(). This way the list can be pulled even when the content is short, and the indicator always works. That is why the example above includes the physics parameter.
Making the Empty State Refreshable
If you show a message such as "No messages yet" when the list is empty, that message must also be inside a scrollable widget. Otherwise the user can't refresh from the empty screen. SliverFillRemaining centers the message while keeping the area scrollable:
RefreshIndicator(
onRefresh: _refresh,
child: _messages.isEmpty
? const CustomScrollView(
physics: AlwaysScrollableScrollPhysics(),
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Center(child: Text('No messages yet')),
),
],
)
: ListView.builder(
physics: const AlwaysScrollableScrollPhysics(),
itemCount: _messages.length,
itemBuilder: (context, index) =>
MessageTile(message: _messages[index]),
),
)Error Handling
An error thrown inside onRefresh closes the indicator but tells the user nothing. Wrapping network requests in try/catch and informing the user is good practice:
Future<void> _refresh() async {
try {
final latest = await messageRepository.fetchLatest();
if (!mounted) return;
setState(() {
_messages
..clear()
..addAll(latest);
});
} catch (_) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Refresh failed')),
);
}
}Starting a Refresh from Code
Sometimes you want to start a refresh without the user pulling: a refresh button in the AppBar, when the page opens, or when a notification arrives. The RefreshIndicatorState.show() method opens the indicator with its animation and calls onRefresh:
final _refreshKey = GlobalKey<RefreshIndicatorState>();
RefreshIndicator(
key: _refreshKey,
onRefresh: _refresh,
child: messageList,
)
// For example, from a button in the AppBar:
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => _refreshKey.currentState?.show(),
)Customizing the Look
RefreshIndicator(
onRefresh: _refresh,
color: Colors.cyan,
backgroundColor: const Color(0xFF0F172A),
strokeWidth: 3,
displacement: 56,
edgeOffset: MediaQuery.paddingOf(context).top,
triggerMode: RefreshIndicatorTriggerMode.anywhere,
child: messageList,
)• color, backgroundColor: The colors of the spinning stroke and the circular background. • strokeWidth: The stroke thickness. • displacement: Where the indicator rests during the refresh, measured from the top edge of the scrollable. Defaults to 40. • edgeOffset: The starting point of the indicator. Increase it when the indicator would sit under a transparent AppBar. • elevation: The shadow elevation of the indicator. Defaults to 2. • triggerMode: With the default RefreshIndicatorTriggerMode.onEdge, the indicator only appears if the pull starts while the list is already at the top. With anywhere, a user who starts mid-list and drags all the way to the top can also trigger a refresh.
Platform Details
iOS and macOS
With RefreshIndicator.adaptive, a CupertinoActivityIndicator is shown on iOS and macOS instead of the Material indicator, while other platforms keep the classic look. On these platforms, the default BouncingScrollPhysics applies friction, so the same finger movement turns into a shorter pull and the user has to drag a bit further. If you want a fully native iOS experience, consider CupertinoSliverRefreshControl, which is used as a sliver inside a CustomScrollView.
Web and Desktop
By default, Flutter doesn't allow drag-scrolling with a mouse on web and desktop, so the RefreshIndicator can't be pulled with a mouse. You can enable mouse dragging by changing the app's scrollBehavior (PointerDeviceKind lives in package:flutter/gestures.dart). A refresh button that calls show() is also a good complement for desktop users:
MaterialApp(
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.trackpad,
},
),
home: const MessagesPage(),
)Nested Scrollables
By default, RefreshIndicator only listens to notifications from the scrollable directly below it (notification.depth == 0). If the actual vertical list is inside another scrollable (for example, in layouts that use NestedScrollView), you can specify which depth to listen to with notificationPredicate:
RefreshIndicator(
onRefresh: _refresh,
notificationPredicate: (notification) => notification.depth == 1,
child: outerScrollView,
)Without a Spinner: RefreshIndicator.noSpinner
If you want to show your own loading animation, RefreshIndicator.noSpinner works without an indicator and only triggers onRefresh. With the onStatusChange callback you can listen to the drag, armed and refresh states and draw your own design.
Conclusion
Adding a RefreshIndicator takes only a few lines. The details are what make the difference: AlwaysScrollableScrollPhysics for short lists and empty states, error handling that informs the user, programmatic triggering with show() when needed, and not forgetting web/desktop users. Pay attention to these and you get a refresh experience that works as expected on every platform.