l10n 在 initState 之前调用
l10n called before initState
发现有关 Flutter 处理 l10n 和 void initState()
的问题。
l10n 很好用 pm 它自己的。完成工作,但我发现了一个我认为应该标记的特定场景。
我将通过显示 example 来更具体。
以下代码取自 gallery app:
...
@override
void initState() {
super.initState();
_navigationViews = <NavigationIconView>[
NavigationIconView(
icon: const Icon(Icons.access_alarm),
title: 'Alarm',
color: Colors.deepPurple,
vsync: this,
),
NavigationIconView(
activeIcon: CustomIcon(),
icon: CustomInactiveIcon(),
title: 'Box',
color: Colors.deepOrange,
vsync: this,
),
NavigationIconView(
activeIcon: const Icon(Icons.cloud),
icon: const Icon(Icons.cloud_queue),
title: 'Cloud',
color: Colors.teal,
vsync: this,
),
NavigationIconView(
activeIcon: const Icon(Icons.favorite),
icon: const Icon(Icons.favorite_border),
title: 'Favorites',
color: Colors.indigo,
vsync: this,
),
NavigationIconView(
icon: const Icon(Icons.event_available),
title: 'Event',
color: Colors.pink,
vsync: this,
)
];
_navigationViews[_currentIndex].controller.value = 1.0;
}
...
我正在努力使用 initState
函数中的本地化。
您可以(某种程度上)通过使用用户的语言代码并手动翻译它而不是使用 locales.dart
文件来绕过它,同样我认为这是一个应该解决的持续问题。
注意:在我写这篇文章时 post 我想到了一个想法,通过调用前一个 class 中的 l10n 字符串来绕过这个问题 - 测试这个理论。
所以我最终得到了 "passing down" 以前 class 的值。这个 "problem" 可以通过使用 ether InheritedWidget 或 "passing down values".
来解决
发现有关 Flutter 处理 l10n 和 void initState()
的问题。
l10n 很好用 pm 它自己的。完成工作,但我发现了一个我认为应该标记的特定场景。 我将通过显示 example 来更具体。 以下代码取自 gallery app:
...
@override
void initState() {
super.initState();
_navigationViews = <NavigationIconView>[
NavigationIconView(
icon: const Icon(Icons.access_alarm),
title: 'Alarm',
color: Colors.deepPurple,
vsync: this,
),
NavigationIconView(
activeIcon: CustomIcon(),
icon: CustomInactiveIcon(),
title: 'Box',
color: Colors.deepOrange,
vsync: this,
),
NavigationIconView(
activeIcon: const Icon(Icons.cloud),
icon: const Icon(Icons.cloud_queue),
title: 'Cloud',
color: Colors.teal,
vsync: this,
),
NavigationIconView(
activeIcon: const Icon(Icons.favorite),
icon: const Icon(Icons.favorite_border),
title: 'Favorites',
color: Colors.indigo,
vsync: this,
),
NavigationIconView(
icon: const Icon(Icons.event_available),
title: 'Event',
color: Colors.pink,
vsync: this,
)
];
_navigationViews[_currentIndex].controller.value = 1.0;
}
...
我正在努力使用 initState
函数中的本地化。
您可以(某种程度上)通过使用用户的语言代码并手动翻译它而不是使用 locales.dart
文件来绕过它,同样我认为这是一个应该解决的持续问题。
注意:在我写这篇文章时 post 我想到了一个想法,通过调用前一个 class 中的 l10n 字符串来绕过这个问题 - 测试这个理论。
所以我最终得到了 "passing down" 以前 class 的值。这个 "problem" 可以通过使用 ether InheritedWidget 或 "passing down values".
来解决