maybeOf static method
- BuildContext context
The data from the closest instance of this class that encloses the given context, if any.
Use this function if you want to allow situations where no SegmentedButtonTheme is in scope. Prefer using SegmentedButtonTheme.of in situations where a SegmentedButtonThemeData is expected to be non-null.
If there is no SegmentedButtonTheme in scope, then this function will return null.
Typical usage is as follows:
SegmentedButtonThemeData? theme = SegmentedButtonTheme.maybeOf(context);
if (theme == null) {
// Do something else instead.
}
See also:
- of, which will return ThemeData.segmentedButtonTheme if it doesn't find a SegmentedButtonTheme ancestor, instead of returning null.
Implementation
static SegmentedButtonThemeData? maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<SegmentedButtonTheme>()?.data;
}