Flutter Button It should be pressed once in a day
NickName:Arpit Jai Ask DateTime:2021-08-16T12:57:18

Flutter Button It should be pressed once in a day

Is there any where I can make a button to be pressed only once in a day. You cannot press that button again in that day. you need to wait till next day inorder to press it again

                  ElevatedButton(
                      onPressed: () {
                        print("Once in a day");
                        title = "Change Date";
                      },
                      child: Text(title),
                    ),

Copyright Notice:Content Author:「Arpit Jai」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68797565/flutter-button-it-should-be-pressed-once-in-a-day

Answers
Bhoomika Chauhan 2021-08-16T07:03:51

Add below code in your onPress function,\nElevatedButton(\n onPressed: () {\n SharedPreferences prefs = await SharedPreferences.getInstance();\n final currentTime = DateTime.now();\n DateTime resetTime = DateTime.parse(prefs.getString("time"));\n \n if(resetTime != null && !compareDate(currentTime, resetTime))\n prefs.setBool("one_tap", true);\n \n if(prefs.getBool("one_tap") == null || prefs.getBool("one_tap")){\n print("Once in a day");\n title = "Change Date";\n prefs.setBool("one_tap", false);\n prefs.setString("time", currentTime.toString());\n }\n},\nchild: Text(title),),\n\ncompareDate(DateTime current, DateTime reset) {\n if (reset != null) {\n return current.year == reset.year &&\n current.month == reset.month &&\n current.day == reset.day;\n } else {\n return true;\n }\n }\n",


More about “Flutter Button It should be pressed once in a day” related questions

Flutter Button It should be pressed once in a day

Is there any where I can make a button to be pressed only once in a day. You cannot press that button again in that day. you need to wait till next day inorder to press it again

Show Detail

create five button in flutter only one button should be pressed at once when clicked the button its color should change also refactor the widget

create five buttons in a row in flutter such that only one button should be pressed at once, when the button is pressed it color should change from white to red also the text color, also refactor the

Show Detail

Flutter TextField should open when button is pressed

First of all, I'm completely new to programming. I'm trying to make a to do app. My problem is that when the button on the bottom left is pressed, it should open up a text field, in which the user ...

Show Detail

Change button from another view controller once the back button has been pressed

I'm trying to hide/disable a button from another view controller once the back button from a nav bar has been pressed, but I can't figure it out. Basically, I have a view controller where a user ca...

Show Detail

How to update a value only once flutter

I want to update a integer type value in firebase database on button pressed ,, but the issue is I want to update the value only once in firebase database on button pressed when user pressed button...

Show Detail

Is there a way I can run a python Script when a button programmed in flutter is pressed?

Essentially , what I want to do is , press a button that I program in Flutter and when that button is pressed , a python script should start running on my Android device . I want to use youtube-dl (

Show Detail

Flutter - Continuously call a function as long as a button is pressed

I was wondering if it exists a way to continuously call a function on Flutter as long as a button (any kind of button is okay) is pressed. For example: GestureDetector( child: Container(),

Show Detail

Change the state of button to pressed

What I am trying to achieve: When the button is pressed for the first time, it should get highlighted/ activated / pressed. On the second click on the button it should get unactivated/ not pressed....

Show Detail

using meta tag once button is pressed

I have a Button setup and I am wondering how I would run the meta only once the button is pressed. Here is the button code: <button type="button" class="btn btn-primary" onclick="waitingDialog...

Show Detail

create a button that can only be pressed once

i am trying to create a button that can only be pressed once for a game in python but i cant figure out how to set a variable that works in the def and does not change every time the function is ru...

Show Detail