Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Created July 25, 2022 04:29
Embed
What would you like to do?
xtension BuildContextX on BuildContext {
/// contextOrNull?.navigator().maybePop();
NavigatorState navigator({
bool rootNavigator = false,
}) => Navigator.of(this, rootNavigator: rootNavigator);
NavigatorState? navigatorOrNull({
bool rootNavigator = false,
}) => tryOrNull<NavigatorState>(() => navigator(rootNavigator: rootNavigator));
/// contextOrNull?.mediaQuery().size;
MediaQueryData mediaQuery() => MediaQuery.of(this);
MediaQueryData? mediaQueryOrNull() => tryOrNull<MediaQueryData>(() => MediaQuery.of(this));
State<StatefulWidget>? get stateOrNull => this is StatefulElement
? tryOrNull<State<StatefulWidget>>(() => (this as StatefulElement).state)
: null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment