Home > Software design >  I have a stored List data and how can I localize it in flutter?
I have a stored List data and how can I localize it in flutter?

Time:10-01

I can translate the text inside the widget using AppLocalizations.of(context)!.translated and it work fine

However, when I want to localize a stored List<> data which will be used in listView Builder, I am not able to do so, since it need (context).

My question is how to localize a stored list data(outside widget) and pass to list view builder? Thanks for your help.

CodePudding user response:

I think you should do 2 things

In case if you have a list in another file, then it should be static like this:

class Presets {
  static var presetData = [];
}

after you loaded up your list, you can do these steps:

First, Create Widgets as children like this:

List<Widget> presetsLoadUp() {
  List<Widget> children = <Widget>[];
  for(i < yourList.length){
    children.add(Text(yourList[i]));
  }
  return children;
}

You can create your own unique widget inside the children.add method.

Secondly, Create the list:

...
child: ListView(
                    children: presetsLoadUp(),
                  ),

CodePudding user response:

If anyone has similar problem, please take it for reference. I just build another widget to solve this. What I do is : build another widget, then put the list data inside and return ListViewBuilder. Everything is same, just put your list data inside another widget can solve the problem

  • Related