Skip to content

Commit

Permalink
Merge pull request #452 from stryder-dev/Fix-450-casing-matching-mate…
Browse files Browse the repository at this point in the history
…rial

Add setting to control the casing of material3 text
  • Loading branch information
aqwert authored Feb 15, 2024
2 parents 054f5b2 + 12b2dc5 commit 1ed6983
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -349,7 +349,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -398,7 +398,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
7 changes: 7 additions & 0 deletions lib/src/platform_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,19 @@ class PlatformSettingsData {
/// Set to true (wrapped) by default which could be a breaking change. If it is then set this value to false
final bool wrapCupertinoAppBarMiddleWithMediaQuery;

/// With Material3 spec defining buttons text as being non ALL CAPS (see https://m3.material.io/components/buttons/overview#388f6096-c34d-4a22-8b1f-11ad69963f7c)
/// 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
/// If this is set to false then it will default to previous behavour of ALL CAPS.
/// Going forward [PlatformText] will likely be removed when the material3 property on ThemeData is removed and all material widgets will assume material3 style.
final bool matchMaterialCaseForPlatformText;

PlatformSettingsData({
this.iosUsesMaterialWidgets = false,
this.iosUseZeroPaddingForAppbarPlatformIcon = false,
this.legacyIosUsesMaterialWidgets = false,
this.platformStyle = const PlatformStyleData(),
this.wrapCupertinoAppBarMiddleWithMediaQuery = true,
this.matchMaterialCaseForPlatformText = true,
});
}

Expand Down
15 changes: 15 additions & 0 deletions lib/src/platform_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@

import 'dart:ui' as ui show TextHeightBehavior;

import 'package:flutter/material.dart' show Theme;
import 'package:flutter/widgets.dart';

import 'platform.dart' show isMaterial;
import 'platform_provider.dart' show PlatformProvider;
import 'platform_theme.dart' show PlatformTheme;

String formatData(BuildContext context, String data) {
if (isMaterial(context)) {
final providerState = PlatformProvider.of(context);
final matchMaterialCaseForPlatformText =
providerState?.settings.matchMaterialCaseForPlatformText ?? true;

final m3 = PlatformTheme.of(context)?.isMaterial3 ??
Theme.of(context).useMaterial3;

// If it material3 and we want to match the casing as defined for material3 then do not return ALL CAPS
if (m3 && matchMaterialCaseForPlatformText) {
return data;
}

return data.toUpperCase();
}
return data;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/platform_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class _PlatformThemeState extends State<PlatformTheme>
applyToBothDarkAndLightTheme: applyToBothDarkAndLightTheme);
}

bool get isMaterial3 =>
(isDark ? _materialDarkTheme : _materialLightTheme)?.useMaterial3 ??
false;

void _setMaterialThemeType({
required bool? useMaterial3,
bool applyToBothDarkAndLightTheme = false,
Expand Down Expand Up @@ -167,6 +171,7 @@ class PlatformThemeState {
set themeMode(ThemeMode? themeMode) => _parent.themeMode = themeMode;

bool get isDark => _parent.isDark;
bool get isMaterial3 => _parent.isMaterial3;

CupertinoThemeData? get cupertinoLightTheme => _parent._cupertinoLightTheme;
CupertinoThemeData? get cupertinoDarkTheme => _parent._cupertinoDarkTheme;
Expand Down

0 comments on commit 1ed6983

Please sign in to comment.