Search packages, repositories and app categories

Package detailsv1.8.1

once

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.

AndroidiOS
30-day downloads
3.3K
Likes
311
Pub points
160

Install package

flutter pub add once

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The 'once' package enables developers to execute code exactly once based on various triggers such as daily, weekly, monthly, on a new app build, or on a new version release. It simplifies the implementation of one-time actions like showing welcome screens, collecting user feedback, or initializing data after updates. Built with simplicity and reliability in mind, it works seamlessly across Android and iOS platforms. The package is ideal for managing periodic or event-based one-time logic without manual state tracking.

Use cases

  • Show onboarding screens once per app version
  • Trigger analytics collection on first launch
  • Display update changelogs only on new version
  • Run initialization tasks after app rebuild
  • Schedule one-time notifications
  • Execute setup routines on first app open

Key features

  • Supports multiple trigger types (daily, weekly, monthly, etc.)
  • Automatic persistence across app restarts
  • No need for manual state management
  • Lightweight and easy to integrate
  • Works on both Android and iOS
  • Handles version and build number detection

Suitable for

  • App onboarding flows
  • User engagement features
  • Analytics and feedback collection
  • Post-update setup tasks
  • Simple scheduled one-time actions

Considerations

  • Does not support custom time intervals beyond predefined options
  • Relies on device's system clock for timing
  • May require handling edge cases around time zone changes
  • Limited to one-time execution per trigger type
  • Not suitable for recurring tasks

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

once pub

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, runUntilDone, 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, showUntilDone, 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 a future<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 */
    },
  );
}

Or maybe you want to show a feature prompt until the user explicitly dismisses it:

Once.runUntilDone("feature_prompt",
  callback: (dismiss) { 
     /* Show feature prompt dialog */ 
     // Call dismiss() when the user clicks "Got it"
     dismiss();
  },
  fallback: () {
    /* Feature already acknowledged */
  },
);

OnceWidget

Mainly builder functions consists of builders and fallbacks

  • builder is the generic function that shows and returns a Widget and provide for BuildContext.
  • fallback is the same but only shows in case that callback future returns null (defaults to SizedBox.shrink()) and provide for BuildContext.

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!');
   },
);

Or maybe you want to show a banner until the user dismisses it:

OnceWidget.showUntilDone("onboarding_banner",
  builder: (dismiss) {
     return Row(
       children: [
         Text('New feature available!'),
         ElevatedButton(
           onPressed: dismiss, // Will not show again after being clicked
           child: Text('Got it'),
         ),
       ],
     );
   },
  fallback: () {
     return SizedBox.shrink();
   },
);

Additional

Functions
  • clear removes the Once or OnceWidget data for a specific key.
  • clearAll removes all the Once and OnceWidget data.
  • markDone manually flags a key as completed for untilDone operations.
Parameters
  • debugCallback used to debug the callback function.
  • debugFallback used to debug the fallback function.

Note: The debug parameters are only works in debug mode.

Contributors

Inspired by the Java library Once made by Jon Finerty

Categories

Dependencies

Dependency list 2 items

Source repository

Projects using this package

No data available yet.