Milad-Akarie / form_field_validator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`PatternValidator`'s pattern param should be type of `String` rather than `Pattern`, which is ambiguous

timnew opened this issue · comments

Describe the bug

PatternValidator(RegExp(r".*")) is a legal based on the method signature, but it doesn't work as expected.
PatternValidator(RegExp(r".*")).isMatch("text") returns false.

To Reproduce
PatternValidator(RegExp(r".*")) is expected to match any text, but it isn't

Expected behavior
PatternValidator(RegExp(r".*")).isMatch("text") should return true, but it returns false.

Flutter doctor

[✓] Flutter (Channel beta, 2.1.0-12.2.pre, on Mac OS X 10.15.5 19F101 darwin-x64, locale en-AU)
    • Flutter version 2.1.0-12.2.pre at /Users/tim.wen/Workspace/flutter
    • Framework revision 5bedb7b1d5 (3 weeks ago), 2021-03-17 17:06:30 -0700
    • Engine revision 711ab3fda0
    • Dart version 2.13.0 (build 2.13.0-116.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /usr/local/lib/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /usr/local/lib/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio
    • Android Studio at /Applications/Android Studio 4.2 Preview.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 1.8.0_242-release-1644-b3-6222593)

[✓] Android Studio (version 4.1)
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.55.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (3 available)
    • iPhone 12 Pro (mobile) • 8E043A16-17CB-44E0-ADEF-9AD872895BAA • ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
    • macOS (desktop)        • macos                                • darwin-x64     • Mac OS X 10.15.5 19F101 darwin-x64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 89.0.4389.114

• No issues found!

Additional context
The fundamental issue isValid method, which convert the pattern to String by calling toString.

@override
bool isValid(String? value) =>
    hasMatch(pattern.toString(), value!, caseSensitive: caseSensitive);

Pattern has 2 implementations: String.toString returns itself. but RegExp.toString doesn't return its pattern.

RegExp(r".*").toString() returns RegExp/.*/.

Can be fixed by #15