locale static method
Currently defined locale.
Implementation
static Locale? locale(BuildContext context) {
if (!_isEnabled(context)) {
return null;
}
final store = Provider.of<DevicePreviewStore>(context);
return store.state.maybeMap(
initialized: (state) {
final splits = state.data.locale.split('_');
final languageCode = splits[0];
String? scriptCode, countryCode;
if (splits.length > 2) {
scriptCode = splits[1];
countryCode = splits[2];
} else if (splits.length > 1) {
countryCode = splits[1];
}
return Locale.fromSubtags(
languageCode: languageCode,
scriptCode: scriptCode,
countryCode: countryCode,
);
},
orElse: () => WidgetsBinding.instance!.window.locale,
);
}