For Once widgets use flutter_once

Related tags

Widgets once
Overview

once

For Once widgets use flutter_once

Want to run a piece of code 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, runWeekly, runMonthly, runOnNewMonth, runYearly and Custom (Duration).

Usage

Mainly runner functions consists of callbacks and fallbacks

  • callback are the generic functions that run and returns a future .
  • fallback are the same but only runs in case if that callback future returns null.

Now you're ready to go. Say you wanted to show the new features dialog when the app is updated:

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 every week for the user:

if (!rated) {
  Once.runWeekly("ratingDialog",
    callback: () { 
       /* Like our app, Please rate us. dialog */ 
    },
    fallback: () {
      /* Thanks */
    },
  );
}

Contributors

inspired by the java library Once made by Jon Finerty

Comments
  • Split the package into two

    Split the package into two

    Hello. I've noticed the package does two things: it has widgets integrated with the once and also does the timer logic thing. This mean the package has a unnecessary dependency on Flutter, those running Dart only can't use it. So, it would be nice to split into once and once_flutter, something like that.

    opened by Ascenio 3
  • runDaily and runOnNewDay not showing expected behaviour

    runDaily and runOnNewDay not showing expected behaviour

    Steps to reproduce:

    1. Use the default flutter app
    2. Convert stateless into statefull widget
    3. Insert the following code into the class _MyAppState
      @override
      void initState() {
        super.initState();
    
        Once.runOnNewDay(
          'testonce',
          callback: () {
            debugPrint("Once is running");
            return true;
          },
            debugCallback: true,
          fallback: () {
            debugPrint("Fallback triggered");
          }
        );
      }
    

    After starting the app for the first time the console shows

    I/flutter (26773): Once is running

    After stopping the app and running it again the console shows:

    I/flutter (27127): Once is running

    Expected behavior: I would expect to get the log message the first time the app is running but not the second time.

    Running on Android Emulator.

    Output of flutter doctor -v

    [✓] Flutter (Channel stable, 3.0.5, on Ubuntu 20.04.4 LTS 5.13.0-52-generic, locale de_DE.UTF-8)
        • Flutter version 3.0.5 at /home/olf/snap/flutter/common/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f1875d570e (vor 5 Wochen), 2022-07-13 11:24:16 -0700
        • Engine revision e85ea0e79c
        • Dart version 2.17.6
        • DevTools version 2.12.2
    
    [!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /home/olf/Android/Sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /opt/android-studio-2021.2.1/android-studio/jre/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        ✗ Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
    
    [✓] Chrome - develop for the web
        • Chrome at google-chrome
    
    [✓] Linux toolchain - develop for Linux desktop
        • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
        • cmake version 3.10.2
        • ninja version 1.8.2
        • pkg-config version 0.29.1
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at /opt/android-studio-2021.2.1/android-studio
        • Flutter plugin version 69.0.2
        • Dart plugin version 212.5744
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] Android Studio
        • Android Studio at /opt/android-studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    
    [✓] Connected device (3 available)
        • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 31) (emulator)
        • Linux (desktop)              • linux         • linux-x64      • Ubuntu 20.04.4 LTS 5.13.0-52-generic
        • Chrome (web)                 • chrome        • web-javascript • Google Chrome 104.0.5112.101
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    opened by wayofwood 1
  • [FEATURE REQUEST] Add todo API

    [FEATURE REQUEST] Add todo API

    One of the most important features of Once java impl is the Todo API.

    Have you thought about including it?

    For example, suppose that you want to display the rate app modal after some conditions are met on a specific screen. You can achieve that easily using the todo API

    opened by mirland 1
  • Once at the first install

    Once at the first install

    Hello,

    Is it possible to add the APP_AT_INSTALL like the java library ? It will fired only at the first launch to show an introduction screens slider. NewVersion will not work in this case.

    Thks V.

    opened by vptcnt 1
  • New update 2.0.0

    New update 2.0.0

    2.0.0

    • all periodic functions now are returning a nullable generic typed Future Future<T?>
    • you can now use FutureBuilder to return a widget from once like so
      • FutureBuilder<Widget?>(
            future: Once.runDaily<Widget?>(
                "MyKey",
                (){/* handling the callback to return a [Widget] or [null] */},
            ),
            builder: (_, snapshot) {
                if (snapshot.hasData) {
                    return snapshot.data!;
                } else {
                    /* handling a fallback widget if [myNullableWidget] returns null */
                }
            },
        )
        
    opened by SPiercer 0
