Skip to content

mirkancal/refreshable_widget

Repository files navigation

Refreshable Widget

style: very good analysis Powered by Mason License: MIT

Refreshable widget

Goal 🏹

Refreshable Widget built for these two Stackoverflow issues, and also for my personal usage. https://stackoverflow.com/q/72025771 https://stackoverflow.com/q/66539533

Possible use case: You have a widget you use with FutureBuilder, shows an async data. But you need to update it periodically because there's no socket or stream that you can listen to. For example a progress for user in a game, which requires you to fetch whole game periodically, like every 20 seconds.

Installation 💻

❗ In order to start using Refreshable Widget you must have the Flutter SDK installed on your machine.

Add refreshable_builder to your pubspec.yaml:

dependencies:
  refreshable_builder:

Install it:

flutter packages get

Usage 🛞

/// pass the type, [num] in below, which is a return type for [refreshCall] and [value] in [builder]
RefreshableWidget<num>(
  // optional initial value if you have
  initialValue: challenge.userParticipation!.donePercent,
  // your API call or logic to refresh
  refreshCall: () async {
    final challenge = await service.getChallenge(id: widget.challengeId); 
    return challenge.userParticipation!.donePercent;
   },
  refreshRate: const Duration(seconds: 20),
  // builder, which is called every time you have new value from refreshCall
  builder: (context, value) {
    return ProgressWidget(
      percent: value,
    );
  },
  // optional error and loading widgets
),

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages