How can I access the "fields" and "values" of a Custom Data Type within a Custom Action?

Custom Code
Resolved

Hello. I want to access the "fields" and "values" of a Custom Data Type within a Custom Action using an argument.

In the Custom Action, I am fetching data from Firebase. The data from Firebase includes Map data, so I am utilizing a Custom Data Type (named "Translation") for it.
Example: TranslationStruct({en: AAA, ja: BBB})

I'd like to return the value if the variable matches the field, and return "OTHER" if the variable doesn't have the field.

What have you tried so far?

In this case, when I tried the following code, an error occurred:

Pattern1

Future<NewsDataTypeStruct> newsCustomAction(
  List<NewsRecord> newsCollection,
  String currentLang,
) async {
  // Add your function code here!

    String title;
    if (newsRecord.title != null && newsRecord.title[currentLang] != null) {
      title = newsRecord.title[currentLang];
    } else {
      title = "OTHER";
    }

    NewsDataTypeStruct newsData = NewsDataTypeStruct(
      title: title,
    );
  return newsData;
}

Error:

The operator '[]' isn't defined for the type 'TranslationStruct'. Try defining the operator '[]'.

Pattern2

newsRecord.title[currentLang] -> newsRecord.title.currentLang 

Error:

The getter 'currentLang' isn't defined for the type 'TranslationStruct'. Try importing the library that defines 'currentLang', correcting the name to the name of an existing getter, or defining a getter or field named 

Pattern3

newsRecord.title[currentLang] -> newsRecord.title.[currentLang]

Error:

Expected an identifier.

The getter '[' isn't defined for the type 'TranslationStruct'. Try importing the library that defines '[', correcting the name to the name of an existing getter, or defining a getter or field named '['.

Do you have any ideas to solve this?

Thank you!

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