0

I have a To Do List with things to do daily like 'Drink Water' and so on. So now I want that when the user has checked a To Do, the next day it should be unchecked again. How can I implement this?

Right now my Code looks like this:

class ToDoScreen extends StatefulWidget {
  const ToDoScreen({Key key}) : super(key: key);

  @override
  _ToDoScreenState createState() => _ToDoScreenState();
}

class _ToDoScreenState extends State<ToDoScreen> {
  List toDos = ['Train Today', 'Drink Water'];
  bool value = false;

  void addToDo(String newToDo) {
    setState(() {
      toDos.add(newToDo);
    });
    Navigator.of(context).pop();
  }

  void newEntry() {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            content: TextField(
              onSubmitted: addToDo,
              decoration: InputDecoration(
                  border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(10)),
                  icon: Icon(Icons.text_snippet_outlined),
                  labelText: 'New To Do'),
            ),
          );
        });
  }
Dalon
  • 566
  • 8
  • 26

2 Answers2

1

As Yeasin Sheikh said in the comment, first of all you need to save your data somewhere, otherwhise you don't have nothing to reset.

I read in the comments that you'd like to use Firebase.

So I suppose you'll be storing data in Firebase Firestore.

The best way to perform such reset, in my opinion, is to use a Firebase Function (docs).

You could see them as server side code. From there you can define a function to access your DB and reset the data.

To trigger the function once a day, you should use an external service to call the function.

I found this question which could help you: here

L. Gangemi
  • 3,110
  • 1
  • 22
  • 47
1

while using firebase you can use firebase function as Gangemi said.

btw my approach will happen on AppSite, you need to check the reset function inside the main class every time it starts or before showing data.

if(DateTime.now().day != savedDate.day) reset();

also you can add expired DateTime and use conditional state.

DateTime.now().add(Duration(days:1))

and use

if(DateTime.now().day == savedDate.day) reset().

reset() means you are iterating list. on firebase/storage.

here reset() means delete data from storage

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56