Skip to content

Instantly share code, notes, and snippets.

@branflake2267
Created April 16, 2018 01:18
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save branflake2267/003b4455043a343f23ad665963f89be1 to your computer and use it in GitHub Desktop.
Save branflake2267/003b4455043a343f23ad665963f89be1 to your computer and use it in GitHub Desktop.
Flutter - Using the Refresh Indicator
import 'dart:async';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.purple,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _count = 0;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Home Page"),
),
body: new RefreshIndicator(
child: new ListView(
children: _getItems(),
),
onRefresh: _handleRefresh,
),
);
}
List<Widget> _getItems() {
var items = <Widget>[];
for (int i = _count; i < _count + 4; i++) {
var item = new Column(
children: <Widget>[
new ListTile(
title: new Text("Item $i"),
),
new Divider(
height: 2.0,
)
],
);
items.add(item);
}
return items;
}
Future<Null> _handleRefresh() async {
await new Future.delayed(new Duration(seconds: 3));
setState(() {
_count += 5;
});
return null;
}
}
@branflake2267
Copy link
Author

ttps://youtu.be/sI3UbjDcTsk - The youtube video covering this code.

@stackoverflows
Copy link

@branflake2267 your videos are really well put together, great job and thank you!

@mohammedbabelly
Copy link

thanks man

@IraKarp
Copy link

IraKarp commented Oct 7, 2020

thank you

@daltoncabrera
Copy link

thanks Sir.

@TarunBinwal
Copy link

thanks sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment