0

I have a Sign-up form with the following input fields:

Domain Name Email Password

What I would like to achieve is the following process:

User types in Business Domain URL, types in Email address connected to the Domain and a Password.

What's the best way to make the app check in the background if the Domain sends back a 200 code to assure validation? We can talk about a compensation, if that is desired.

I've experimented with "http 0.12.0+4" on pub.dev but it wasn't constructed exactly for what i want to achieve.

import 'package:easybeezzy/screens/login_screen.dart';
import 'package:flutter/material.dart';

class SignupScreen extends StatefulWidget {
  static final String id = 'signup_screen';

  @override
  _SignupScreenState createState() => _SignupScreenState();
}

class _SignupScreenState extends State<SignupScreen> {
  final _formKey = GlobalKey<FormState>();
  String _name, _email, _password, _domain;

  _submit() {
    if (_formKey.currentState.validate()) {
      _formKey.currentState.save();
      print(_name);
      print(_domain);
      print(_email);
      print(_password);
      //Logging in the User with Firebase
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SingleChildScrollView(
          child: Container(
            height: MediaQuery.of(context).size.height,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Text(
                  'Easy Beezy',
                  style: TextStyle(
                    fontSize: 50.0,
                    fontFamily: 'PlayfairDisplay',
                  ),
                ),
                Form(
                  key: _formKey,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Padding(
                        padding: EdgeInsets.symmetric(
                          horizontal: 30.0,
                          vertical: 10.0,
                        ),
                        child: TextFormField(
                          decoration: InputDecoration(labelText: 'Domain'),
                          validator: (input) => input.length < 3
                              ? 'Please enter a valid Domain'
                              : null,
                          onSaved: (input) => _domain = input,
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.symmetric(
                          horizontal: 30.0,
                          vertical: 10.0,
                        ),
                        child: TextFormField(
                          decoration: InputDecoration(labelText: 'Name'),
                          validator: (input) => input.trim().isEmpty
                              ? 'Please enter a valid name'
                              : null,
                          onSaved: (input) => _name = input,
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.symmetric(
                            horizontal: 30.0, vertical: 10.0),
                        child: TextFormField(
                          decoration: InputDecoration(labelText: 'Email'),
                          validator: (input) => !input.contains('@')
                              ? 'Please enter a valid email, must be connected to the DOMAIN.'
                              : null,
                          onSaved: (input) => _email = input,
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.symmetric(
                          horizontal: 30.0,
                          vertical: 10.0,
                        ),
                        child: TextFormField(
                          decoration: InputDecoration(labelText: 'Password'),
                          validator: (input) => input.length < 6
                              ? 'Must be at least six characters'
                              : null,
                          onSaved: (input) => _password = input,
                          obscureText: true,
                        ),
                      ),
                      SizedBox(height: 20.0),
                      Container(
                        width: 250.0,
                        child: FlatButton(
                          onPressed: _submit,
                          color: Colors.amberAccent,
                          padding: EdgeInsets.all(10.0),
                          child: Text(
                            'Sign Up',
                            style: TextStyle(
                                fontSize: 20.0, color: Colors.black54),
                          ),
                        ),
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      Container(
                        width: 250.0,
                        child: FlatButton(
                          onPressed: () => Navigator.pop(context),
                          color: Colors.blueAccent,
                          padding: EdgeInsets.all(10.0),
                          child: Text(
                            'Back to login',
                            style:
                                TextStyle(fontSize: 20.0, color: Colors.white),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Thank you very much for your time, if you need more info about my project let me know so I can provide it to you. You will not be forgotten once the app is ready for testing.

1 Answers1

1

You can use Uri.parse to check if the URL is valid.

bool validURL = Uri.parse(url).isAbsolute;

If you have a List of domains to validate with, you can use List.contains(String) - this returns a boolean.

Omatt
  • 8,564
  • 2
  • 42
  • 144
  • Omatt, thanks a lot for your kind response, well appreciated. I will try out your suggestion. The target is to the have app to validate the inserted URL and that the email has the same @domain. I will keep you posted, thanks again. – Enrico Petrarolo Feb 15 '22 at 08:51
  • 1
    When I type "`google.com`" it shows me false. When I type "`www.google.com`" it shows me false. When I type "`https://www.google.com/`" it shows me true. How can I fix this problem? – My Car Apr 08 '22 at 13:35
  • If you're anticipating for diverse URIs, an alternative would be to use a `RegExp`. Use a regex pattern from this [post](https://stackoverflow.com/questions/161738/) that will fit your use case. Then use `RegExp(yourRegexPattern).hasMatch(yourUrl);` – Omatt Apr 08 '22 at 15:05