I want to translate my app to different languages it works fine but listview buidler is translating for only one time when exit app and open.again translate for only one time and i want to translate again i have to exit app then list view builder will translate..
Model class Whole app is translated perfectly Except List View Builder `
class Exercise1Model {
final String name;
final String subtitle;
Exercise1Model(
{
required this.subtitle,
required this.name,
});
static List<Exercise1Model> list = [
Exercise1Model(
name: "warm_up".tr,
subtitle: 'warming_sub'.tr,
),
]
}
List View Builder
`
ListView.builder(
itemCount: ExerciseModel.list.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
return Container(
height: 200,
padding: const EdgeInsets.all(25),
child: Stack(
children: [
child: Text(
ExerciseModel.list[index].name,
style: const TextStyle(
fontSize: 20,
color: Colors.white,
wordSpacing: 10,
fontWeight: FontWeight.bold),
)),
),
),
),
],
),
),
);
}),
`
`
waiting...............
CodePudding user response:
Don't use .tr
method in your model:
static List<Exercise1Model> list = [
Exercise1Model(
name: "warm_up",
subtitle: 'warming_sub',
),
]
But use it in your UI(ListView):
ListView.builder(
itemCount: ExerciseModel.list.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
return Container(
height: 200,
padding: const EdgeInsets.all(25),
child: Stack(
children: [
child: Text(
ExerciseModel.list[index].name.tr,
style: const TextStyle(
fontSize: 20,
color: Colors.white,
wordSpacing: 10,
fontWeight: FontWeight.bold),
)),
),
),
),
],
),
),
);
}),