Home > Blockchain >  Flutter “Please wait ….. minutes for this” function
Flutter “Please wait ….. minutes for this” function

Time:10-21

I'm new to Flutter. I want to write a function so that users don't constantly change their profile pictures and occupy storage space. For example, the user will be able to run the function that changes the profile photo every 20 minutes. If the user tries to change their profile photo before the 20 minutes are up, a notification will appear. How can I do it? Can you help me? Can i do this with if/else? Here are some codes:

void chooseProfileImage() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext bc) {
        return SafeArea(
          child: Container(
            child: new Wrap(
              children: <Widget>[
                new ListTile(
                    leading: new Icon(Icons.photo_library),
                    title: new Text(
                      "From Gallery",
                      style: TextStyle(fontFamily: Constants.appFont),
                    ),
                    onTap: () {
                      proImgFromGallery();
                      Navigator.of(context).pop();
                    }),
                new ListTile(
                  leading: new Icon(Icons.photo_camera),
                  title: new Text(
                    "From Camera",
                    style: TextStyle(fontFamily: Constants.appFont),
                  ),
                  onTap: () {
                    proImgFromCamera();
                    Navigator.of(context).pop();
                  },
.
.
.

CodePudding user response:

Since you are working with a database, you should add a new field to the user table which contains a timestamp of the last modificataion.

Another option could be storing the timestamp on the device, e.g. in the shared preferences. But thats a unsafe solution because the user could just delete the app data and the timestamp would be gone.

With the given timestamp you can now perform a if conditon and decide to wheter allow the action or not.

  • Related