'Call AppLocalizations’ method through regex

I’m trying to build an ItemList in flutter that would call the AppLocalizations.of(context) with the methods value01, value02, value03.

Example of arbFile:
{
  'value01': 'foo',
  'value02': 'bar',
  'value03': 'foobar',
  ...
}

Of course I would like this to be called through a for loop fashion without having to write all the code.

--

I thought about parsing the original arb file to find parameters matching the "value.." pattern, but I don't know how would I call the functions in the AppLocalizations then :/

Could (1) a reflectable or (2) extending the i10n-generating-code for AppLocalization work ?

Or is another method even more efficient ? Thx :)



Solution 1:[1]

I believe you can achieve your desired functionality by modifying .arb files. Instead of creating value01,value02 etc. You can just create one value and use some special character to separate it.

arb file

  "value": "value1:value2:value3",

Now you can get your values as list using .split() method

final values = AppLocalizations.of(context)!.value.split(':');

Now, using a for loop should be a problem :)

for (var i = 0; i < values.length; i++)
    Text(values[i])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wiktor