1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
final List<String> items = List.generate(20, (i) => 'Item ${i + 1}');
Future<void> _onRefresh() async { await Future.delayed(const Duration(seconds: 2)); setState(() { items.clear(); items .addAll(List.generate(20, (i) => 'New item ${i + items.length + 1}')); }); }
void _triggerRefresh() { WidgetsBinding.instance!.addPostFrameCallback((_) { _refreshIndicatorKey.currentState!.show(); }); }
@override Widget build(BuildContext context) { _triggerRefresh() return CustomerContainer( width: 355, height: 485, children: RefreshIndicator( onRefresh: _onRefresh, key: _refreshIndicatorKey, child: ListView.builder( itemCount: items.length, itemBuilder: (context, index) { return ListTile( title: Text(items[index]), ); }), )); }
|