Created
April 18, 2024 16:45
-
-
Save fredgrott/73dc6066f47830e543700512687ec790 to your computer and use it in GitHub Desktop.
localization testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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