Skip to content

Commit 1ed6983

Browse files
authored
Merge pull request #452 from stryder-dev/Fix-450-casing-matching-material
Add setting to control the casing of material3 text
2 parents 054f5b2 + 12b2dc5 commit 1ed6983

5 files changed

Lines changed: 31 additions & 4 deletions

File tree

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>11.0</string>
24+
<string>12.0</string>
2525
</dict>
2626
</plist>

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
276276
GCC_WARN_UNUSED_FUNCTION = YES;
277277
GCC_WARN_UNUSED_VARIABLE = YES;
278-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
278+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
279279
MTL_ENABLE_DEBUG_INFO = NO;
280280
SDKROOT = iphoneos;
281281
SUPPORTED_PLATFORMS = iphoneos;
@@ -349,7 +349,7 @@
349349
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
350350
GCC_WARN_UNUSED_FUNCTION = YES;
351351
GCC_WARN_UNUSED_VARIABLE = YES;
352-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
352+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
353353
MTL_ENABLE_DEBUG_INFO = YES;
354354
ONLY_ACTIVE_ARCH = YES;
355355
SDKROOT = iphoneos;
@@ -398,7 +398,7 @@
398398
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
399399
GCC_WARN_UNUSED_FUNCTION = YES;
400400
GCC_WARN_UNUSED_VARIABLE = YES;
401-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
401+
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
402402
MTL_ENABLE_DEBUG_INFO = NO;
403403
SDKROOT = iphoneos;
404404
SUPPORTED_PLATFORMS = iphoneos;

lib/src/platform_provider.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,19 @@ class PlatformSettingsData {
152152
/// Set to true (wrapped) by default which could be a breaking change. If it is then set this value to false
153153
final bool wrapCupertinoAppBarMiddleWithMediaQuery;
154154

155+
/// With Material3 spec defining buttons text as being non ALL CAPS (see https://m3.material.io/components/buttons/overview#388f6096-c34d-4a22-8b1f-11ad69963f7c)
156+
/// If this is set to true then using [PlatformText] with material3 style will default to sentence case and not ALL CAPS. Material 2 will continue to be ALL CAPS
157+
/// If this is set to false then it will default to previous behavour of ALL CAPS.
158+
/// Going forward [PlatformText] will likely be removed when the material3 property on ThemeData is removed and all material widgets will assume material3 style.
159+
final bool matchMaterialCaseForPlatformText;
160+
155161
PlatformSettingsData({
156162
this.iosUsesMaterialWidgets = false,
157163
this.iosUseZeroPaddingForAppbarPlatformIcon = false,
158164
this.legacyIosUsesMaterialWidgets = false,
159165
this.platformStyle = const PlatformStyleData(),
160166
this.wrapCupertinoAppBarMiddleWithMediaQuery = true,
167+
this.matchMaterialCaseForPlatformText = true,
161168
});
162169
}
163170

lib/src/platform_text.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,27 @@
66

77
import 'dart:ui' as ui show TextHeightBehavior;
88

9+
import 'package:flutter/material.dart' show Theme;
910
import 'package:flutter/widgets.dart';
1011

1112
import 'platform.dart' show isMaterial;
13+
import 'platform_provider.dart' show PlatformProvider;
14+
import 'platform_theme.dart' show PlatformTheme;
1215

1316
String formatData(BuildContext context, String data) {
1417
if (isMaterial(context)) {
18+
final providerState = PlatformProvider.of(context);
19+
final matchMaterialCaseForPlatformText =
20+
providerState?.settings.matchMaterialCaseForPlatformText ?? true;
21+
22+
final m3 = PlatformTheme.of(context)?.isMaterial3 ??
23+
Theme.of(context).useMaterial3;
24+
25+
// If it material3 and we want to match the casing as defined for material3 then do not return ALL CAPS
26+
if (m3 && matchMaterialCaseForPlatformText) {
27+
return data;
28+
}
29+
1530
return data.toUpperCase();
1631
}
1732
return data;

lib/src/platform_theme.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class _PlatformThemeState extends State<PlatformTheme>
118118
applyToBothDarkAndLightTheme: applyToBothDarkAndLightTheme);
119119
}
120120

121+
bool get isMaterial3 =>
122+
(isDark ? _materialDarkTheme : _materialLightTheme)?.useMaterial3 ??
123+
false;
124+
121125
void _setMaterialThemeType({
122126
required bool? useMaterial3,
123127
bool applyToBothDarkAndLightTheme = false,
@@ -167,6 +171,7 @@ class PlatformThemeState {
167171
set themeMode(ThemeMode? themeMode) => _parent.themeMode = themeMode;
168172

169173
bool get isDark => _parent.isDark;
174+
bool get isMaterial3 => _parent.isMaterial3;
170175

171176
CupertinoThemeData? get cupertinoLightTheme => _parent._cupertinoLightTheme;
172177
CupertinoThemeData? get cupertinoDarkTheme => _parent._cupertinoDarkTheme;

0 commit comments

Comments
 (0)