Skip to content

Instantly share code, notes, and snippets.

@fredgrott
Created April 18, 2024 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredgrott/73dc6066f47830e543700512687ec790 to your computer and use it in GitHub Desktop.
Save fredgrott/73dc6066f47830e543700512687ec790 to your computer and use it in GitHub Desktop.
localization testing
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:localization_wo_context/generated/l10n.dart';
import 'package:localization_wo_context/generated/l10n.dart';
import 'package:localization_wo_context/generated/l10n.dart';
late final appNavKey;
void main() {
setUpAll(() {
appNavKey = GlobalKey<NavigatorState>();
});
testWidgets('model test', (WidgetTester tester) async {
child:
MaterialApp(
navigatorKey: appNavKey,
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en'),
// Locale('de'),
],
home: Container());
// builds on the hook in the MaterialApp wrapper parameter
// navigatorKey so that we can grab the global ref once
// the MaterialApp wrapper is test pumped
BuildContext testAppContext = appNavKey.currentState!.context;
// So now we can test the Model that has localizations
//by using
// LocalizationClassSingeton.of(testAppppContect)!.loremIpsum
//
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment