搜尋套件、儲存庫與 APP 分類

套件詳情v1.8.1

once

希望定期執行一段程式碼(一次 - 每日 - 每週 - 每月 - 新建構時 - 新版本發布時 - 任意週期)?我們來幫你解決。

AndroidiOS
近 30 天下載
3340
喜歡數
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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。