Owner
Mostafa Soliman
Mobile Engineer
Mostafa Soliman
Flutter package: Assorted layout widgets that boldly go where no native Flutter widgets have gone before.

assorted_layout_widgets I will slowly but surely add interesting widgets, classes and methods to this package. Despite the package name, they are not

Marcelo Glasberg 122 Dec 22, 2022
Flutter-useful-widgets - Flutter Useful Widgets

useful_widgets This package makes it easy to build apps by providing a list of simple and useful widgets. import 'package:useful_widgets/useful_widget

Ricardo Crescenti 6 Jun 20, 2022
Widgets beginner - Widgets beginner with flutter

Widgets beginner - Widgets beginner with flutter

Tukhtamurodov Sardorbek 2 Feb 6, 2022
React hooks for Flutter. Hooks are a new kind of object that manages a Widget life-cycles. They are used to increase code sharing between widgets and as a complete replacement for StatefulWidget.

English | Português Flutter Hooks A Flutter implementation of React hooks: https://medium.com/@dan_abramov/making-sense-of-react-hooks-fdbde8803889 Ho

Remi Rousselet 2.6k Dec 29, 2022
A code generator to write widgets as function without loosing the benefits of classes.

Widgets are cool. But classes are quite verbose: class Foo extends StatelessWidget { final int value; final int value2; const Foo({Key key, thi

Remi Rousselet 528 Dec 29, 2022
Code generation for Flutter Padding widgets based on your constants

Code generation for Flutter Padding widgets based on your constants

Emanuele 14 Oct 20, 2022
A provider that passes EventBus down to all the widgets.

A provider that passes EventBus down to all the widgets.

null 0 Jul 9, 2022
Animate SliverAppBar's widgets when scrolling

Animate SliverAppBar's widgets when scrolling

null 6 Oct 2, 2022
This package supports drag & drop widgets inside the GridView.builder for multiplatform

This package supports drag & drop widgets inside the GridView.builder for multiplatform. It provides all the properties which are available in Gridview. builder and easy to implement with the few lines of code.

MindInventory 68 Dec 29, 2022
Flutter widgets and themes implementing the current macOS design language.

macos_ui Flutter widgets and themes implementing the current macOS design language. NOTE: This package depends on the excellent native_context_menu pl

Reuben Turner 1.1k Jan 7, 2023
Flutter Package for Easier Creation of Home Screen Widgets

Home Widget HomeWidget is a Plugin to make it easier to create HomeScreen Widgets on Android and iOS. HomeWidget does not allow writing Widgets with F

Anton Borries 405 Dec 31, 2022
This repo is for anything that can be reusable in flutter like custom widgets 🟥, animations 🌟and more

Flutter Shortcuts This repo is for anything that can be reusable in flutter like custom widgets ?? , animations ?? and more. How to Use Just get the f

Abdelrahman Mostafa Elmarakby 91 Dec 3, 2022
Library Widgets

Library Widgets Installing 1. Depend on it Add this to your package's pubspec.yaml file: dependencies: library_widgets: ^0.0.1 2. Install it You can

Leonardo Serrano 1 Oct 28, 2021
A basic Flutter app that includes some native Widgets like alerts, cards, avatars, animated container, inputs, etc.

Flutter components This project was created with Flutter and some native Widgets like alerts, cards, avatars, animated container, inputs, etc. Getting

Paúl 4 Nov 15, 2021
A Flutter package which provides helper widgets for selecting single or multiple account/user from the given list.

account_selector A Flutter package which provides helper widgets for selecting single or multiple account/user from a list Supported Dart Versions Dar

Harpreet Singh 49 Oct 7, 2021
Custom Flutter widgets that makes Checkbox and Radio Buttons much cleaner and easier.

custom_radio_grouped_button Custom Radio Buttons and Grouped Check Box Button Custom Flutter widgets that makes Checkbox and Radio Buttons much cleane

Ketan Choyal 144 Sep 23, 2022
A collection of widgets for making amazing onboarding experience in your flutter applications

Pal widgets A flutter package for better onboarding. A set of amazing onboarding widgets for your flutter applications. Install package add in your pu

Apparence.io 25 Oct 7, 2022
A flutter widget for comparing two stacked widgets by dragging a slider thumb to reveal either sides of the slider horizontally or vertically.

Juxtapose A flutter widget for comparing two stacked widgets by dragging a slider thumb to reveal either sides of the slider horizontally or verticall

Leslie Arkorful 74 Nov 24, 2022
An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

An extensive snap tool/widget for Flutter that allows very flexible snap management and snapping between your widgets.

AliYigitBireroglu 101 Dec 16, 2022