@@ -11,6 +11,7 @@ import 'package:flutter/rendering.dart';
11
11
import 'package:flutter/services.dart' ;
12
12
13
13
import 'adaptive_text_selection_toolbar.dart' ;
14
+ import 'color_scheme.dart' ;
14
15
import 'colors.dart' ;
15
16
import 'debug.dart' ;
16
17
import 'desktop_text_selection.dart' ;
@@ -1191,6 +1192,22 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
1191
1192
}
1192
1193
// AutofillClient implementation end.
1193
1194
1195
+ Set <MaterialState > get _materialState {
1196
+ return < MaterialState > {
1197
+ if (! _isEnabled) MaterialState .disabled,
1198
+ if (_isHovering) MaterialState .hovered,
1199
+ if (_effectiveFocusNode.hasFocus) MaterialState .focused,
1200
+ if (_hasError) MaterialState .error,
1201
+ };
1202
+ }
1203
+
1204
+ TextStyle _getInputStyleForState (TextStyle style) {
1205
+ final ThemeData theme = Theme .of (context);
1206
+ final TextStyle stateStyle = MaterialStateProperty .resolveAs (theme.useMaterial3 ? _m3StateInputStyle (context)! : _m2StateInputStyle (context)! , _materialState);
1207
+ final TextStyle providedStyle = MaterialStateProperty .resolveAs (style, _materialState);
1208
+ return providedStyle.merge (stateStyle);
1209
+ }
1210
+
1194
1211
@override
1195
1212
Widget build (BuildContext context) {
1196
1213
assert (debugCheckHasMaterial (context));
@@ -1204,7 +1221,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
1204
1221
1205
1222
final ThemeData theme = Theme .of (context);
1206
1223
final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle .of (context);
1207
- final TextStyle style = (theme.useMaterial3 ? _m3InputStyle (context) : theme.textTheme.titleMedium! ).merge (widget.style);
1224
+ final TextStyle style = _getInputStyleForState (theme.useMaterial3 ? _m3InputStyle (context) : theme.textTheme.titleMedium! ).merge (widget.style);
1208
1225
final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.brightness;
1209
1226
final TextEditingController controller = _effectiveController;
1210
1227
final FocusNode focusNode = _effectiveFocusNode;
@@ -1402,12 +1419,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
1402
1419
}
1403
1420
final MouseCursor effectiveMouseCursor = MaterialStateProperty .resolveAs <MouseCursor >(
1404
1421
widget.mouseCursor ?? MaterialStateMouseCursor .textable,
1405
- < MaterialState > {
1406
- if (! _isEnabled) MaterialState .disabled,
1407
- if (_isHovering) MaterialState .hovered,
1408
- if (focusNode.hasFocus) MaterialState .focused,
1409
- if (_hasError) MaterialState .error,
1410
- },
1422
+ _materialState,
1411
1423
);
1412
1424
1413
1425
final int ? semanticsMaxValueLength;
@@ -1453,6 +1465,14 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
1453
1465
}
1454
1466
}
1455
1467
1468
+ TextStyle ? _m2StateInputStyle (BuildContext context) => MaterialStateTextStyle .resolveWith ((Set <MaterialState > states) {
1469
+ final ThemeData theme = Theme .of (context);
1470
+ if (states.contains (MaterialState .disabled)) {
1471
+ return TextStyle (color: theme.disabledColor);
1472
+ }
1473
+ return TextStyle (color: theme.textTheme.titleMedium? .color);
1474
+ });
1475
+
1456
1476
TextStyle _m2CounterErrorStyle (BuildContext context) =>
1457
1477
Theme .of (context).textTheme.bodySmall! .copyWith (color: Theme .of (context).colorScheme.error);
1458
1478
@@ -1465,6 +1485,13 @@ TextStyle _m2CounterErrorStyle(BuildContext context) =>
1465
1485
1466
1486
// Token database version: v0_162
1467
1487
1488
+ TextStyle ? _m3StateInputStyle (BuildContext context) => MaterialStateTextStyle .resolveWith ((Set <MaterialState > states) {
1489
+ if (states.contains (MaterialState .disabled)) {
1490
+ return TextStyle (color: Theme .of (context).textTheme.bodyLarge! .color? .withOpacity (0.38 ));
1491
+ }
1492
+ return TextStyle (color: Theme .of (context).textTheme.bodyLarge! .color);
1493
+ });
1494
+
1468
1495
TextStyle _m3InputStyle (BuildContext context) => Theme .of (context).textTheme.bodyLarge! ;
1469
1496
1470
1497
TextStyle _m3CounterErrorStyle (BuildContext context) =>
0 commit comments