Uraam Asif
Uraam Asif

Reputation: 63

How update provider's data in Flutter Dart

I have a list of a few things and each has its own ID. I want to pass that certain ID to the provider whenever it's clicked. But as of now, when I click on ITEM ONE in the list for the first time, the ID of ITEM ONE is passed to the provider, but when I click again on a different item in the list the ID of that item is not updated in the provider. I want to know, how can I update the data of the provider every time a new item is clicked.

here are my codes:

onTap: () async {
  Provider.of<providerFile>(context, listen: false).setdataID(DataID);
  Navigator.push(context, MaterialPageRoute(builder: (context) => NextPageHome(DataID: DataID)));
},


String DataID = '';

  void setdataID(String pin) {
    if (DataID.isEmpty) {
      DataID = pin;
      notifyListeners();
    }
  }

Thanks, programmers.

Upvotes: 1

Views: 167

Answers (1)

roosi
roosi

Reputation: 128

At second time DataID is not anymore empty and therefore not set.

Upvotes: 1

Related Questions