class MyWidget extends StatefulWidget {
const MyWidget({Key? key}) : super(key: key);
@override
State<MyWidget> createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
List<String> cities = ['New York', 'Paris', 'Tokyo', 'London'];
Future<void> _refresh() async {
// your refresh logic here
await Future.delayed(const Duration(seconds: 2));
setState(() {});
print('huh??');
}
@override
Widget build(BuildContext context) {
return Container(
height: 400,
child: RefreshIndicator(
onRefresh: _refresh,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: cities.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 100,
height: 100,
color: Colors.blue,
child: Center(
child: Text(cities[index]),
),
),
);
},
),
),
);
}
}
I have this widget. I am trying to execute _refresh()
function when I pull the side on the right. However, it does not work and I dunno what I have to add to make it work now. I also tried to pull the left side but does not work as well.
2
Answers
There is problem with your _refresh() function. Try to add new data in _refresh() function,which you want to update and its working perfectly.
Here in this post’s comment. It is said that
Refersh Indicator
doesn’t work onHorizontal
Scrolling. and another comment shows the workaround to tackle this. I made it easier for you: