Component - Pull-to-refresh
This UI component allows users to refresh the content on the screen by pulling down from the top. It is commonly used in lists or feeds to update data.
This UI component allows users to refresh the content on the screen by pulling down from the top. It is commonly used in lists or feeds to update data.
Scaffold
├── AppBar
└── RefreshIndicator
└── ListView
├── ListTile
├── ListTile
└── ...RefreshIndicator in a Flutter app?RefreshIndicator in Flutter?onRefresh callback and a child widget that is scrollable.onRefresh: _refresh and child: ListView(). RefreshIndicator(child: ListView(), refresh: _refresh) uses wrong parameter name refresh. RefreshIndicator(refreshCallback: _refresh, child: ListView()) uses refreshCallback which is incorrect. RefreshIndicator(onRefresh: _refresh()) calls _refresh() instead of passing the function.RefreshIndicator(
onRefresh: () async {
await Future.delayed(Duration(seconds: 2));
},
child: ListView(
children: [Text('Item 1'), Text('Item 2')],
),
)RefreshIndicator:
RefreshIndicator(
onRefresh: () async {
// refresh logic
},
child: Column(
children: [Text('Item 1'), Text('Item 2')],
),
)class MyList extends StatefulWidget {
@override
State<MyList> createState() => _MyListState();
}
class _MyListState extends State<MyList> {
List<String> items = ['Old item'];
Future<void> _refresh() async {
final newData = await fetchDataFromInternet();
// What should you do here?
}
@override
Widget build(BuildContext context) {
return RefreshIndicator(
onRefresh: _refresh,
child: ListView(
children: items.map((e) => Text(e)).toList(),
),
);
}
}Pass the test and this pattern moves unknown