Skip to content

Instantly share code, notes, and snippets.



Last active Jul 15, 2019
What would you like to do?
import 'dart:async';
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(PullToRefresh());
class PullToRefresh extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Pull To Refresh',
home: HomePage(),
class HomePage extends StatefulWidget {
_HomePageState createState() => _HomePageState();
class _HomePageState extends State<HomePage> {
var list;
var random;
var refreshKey = GlobalKey<RefreshIndicatorState>();
void initState() {
list = List.generate(3, (i) => "Item $i");
random = Random();
Future<Null> refreshList() async {
refreshKey.currentState?.show(atTop: false);
await Future.delayed(Duration(seconds: 2));
setState(() {
list = List.generate(random.nextInt(10), (i) => "Item $i");
return null;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Pull to refresh"),
body: RefreshIndicator(
key: refreshKey,
child: ListView.builder(
itemCount: list?.length,
itemBuilder: (context, i) => ListTile(
title: Text(list[i]),
onRefresh: refreshList,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment