[ermine] Ensure app starts with the correct initial locale.
TEST: Updated app_widget_test.
Change-Id: I3bfb62b8e224eb40c6eb8262189a9478e2757358
diff --git a/session_shells/ermine/shell/lib/main.dart b/session_shells/ermine/shell/lib/main.dart
index 44c61d1..796f429 100644
--- a/session_shells/ermine/shell/lib/main.dart
+++ b/session_shells/ermine/shell/lib/main.dart
@@ -13,6 +13,8 @@
setupLogger(name: 'ermine');
final model = AppModel();
+ await model.init();
+
final app = App(model: model);
runApp(app);
diff --git a/session_shells/ermine/shell/lib/src/models/app_model.dart b/session_shells/ermine/shell/lib/src/models/app_model.dart
index 49d11c9..4612531 100644
--- a/session_shells/ermine/shell/lib/src/models/app_model.dart
+++ b/session_shells/ermine/shell/lib/src/models/app_model.dart
@@ -57,6 +57,7 @@
ValueNotifier<bool> peekNotifier = ValueNotifier(false);
ValueNotifier<bool> recentsVisibility = ValueNotifier(false);
KeyboardShortcuts _keyboardShortcuts;
+ Locale _initialLocale;
StatusModel status;
TopbarModel topbarModel;
String keyboardShortcuts = 'Help Me!';
@@ -94,12 +95,20 @@
status = StatusModel.fromStartupContext(_startupContext, onLogout);
}
+ /// Performs initialization before the [App] widget are created.
+ Future<void> init() async {
+ /// Read the initial [Locale].
+ _initialLocale = await localeStream.asBroadcastStream().first;
+ }
+
SuggestionService get suggestions => SuggestionService(_suggestionsService);
modular.PuppetMaster get puppetMaster => _puppetMaster;
Stream<Locale> get localeStream => LocaleSource(_intl).stream();
+ Locale get initialLocale => _initialLocale;
+
bool get isFullscreen => clustersModel.fullscreenStory != null;
bool get hasStories => clustersModel.hasStories;
diff --git a/session_shells/ermine/shell/lib/src/widgets/app.dart b/session_shells/ermine/shell/lib/src/widgets/app.dart
index 6001fcc..a462f46 100644
--- a/session_shells/ermine/shell/lib/src/widgets/app.dart
+++ b/session_shells/ermine/shell/lib/src/widgets/app.dart
@@ -28,11 +28,9 @@
Widget build(BuildContext context) {
return StreamBuilder<Locale>(
stream: model.localeStream,
+ initialData: model.initialLocale,
builder: (context, snapshot) {
final locale = snapshot.data;
- if (locale == null) {
- return Offstage();
- }
// Needed to set the locale for anything that depends on the Intl
// package.
Intl.defaultLocale = locale.toString();
diff --git a/session_shells/ermine/shell/test/app_widget_test.dart b/session_shells/ermine/shell/test/app_widget_test.dart
index f2c6f97..af50658 100644
--- a/session_shells/ermine/shell/test/app_widget_test.dart
+++ b/session_shells/ermine/shell/test/app_widget_test.dart
@@ -19,16 +19,12 @@
testWidgets('Test locale change', (tester) async {
final swissFrench = Locale('fr', 'CH');
+
final model = MockAppModel();
- when(model.localeStream)
- .thenAnswer((_) => Stream<Locale>.value(swissFrench));
+ when(model.initialLocale).thenReturn(swissFrench);
when(model.overviewVisibility).thenReturn(ValueNotifier<bool>(false));
final app = App(model: model);
-
- await tester.pumpWidget(app);
- expect(Intl.defaultLocale, null);
-
await tester.pumpWidget(app);
expect(Intl.defaultLocale, swissFrench.toString());
});