搜索插件、代码仓与 APP 分类

插件详情v1.8.1

once

希望定期运行一段代码(一次 - 每日 - 每周 - 每月 - 新版本构建时 - 新版本发布时 - 任意周期)?我们来帮你解决。

AndroidiOS
近 30 天下载
4200
喜欢数
311
Pub 分数
160

安装插件

flutter pub add once

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

‘once’ 包使开发者能够根据各种触发器(如每日、每周、每月、新应用构建或新版本发布)精确执行一次代码。它简化了显示欢迎界面、收集用户反馈或在更新后初始化数据等一次性操作的实现。该包以简单性和可靠性为核心设计,可在 Android 和 iOS 平台无缝运行。该包非常适合管理周期性或基于事件的一次性逻辑,而无需手动跟踪状态。

适合场景

  • 每个应用版本仅显示一次引导屏幕
  • 在首次启动时触发分析数据收集
  • 仅在新版本中显示更新日志
  • 在应用重建后运行初始化任务
  • 安排一次性通知
  • 在首次打开应用时执行设置流程

主要特点

  • 支持多种触发类型(每日、每周、每月等)
  • 自动跨应用重启持久化
  • 无需手动管理状态
  • 轻量且易于集成
  • 适用于 Android 和 iOS
  • 处理版本和构建号检测

适合对象

  • 应用入门流程
  • 用户参与功能
  • 分析和反馈收集
  • 更新后设置任务
  • 简单的定时一次性操作

使用建议

  • 不支持自定义时间间隔,超出预设选项
  • 依赖设备的系统时钟进行定时
  • 可能需要处理时区变化相关的边界情况
  • 每个触发类型限一次执行
  • 不适用于重复性任务

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

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

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。