once 1.6.3 once: ^1.6.3 copied to clipboard
Want to run a piece of code once periodically (Once - Daily - Weekly - Monthly - On new build - On new version - Any period)? We cover your back.
once #
Want to run/show a piece of code/widget once (Once - Hourly - Daily - Weekly - Monthly - Every new version - Any custom duration)? We cove your back.
Some things should happen once.
- Users should only get the guided tour once.
- Release notes should only pop up once every new app version comes.
- Etc.. once every (Whatever you want).
Once
supports runOnce
, runOnEveryNewVersion
, runEvery12Hours
, runHourly
, runDaily
, runOnNewDay
, runWeekly
, runMonthly
, runOnNewMonth
, runYearly
and runCustom
.
Some widgets should show once.
- Users should only get this alert OnceWidget.
- Hello it new version widget shows OnceWidget every new app version comes.
- Etc.. OnceWidget every (Whatever you want).
OnceWidgets
supports showOnce
, showOnEveryNewVersion
, showEvery12Hours
, showHourly
, showDaily
, showOnNewDay
, showWeekly
, showMonthly
, showOnNewMonth
, showYearly
and showCustom
.
Usage #
Once #
Mainly runner functions consists of callbacks and fallbacks
callback
is the generic function that runs and returns afuture<T?>
.fallback
is the same but only runs in case that callback future returns null.
Now you're ready to go. Say you wanted to show the new features dialog when new version of the app come:
Once.runOnEveryNewVersion(
callback: () {
/* What's new in 2.3.2 version? dialog */
},
fallback: () {
/* Navigate to new screen */
},
);
Or maybe you want to show the rate this app dialog weekly:
if (!rated) {
Once.runWeekly("ratingDialog",
callback: () {
/* Like our app, Please rate us. dialog */
},
fallback: () {
/* Thanks */
},
);
}
OnceWidget #
Mainly builder functions consists of builders and fallbacks
builder
is the generic function that shows and returns aWidget
and provide forBuildContext
.fallback
is the same but only shows in case that callback future returns null (defaults toSizedBox.shrink()
) and provide forBuildContext
.
Now you're ready to go. Say you wanted to view a banner widget when the app is updated:
OnceWidget.showOnEveryNewVersion(
builder: (context) {
return Container(...);
},
);
Or maybe you want to show the hello new week widget weekly:
OnceWidget.showWeekly("weekWidget",
builder: (context) {
return Text('Hello, New Week');
},
fallback: (context) {
return Text('Hello!');
},
);
Additional #
Functions #
clear
removes theOnce
orOnceWidget
data for a specifickey
.clearAll
removes all theOnce
andOnceWidget
data.
Parameters #
debugCallback
used to debug thecallback
function.debugFallback
used to debug thefallback
function.
Note: The debug parameters are only works in debug mode.
Contributors #
Inspired by the Java library Once made by Jon Finerty