-3

I am relatively new to flutter. I have been dealing with flutter code base written by previous developer. So whenever i navigate to history page in the app it throws exception stating type 'String' is not a subtype of type 'Timestamp'. I have no clue what's wrong with the code. any help would be apprecated. I have been stuck for a couple of days now. type of createddate is string.enter image description here

            docs.documents.forEach((i) {
              Timestamp date = i.data['createddate'];
              DateTime dates = date.toDate();
              DateFormat inputFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
              DateTime parsedDate = inputFormat.parse(dates.toString());
              print(approvestatus + 'dada');
              if ((filterFrom
                          .subtract(Duration(hours: 24))
                          .isBefore(parsedDate) &&
                      filterTo
                          .add(Duration(hours: 24))
                          .isAfter(parsedDate)) &&
                  (i.data['shopkeeperid'].toString() == uid) &&
                  (i.data['productid']
                          .toString()
                          .toLowerCase()
                          .contains(searchvalue.toString()) ||
                      i.data['productname']
                          .toString()
                          .toLowerCase()
                          .contains(searchvalue.toString()) ||
                      i.data['productbrand']
                          .toString()
                          .toLowerCase()
                          .contains(searchvalue.toString()) ||
                      i.data['availablequantity']
                          .toString()
                          .toLowerCase()
                          .contains(searchvalue.toString()) ||
                      searchvalue == "")) {
                childrenWidgets.add(productView(i, context));
              }
            });
Aniket
  • 982
  • 1
  • 11
  • 16

1 Answers1

1

there is a timeStamp variable in your code and you are trying to pass a string to it. I cannot clearly understand this code. but you got to put debug point on every line. for example first line

      Timestamp date = i.data['createddate'];

if the data['createddate']; is a string it can make this error put the debug point and you can see each value and you will also be able to understand from which point your code won't move forward

Ardeshir ojan
  • 1,914
  • 1
  • 13
  • 36
  • thanks for the reply. i did put a debugger. after this line Timestamp date = i.data['createddate']; it throws the exception . type of createddate is string. and it is been assigned to type of timestamp. – Aniket Oct 06 '21 at 13:22
  • 1
    @Aniket so from your code i think you should change the String in data to timeStamp this will help https://stackoverflow.com/questions/50632217/dart-flutter-converting-timestamp or you may just want to change that timeStamp to a String – Ardeshir ojan Oct 06 '21 at 13:26
  • Thanks mate that link was super usefull. Really appreciate it. – Aniket Oct 06 '21 at 13:36