Amat3rasu
Amat3rasu

Reputation: 53

How can I make refresh page button in flutter?

How can I make refresh page button in flutter?

            new IconButton(
          icon: new Image.asset(
            '../assets/images/iconRefresh.png',
            width: 31,
            height: 31,
          ),
          tooltip: 'Refresh',
          onPressed: iconButtonPressed,
        ),

I don't know function of it. Honestly I am a rooky in programming so please help me :)

Upvotes: 4

Views: 21619

Answers (2)

Sagar Acharya
Sagar Acharya

Reputation: 3767

You can use a Refreshindicator widget Below is the sample example

RefreshIndicator(
    key: _refreshIndicatorKey,
    onRefresh: _refresh,
    child: ListView(children: [
      // body of above
    ])),

And Following is the method on Refresh

Future<Null> _refresh() {
  // You can do part here what you want to refresh
}

you can check out the complete example in the below-mentioned link: https://medium.com/flutterpub/adding-swipe-to-refresh-to-flutter-app-b234534f39a7

As you are not clear with what you have mentioned as "button" you can use the setState to make changes.

Upvotes: 1

Benedikt J Schlegel
Benedikt J Schlegel

Reputation: 1939

In Flutter, you can rebuild your Widget very easily. You can just call the setState function, and Flutter will run build again. If anything changed in your State, it will be updated. Note that this only works in Stateful Widgets.

void updateUI(){
   setState(() {
      //You can also make changes to your state here.
    });
}

Upvotes: 0

Related Questions