Check if custom data type attribute is null in custom action code

Custom Code

Hi all,

I've been trying to run a snippet of code with no success. My problem is that I can't seem to perform a null check on a custom data type variable with an attribute that can be set to null. I have these 2 custom data types:

Parent {
  id: Int,
  child?: Child
}

Child {
  id: Int
}

and when running this snippet in a custom action...

for (ParentStruct parent in listOfParents) {
  print(parent);
  if (parent.child != null) {
    print("IS NOT NULL!");
    print(parent.child);
  }
}

I always get:

flutter: ParentStruct({id: 123, child: {id: 321}})
flutter: IS NOT NULL!
flutter: ChildStruct({id: 321})
flutter: ParentStruct({id: 456})
flutter: IS NOT NULL!
flutter: ChildStruct({})

even when the second element has parent.child set to null.

Does anybody know why I'd be getting an empty data structure as a result? And how to correctly perform a null check?

Thanks!

What have you tried so far?

.

Did you check FlutterFlow's Documentation for this topic?
No
1
2 replies