Want to refresh on pull in Flutter for tab bar? Child of RefreshIndicator should be Scrollable, in the above example it is DefaultTabController because of which you are not getting the RefreshIndicator
I moved RefreshIndicator into Tab view and added a Scrollable as child (ListView). Please refer the below code
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | import 'dart:async'; import 'package:flutter/material.dart'; void main() => runApp(MaterialApp( debugShowCheckedModeBanner: false, home: HomePage(), )); class HomePage extends StatefulWidget { @override _HomePageState createState() => new _HomePageState(); } class _HomePageState extends State<HomePage> { var refreshKey = GlobalKey<RefreshIndicatorState>(); // @override // void initState() { // super.initState(); // random = Random(); // refreshList(); // } Future<Null> refreshList() async { refreshKey.currentState?.show(atTop: false); await Future.delayed(Duration(seconds: 2)); setState(() { new HomePage(); }); return null; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Pull to refresh"), ), body: new DefaultTabController( length: 5, child: new Column( children: <Widget>[ new Container( width: 1200.0, child: new Material( color: Colors.lightBlue, child: new TabBar( isScrollable: true, labelColor: Colors.white, tabs: [ Tab( child: new Text("All", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Moving", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Idle", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Parked", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Inactive", style: new TextStyle(fontSize: 20.0)), ), ], ), ), ), new Expanded( child: new TabBarView( children: [ Tab( child: new RefreshIndicator( child: new ListView( children: <Widget>[ new Column( children: <Widget>[ new Center( child: new Text("Demo", style: new TextStyle(fontSize: 20.0)), ) ], ) ], ), onRefresh: refreshList, key: refreshKey, ), ), Tab( child: new Text("Demo", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Demo", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Demo", style: new TextStyle(fontSize: 20.0)), ), Tab( child: new Text("Demo", style: new TextStyle(fontSize: 20.0)), ), ], ), ), ], ), ), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.