The flat list of 6 languages plus 'system' dominated Settings. Replace it with a single tile showing the current language, opening a bottom-sheet picker (all languages + 'System language'). Resolve LocaleStore defensively so the screen renders in DI-less widget tests.
76 lines
3.1 KiB
Dart
76 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:tane/app.dart';
|
|
import 'package:tane/i18n/strings.g.dart';
|
|
import 'package:tane/services/locale_store.dart';
|
|
import 'package:tane/ui/settings_screen.dart';
|
|
|
|
import '../support/test_support.dart';
|
|
|
|
/// Asturian (`ast`) is a first-class language, but Flutter ships no
|
|
/// Material/Cupertino localizations for it. The app carries the honest `ast`
|
|
/// locale for its own strings and borrows Spanish for the framework chrome
|
|
/// (see [materialLocaleFor]). These tests pin both halves of that contract.
|
|
void main() {
|
|
testWidgets('picking Asturian switches app text to Asturian, keeps Material '
|
|
'chrome resolvable in Spanish, and persists the choice', (tester) async {
|
|
LocaleSettings.setLocaleSync(AppLocale.en);
|
|
final store = LocaleStore(InMemorySecretStore());
|
|
late Locale materialLocale;
|
|
|
|
await tester.pumpWidget(
|
|
TranslationProvider(
|
|
child: Builder(
|
|
builder: (context) {
|
|
final appLocale = TranslationProvider.of(context).flutterLocale;
|
|
return MaterialApp(
|
|
// Mirrors app.dart: the framework localizations follow the mapped
|
|
// locale, the app's own strings follow slang.
|
|
locale: materialLocaleFor(appLocale),
|
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
|
localizationsDelegates: const [
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
home: Builder(
|
|
builder: (context) {
|
|
// Resolving these must never throw for the Asturian locale.
|
|
materialLocale = Localizations.localeOf(context);
|
|
MaterialLocalizations.of(context);
|
|
return SettingsScreen(localeStore: store);
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
|
|
// Starts in English.
|
|
expect(find.text('Language'), findsOneWidget);
|
|
expect(materialLocale.languageCode, 'en');
|
|
|
|
// Open the language picker, then choose Asturian.
|
|
await tester.tap(find.byKey(const Key('settings.language')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Asturianu'));
|
|
await tester.pumpAndSettle();
|
|
|
|
// App strings are now Asturian…
|
|
expect(find.text('Llingua'), findsOneWidget);
|
|
// …the framework chrome fell back to Spanish (not the unsupported `ast`)…
|
|
expect(materialLocale.languageCode, 'es');
|
|
// …and the choice was remembered for next launch.
|
|
expect(await store.saved(), AppLocale.ast);
|
|
});
|
|
|
|
test('materialLocaleFor maps Asturian to Spanish and passes others through',
|
|
() {
|
|
expect(materialLocaleFor(const Locale('ast')), const Locale('es'));
|
|
expect(materialLocaleFor(const Locale('es')), const Locale('es'));
|
|
expect(materialLocaleFor(const Locale('en')), const Locale('en'));
|
|
expect(materialLocaleFor(const Locale('pt')), const Locale('pt'));
|
|
});
|
|
}
|