From 40afd685dd3729645f7447dd64bb6f9c90e98ca7 Mon Sep 17 00:00:00 2001 From: Flummi Date: Mon, 30 May 2022 07:34:42 +0200 Subject: [PATCH] refresh --- lib/view/home.dart | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/view/home.dart b/lib/view/home.dart index 714796e..311a49e 100644 --- a/lib/view/home.dart +++ b/lib/view/home.dart @@ -20,6 +20,13 @@ class _HomeState extends State { f0cks = fetchDataFromApi(); } + Future loadf0cks() { + setState(() { + f0cks = fetchDataFromApi(); + }); + return f0cks; + } + @override Widget build(BuildContext context) { return Scaffold( @@ -32,8 +39,14 @@ class _HomeState extends State { body: FutureBuilder>( future: f0cks, builder: (context, snapshot) { - if(snapshot.hasData) { - return CustomScrollView( + if(!snapshot.hasData) { + return Text("${snapshot.error}"); + } + return RefreshIndicator( + onRefresh: () { + return loadf0cks(); + }, + child: CustomScrollView( shrinkWrap: true, slivers: [ SliverGrid( @@ -83,11 +96,8 @@ class _HomeState extends State { ) ), ] - ); - } else if(snapshot.hasError) { - return Text("${snapshot.error}"); - } - return const CircularProgressIndicator(); + ) + ); } ) );