Created
April 18, 2024 16:39
-
-
Save fredgrott/087cd8330491a0963185a1611c9646cf to your computer and use it in GitHub Desktop.
app globals
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'; | |
final navigatorKey = GlobalKey<NavigatorState>(); | |
// navigatorKey is parameter which goes in the MaterialApp | |
// navigagtorKey parameter slot. Then we can do | |
// LocalizationClassSingeton.of(appContect)!.loremIpsum | |
// in places outside the widgets such as the Models. | |
// That also means that to test the models we use a MaterialApp | |
// wrapper in test to pumpwidget with child widget being | |
// anything to insert the navigatorKey parameter and | |
// localizations as then after the pump of widgets we | |
// have the appContext global filled and then can | |
// test the model stuff that has localizations. | |
// | |
BuildContext appContext = navigatorKey.currentState!.context; | |
// if using routes u need something different | |
// scaffoldMessengerKey is used in MaterialApp.routes | |
final scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>(); | |
// Then | |
BuildContext routeAppContext = scaffoldMessengerKey.currentContext!; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment