Unverified Commit 41940c93 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Suggest predicate-based formatter in [FilteringTextInputFormatter] docs for...

Suggest predicate-based formatter in [FilteringTextInputFormatter] docs for whole string matching (#107848)
parent 25526f1b
...@@ -751,8 +751,8 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -751,8 +751,8 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
// Steps to convert `rect` (from a RenderBox coordinate system) to its // Steps to convert `rect` (from a RenderBox coordinate system) to its
// scroll offset within this viewport (not in the exact order): // scroll offset within this viewport (not in the exact order):
// //
// 1. Pick the outmost RenderBox (between which, and the viewport, there is // 1. Pick the outermost RenderBox (between which, and the viewport, there
// nothing but RenderSlivers) as an intermediate reference frame // is nothing but RenderSlivers) as an intermediate reference frame
// (the `pivot`), convert `rect` to that coordinate space. // (the `pivot`), convert `rect` to that coordinate space.
// //
// 2. Convert `rect` from the `pivot` coordinate space to its sliver // 2. Convert `rect` from the `pivot` coordinate space to its sliver
......
...@@ -212,19 +212,31 @@ class _TextEditingValueAccumulator { ...@@ -212,19 +212,31 @@ class _TextEditingValueAccumulator {
} }
} }
/// A [TextInputFormatter] that prevents the insertion of characters /// A [TextInputFormatter] that prevents the insertion of characters matching
/// matching (or not matching) a particular pattern. /// (or not matching) a particular pattern, by replacing the characters with the
/// given [replacementString].
/// ///
/// Instances of filtered characters found in the new [TextEditingValue]s /// Instances of filtered characters found in the new [TextEditingValue]s
/// will be replaced with the [replacementString] which defaults to the empty /// will be replaced by the [replacementString] which defaults to the empty
/// string. /// string, and the current [TextEditingValue.selection] and
/// [TextEditingValue.composing] region will be adjusted to account for the
/// replacement.
/// ///
/// Since this formatter only removes characters from the text, it attempts to /// This formatter is typically used to match potentially recurring [Pattern]s
/// preserve the existing [TextEditingValue.selection] to values it would now /// in the new [TextEditingValue]. It never completely rejects the new
/// fall at with the removed characters. /// [TextEditingValue] and falls back to the current [TextEditingValue] when the
/// given [filterPattern] fails to match. Consider using a different
/// [TextInputFormatter] such as:
/// ```dart
/// TextInputFormatter.withFunction((oldValue, newValue) => regExp.hasMatch(newValue.text) ? newValue : oldValue)
/// ```
/// for accepting/rejecting new input based on a predicate on the full string.
/// As an example, [FilteringTextInputFormatter] typically shouldn't be used
/// with [RegExp]s that contain positional matchers (`^` or `$`) since these
/// patterns are usually meant for matching the whole string.
class FilteringTextInputFormatter extends TextInputFormatter { class FilteringTextInputFormatter extends TextInputFormatter {
/// Creates a formatter that prevents the insertion of characters /// Creates a formatter that replaces banned patterns with the given
/// based on a filter pattern. /// [replacementString].
/// ///
/// If [allow] is true, then the filter pattern is an allow list, /// If [allow] is true, then the filter pattern is an allow list,
/// and characters must match the pattern to be accepted. See also /// and characters must match the pattern to be accepted. See also
......
...@@ -299,7 +299,7 @@ class SlottedRenderObjectElement<S> extends RenderObjectElement { ...@@ -299,7 +299,7 @@ class SlottedRenderObjectElement<S> extends RenderObjectElement {
throw FlutterError.fromParts(<DiagnosticsNode>[ throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('Multiple widgets used the same key in ${widget.runtimeType}.'), ErrorSummary('Multiple widgets used the same key in ${widget.runtimeType}.'),
ErrorDescription( ErrorDescription(
'The key ${duplicateKey.key} was used by multiple widgets. The parents of those widgets were:\n' 'The key ${duplicateKey.key} was used by multiple widgets. The offending widgets were:\n'
), ),
for (final Element element in duplicateKey.value) ErrorDescription(' - $element\n'), for (final Element element in duplicateKey.value) ErrorDescription(' - $element\n'),
ErrorDescription( ErrorDescription(
......
...@@ -197,7 +197,7 @@ void main() { ...@@ -197,7 +197,7 @@ void main() {
expect((tester.takeException() as FlutterError).toString(), equalsIgnoringHashCodes( expect((tester.takeException() as FlutterError).toString(), equalsIgnoringHashCodes(
'Multiple widgets used the same key in _Diagonal.\n' 'Multiple widgets used the same key in _Diagonal.\n'
"The key [<'widget 1'>] was used by multiple widgets. The parents of those widgets were:\n" "The key [<'widget 1'>] was used by multiple widgets. The offending widgets were:\n"
" - SizedBox-[<'widget 1'>](width: 50.0, height: 50.0, renderObject: RenderConstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT)\n" " - SizedBox-[<'widget 1'>](width: 50.0, height: 50.0, renderObject: RenderConstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT)\n"
" - SizedBox-[<'widget 1'>](width: 10.0, height: 10.0, renderObject: RenderConstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT)\n" " - SizedBox-[<'widget 1'>](width: 10.0, height: 10.0, renderObject: RenderConstrainedBox#00000 NEEDS-LAYOUT NEEDS-PAINT)\n"
" - SizedBox-[<'widget 1'>](width: 100.0, height: 100.0, renderObject: RenderConstrainedBox#a4685 NEEDS-LAYOUT NEEDS-PAINT)\n" " - SizedBox-[<'widget 1'>](width: 100.0, height: 100.0, renderObject: RenderConstrainedBox#a4685 NEEDS-LAYOUT NEEDS-PAINT)\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment