Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mask for IP v4 Address #60

Closed
insinfo opened this issue Sep 17, 2021 · 2 comments
Closed

mask for IP v4 Address #60

insinfo opened this issue Sep 17, 2021 · 2 comments

Comments

@insinfo
Copy link

insinfo commented Sep 17, 2021

Hi, I would like to mask IP Address in TextFormField. The following code is partially written and does not work. Please advice.

new MaskTextInputFormatter(mask: '#.#.#.#',
    filter: {
      '#': new RegExp(r'^([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$')
    }); 
...
For each value, the number should be between 0-255.
@insinfo insinfo changed the title mask for IP Addres mask for IP v4 Address Sep 17, 2021
@tsctrl
Copy link

tsctrl commented Jan 24, 2022

any update? i am having same issue

@GuilhermeAlecrim7K
Copy link

Using the RegEx provided by @insinfo , the result is that whatever number is inputted into the field, the RegEx is matched. This means that the outcome in the TextField is always the same, four single digits separated by '.'.

I spent some time thinking about it and I do not believe there is a solution to accurately display the IPv4 mask.

Think about the following addresses:

25.1.3.67
251.3.6.7

Both are valid adresses and contain the same set of digits in the same order but are completely different. Since both values are valid, what criteria should be used for the mask? It is something only the user can define.

The best option would be to render a Row containing 4 TextFormField and a Text to display the dot. You should componentize the TextFormField since it can have the exact same properties.

Here's a sample:

import 'package:flutter/material.dart';

class TextFormFieldRow extends StatelessWidget {
  const TextFormFieldRow({super.key});

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        for (var i = 0; i < 4; i++) ...[
          SizedBox(
            height: 40,
            width: 50,
            // Customize TextFormField here
            child: Center(child: TextFormField()),
          ),
          Text('.'),
        ]
      ]..removeLast(),
    );
  }
}

@siqwin siqwin closed this as completed Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants