Repository navigation
Open
flutter/packages
#13734Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
-
Use Material
TextFieldinside a custom theme, outside ofMaterialAppand any other Flutter-provided wrappers -
Set
TextField.decorationtonullas per documentation only having it non-null requires you to have aMaterialancestor:If decoration is non-null (which is the default), the text field requires one of its ancestors to be a Material widget.
Which is understood as having
decorationvalue to benullallows you not to haveMaterialancestors
Expected results
Everything works and no errors are happening
Actual results
The error:
No Material widget found.
TextField widgets require a Material widget ancestor within the closest LookupBoundary.
So either documentation has to be changed or the assertion has to take into account the decoration value
Code sample
Code sample
import 'package:flutter/cupertino.dart' show DefaultCupertinoLocalizations;
import 'package:flutter/material.dart' show DefaultMaterialLocalizations, TextField;
import 'package:flutter/widgets.dart';
void main() {
runApp(TextFieldExample());
}
class TextFieldExample extends StatelessWidget {
@override
Widget build(final BuildContext context) {
return Localizations(
locale: basicLocaleListResolution(null, [Locale('en', 'US')]),
delegates: [
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: TextField(decoration: null),
);
}
}
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
[✓] Flutter (Channel stable, 3.10.5, on macOS 12.6.3 21G419 darwin-x64, locale en-RU)
• Flutter version 3.10.5 on channel stable at /usr/local/Caskroom/flutter/3.10.5/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 796c8ef792 (3 months ago), 2023-06-13 15:51:02 -0700
• Engine revision 45f6e00911
• Dart version 3.0.5
• DevTools version 2.23.1
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/outring/Library/Android/sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.12.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] Connected device (3 available)
• iPhone 14 (mobile) • BB48C113-D88F-42CF-992A-A9ABDE3F5069 • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.6.3 21G419 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 116.0.5845.110
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: error messageError messages from the Flutter frameworkError messages from the Flutter frameworka: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 3.13Found to occur in 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14Found to occur in 3.14has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-text-inputOwned by Text Input teamOwned by Text Input teamtriaged-text-inputTriaged by Text Input teamTriaged by Text Input team
Activity
opxdelwin commentedon Aug 30, 2023
@outring Thanks for filing this issue, please provide a minimal reproducible code so that we can assist you better.
If possible, format
flutter doctoroutput as per markdown syntaxes.dam-ease commentedon Aug 30, 2023
Hi @outring. Please can you provide a minimal complete reproducible code sample that doesn’t include 3rd party plugins or complex production code?
Thank you
outring commentedon Aug 30, 2023
Hi @dam-ease. I've updated the code sample. According to the documentation it should work without errors but in debug mode it causes an assertion failure here:
flutter/packages/flutter/lib/src/material/text_field.dart
Line 1240 in 44a9b36
Either the assertion should take into account the value of
decorationor the documentation should be updated to avoid confusion about theMaterialancestors necessity. Thanks!dam-ease commentedon Aug 31, 2023
Hi @outring. Thanks for your response. Kindly check out the documentation https://docs.flutter.dev/release/breaking-changes/text-field-material-localizations on why you are getting this issue.
outring commentedon Aug 31, 2023
@dam-ease thanks. Please, check my code sample — it contains all the localizations (specifically it uses the method explained in the 3rd example of the page you have shared). The error I'm getting is:
As you can see it says nothing about localizations. If I add a
Materialancestor I won't get any errors at all. So the localizations have nothing to do with thisThe problem is that per documentation you can use use
TextFieldwithoutMaterialancestor if thedecorationisnull. Which is currently not true per implementationdam-ease commentedon Aug 31, 2023
Hi @outring. I think there might be a misinterpretation in the line you're referencing from the docs. From my understanding and from the error displayed,
TextFieldwidget requires aMaterialancestor as also shown https://docs.flutter.dev/release/breaking-changes/text-field-material-localizations.outring commentedon Aug 31, 2023
The documentation doesn't say that the
TextFieldrequiresMaterialancestor at all times. It only says that it's needed only when the decoration is not null:So if you believe the implementation is correct, then the documentation has to be fixed to avoid future confusion
https://docs.flutter.dev/release/breaking-changes/text-field-material-localizations specifically doesn't say anything about
Materialancestors, it only coversLocalizationsancestor or aMaterialAppancestor which hasLocalizationsbuilt-in. So I'm afraid it's not related to the issue I'm facing in any wayI would like to have a confirmation on the point 1, whether the documentation is wrong or implementation so I can prepare a PR for this issue, please
dam-ease commentedon Aug 31, 2023
Hi @outring. Thanks for your patience and detailed explanation. From what's here, it seems the
textfieldapplies the effectiveTextDecoration only when thetextDecorationis not null. But then, if you don't want to use the Material, you could look into using EditableText directly so that you can customize it.5 remaining items
justinmc commentedon Aug 31, 2023
Here's where that assertion was added for the record: #16147
I wonder if someone uses a TextField inside of CupertinoApp, does this assertion get triggered?
If someone (CC @Renzo-Olivares ) can put together a simple app that doesn't have a Material where TextField seems to work with the assertion disabled, then let's remove it. Otherwise, if the TextField seems to break somehow, then we should remove the line in the docs.
Renzo-Olivares commentedon Sep 1, 2023
I came up with a few samples to observe this behavior.
Some observations:
CupertinoTextFieldwill load without any localizations provided toWidgetsApp, but will crash when doing something like opening the context menu because of those missing localizations. We should probably assert and document this inCupertinoTextField.CupertinoTextFieldcurrently "works" on allAppvariants without any changes.TextFieldlets us useTextFieldinCupertinoAppandWidgetsApp.decorationtoTextFieldwhen used underWidgetsAppdoes not require it to have a material ancestor.Looks like
CupertinoTextFieldandTextFieldshould be able to be used in anyAppcontext given that the proper localizations are defined. I'll work on verifying this further and making this change.flutter-triage-bot commentedon Jan 19, 2024
This issue is assigned to @Renzo-Olivares but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
flutter-triage-bot commentedon Apr 7, 2024
This issue was assigned to @Renzo-Olivares but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.