0
votes

Comment mettre un var au lieu d'une chaîne dans le package de validation par courrier électronique

J'ai besoin de mettre un var dans l'endroit de la chaîne dans le validateur de courrier électronique: xxx

mais cela me jette cette erreur: Arguments invalides: email. Aide !!


0 commentaires

3 Réponses :


0
votes

Vous obtenez l'erreur car la méthode valider a besoin d'une chaîne .

Remplacez votre code par celui ci-dessous: Cela fonctionne parfaitement: xxx

J'espère que cela aide.

Mise à jour

Ajouter les variables ci-dessous à votre classe: xxx

Remplacez votre widget de messagerieTexformfield avec celui ci-dessous: xxx

Remplacez ceci avec votre fonction de validation xxx

J'espère que cela aide.


3 commentaires

Merci pour votre réponse, mais je dois valider le courrier électronique dans lequel l'utilisateur entre dans CustomTextfield, car le courrier est le contrôleur,


D'accord. Faites ceci: email = textditingcontroller.text; . Qui obtiendrait le texte de votre Textfield F vous avez un contrôleur qui lui est attribué


Membre d'instance 'Text' n'est pas accessible à l'aide d'un accès statique.



0
votes
import 'package:flutter/material.dart';
import 'package:login_signup/constants/constants.dart';
import 'package:login_signup/ui/widgets/custom_shape.dart';
import 'package:login_signup/ui/widgets/customappbar.dart';
import 'package:login_signup/ui/widgets/responsive_ui.dart';
import 'package:login_signup/ui/widgets/textformfield.dart';
import 'package:email_validator/email_validator.dart';

class SignUpScreen extends StatefulWidget {
  @override
  _SignUpScreenState createState() => _SignUpScreenState();
}

class _SignUpScreenState extends State<SignUpScreen> {
  bool checkBoxValue = false;
  double _height;
  double _width;
  double _pixelRatio;
  bool _large;
  bool _medium;
  var email;

  void validation(var val) {
    bool emailvalidated = EmailValidator.validate(val);
    if (emailvalidated) {
      print('object');
    }
  }

  @override
  Widget build(BuildContext context) {
    _height = MediaQuery.of(context).size.height;
    _width = MediaQuery.of(context).size.width;
    _pixelRatio = MediaQuery.of(context).devicePixelRatio;
    _large = ResponsiveWidget.isScreenLarge(_width, _pixelRatio);
    _medium = ResponsiveWidget.isScreenMedium(_width, _pixelRatio);

    return Material(
      child: Scaffold(
        body: Container(
          height: _height,
          width: _width,
          margin: EdgeInsets.only(bottom: 5),
          child: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                Opacity(opacity: 0.88, child: CustomAppBar()),
                clipShape(),
                form(),
                acceptTermsTextRow(),
                SizedBox(
                  height: _height / 35,
                ),
                button(),
                infoTextRow(),
                socialIconsRow(),
                //signInTextRow(),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget clipShape() {
    return Stack(
      children: <Widget>[
        Opacity(
          opacity: 0.75,
          child: ClipPath(
            clipper: CustomShapeClipper(),
            child: Container(
              height: _large
                  ? _height / 8
                  : (_medium ? _height / 7 : _height / 6.5),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [Colors.orange[200], Colors.pinkAccent],
                ),
              ),
            ),
          ),
        ),
        Opacity(
          opacity: 0.5,
          child: ClipPath(
            clipper: CustomShapeClipper2(),
            child: Container(
              height: _large
                  ? _height / 12
                  : (_medium ? _height / 11 : _height / 10),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: [Colors.orange[200], Colors.pinkAccent],
                ),
              ),
            ),
          ),
        ),
        Container(
          height: _height / 5.5,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            boxShadow: [
              BoxShadow(
                  spreadRadius: 0.0,
                  color: Colors.black26,
                  offset: Offset(1.0, 10.0),
                  blurRadius: 20.0),
            ],
            color: Colors.white,
            shape: BoxShape.circle,
          ),
          child: GestureDetector(
              onTap: () {
                print('Adding photo');
              },
              child: Icon(
                Icons.add_a_photo,
                size: _large ? 40 : (_medium ? 33 : 31),
                color: Colors.orange[200],
              )),
        ),
//        Positioned(
//          top: _height/8,
//          left: _width/1.75,
//          child: Container(
//            alignment: Alignment.center,
//            height: _height/23,
//            padding: EdgeInsets.all(5),
//            decoration: BoxDecoration(
//              shape: BoxShape.circle,
//              color:  Colors.orange[100],
//            ),
//            child: GestureDetector(
//                onTap: (){
//                  print('Adding photo');
//                },
//                child: Icon(Icons.add_a_photo, size: _large? 22: (_medium? 15: 13),)),
//          ),
//        ),
      ],
    );
  }

  Widget form() {
    return Container(
      margin: EdgeInsets.only(
          left: _width / 12.0, right: _width / 12.0, top: _height / 20.0),
      child: Form(
        child: Column(
          children: <Widget>[
            firstNameTextFormField(),
            SizedBox(height: _height / 60.0),
            lastNameTextFormField(),
            SizedBox(height: _height / 60.0),
            emailTextFormField(),
            SizedBox(height: _height / 60.0),
            phoneTextFormField(),
            SizedBox(height: _height / 60.0),
            passwordTextFormField(),
          ],
        ),
      ),
    );
  }

  Widget firstNameTextFormField() {
    return CustomTextField(
      keyboardType: TextInputType.text,
      icon: Icons.person,
      hint: "First Name",
    );
  }

  Widget lastNameTextFormField() {
    return CustomTextField(
      keyboardType: TextInputType.text,
      icon: Icons.person,
      hint: "Last Name",
    );
  }

  Widget emailTextFormField() {
    return CustomTextField(
      keyboardType: TextInputType.emailAddress,
      icon: Icons.email,
      hint: "Email ID",
      textEditingController: email,
    );
  }

  Widget phoneTextFormField() {
    return CustomTextField(
      keyboardType: TextInputType.number,
      icon: Icons.phone,
      hint: "Mobile Number",
    );
  }

  Widget passwordTextFormField() {
    return CustomTextField(
      keyboardType: TextInputType.text,
      obscureText: true,
      icon: Icons.lock,
      hint: "Password",
    );
  }

  Widget acceptTermsTextRow() {
    return Container(
      margin: EdgeInsets.only(top: _height / 100.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Checkbox(
              activeColor: Colors.orange[200],
              value: checkBoxValue,
              onChanged: (bool newValue) {
                setState(() {
                  checkBoxValue = newValue;
                });
              }),
          Text(
            "I accept all terms and conditions",
            style: TextStyle(
                fontWeight: FontWeight.w400,
                fontSize: _large ? 12 : (_medium ? 11 : 10)),
          ),
        ],
      ),
    );
  }

  Widget button() {
    return RaisedButton(
      elevation: 0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
      onPressed: () {
        validation(email);
      },
      textColor: Colors.white,
      padding: EdgeInsets.all(0.0),
      child: Container(
        alignment: Alignment.center,
//        height: _height / 20,
        width: _large ? _width / 4 : (_medium ? _width / 3.75 : _width / 3.5),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(20.0)),
          gradient: LinearGradient(
            colors: <Color>[Colors.orange[200], Colors.pinkAccent],
          ),
        ),
        padding: const EdgeInsets.all(12.0),
        child: Text(
          'SIGN UP',
          style: TextStyle(fontSize: _large ? 14 : (_medium ? 12 : 10)),
        ),
      ),
    );
  }

  Widget infoTextRow() {
    return Container(
      margin: EdgeInsets.only(top: _height / 40.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            "Or create using social media",
            style: TextStyle(
                fontWeight: FontWeight.w400,
                fontSize: _large ? 12 : (_medium ? 11 : 10)),
          ),
        ],
      ),
    );
  }

  Widget socialIconsRow() {
    return Container(
      margin: EdgeInsets.only(top: _height / 80.0),
      child: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          CircleAvatar(
            radius: 15,
            backgroundImage: AssetImage("assets/images/googlelogo.png"),
          ),
          SizedBox(
            width: 20,
          ),
          CircleAvatar(
            radius: 15,
            backgroundImage: AssetImage("assets/images/fblogo.jpg"),
          ),
          SizedBox(
            width: 20,
          ),
          CircleAvatar(
            radius: 15,
            backgroundImage: AssetImage("assets/images/twitterlogo.jpg"),
          ),
        ],
      ),
    );
  }

  Widget signInTextRow() {
    return Container(
      margin: EdgeInsets.only(top: _height / 20.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            "Already have an account?",
            style: TextStyle(fontWeight: FontWeight.w400),
          ),
          SizedBox(
            width: 5,
          ),
          GestureDetector(
            onTap: () {
              Navigator.of(context).pop(SIGN_IN);
              print("Routing to Sign up screen");
            },
            child: Text(
              "Sign in",
              style: TextStyle(
                  fontWeight: FontWeight.w800,
                  color: Colors.orange[200],
                  fontSize: 19),
            ),
          )
        ],
      ),
    );
  }
}

9 commentaires

Vous n'avez pas ajouté votre CustomTextfield code @omar Yacop


J'ai eu: widget emailTextFormfield () {return CustomTextfield (claviertype: textinputtype.emailaddress, icône: icônes.email, indice: "Identification par courrier électronique", TextEditController: email,); }


Pouvez-vous l'ajouter au code que vous venez de télécharger s'il vous plaît? @Omar yacop


Ce que je vous demande d'ajouter au téléchargement est ce fichier importer 'package: login_signup / ui / widgets / textformfield.dart'; @omar yacop. Avec cela, je pourrai résoudre l'erreur dans votre code.


Désolé je n'ai pas réalisé ce que vous voulez


J'avais vérifié.


Mais vous avez défini TextDItingController deux fois. Var Courriel = EmailDItingController.Text Seuls les membres statiques sont accessibles dans Initializers.Dart (implicit_this_reference_in_initializer) Le type d'e-mail ne peut pas être déduit car il fait référence à une instance getter, "e-mail", qui a un type implicite. Ajoutez un type explicite pour «email» ou «e-mail»


La dernière mise à jour fonctionne bien, mais elle dit validé si elle a des lettres, @, gmail.com mais si elle l'a ./; [] [] Ce n'est pas validé. Donc, je peux travailler avec ceci pour le moment, mais comment puis-je m'inscrire sur Firebase et merci beaucoup.


Demandez cela dans une autre question. Je répondrai. Cette question semble désorganisée déjà @omar Yacop



0
votes
Here:
import 'package:flutter/material.dart';
import 'package:login_signup/ui/widgets/responsive_ui.dart';

class CustomTextField extends StatelessWidget {
  final String hint;
  final TextEditingController textEditingController;
  final TextInputType keyboardType;
  final bool obscureText;
  final IconData icon;
  double _width;
  double _pixelRatio;
  bool large;
  bool medium;


  CustomTextField(
    {this.hint,
      this.textEditingController,
      this.keyboardType,
      this.icon,
      this.obscureText= false,
     });

  @override
  Widget build(BuildContext context) {
    _width = MediaQuery.of(context).size.width;
    _pixelRatio = MediaQuery.of(context).devicePixelRatio;
    large =  ResponsiveWidget.isScreenLarge(_width, _pixelRatio);
    medium=  ResponsiveWidget.isScreenMedium(_width, _pixelRatio);
    return Material(
      borderRadius: BorderRadius.circular(30.0),
      elevation: large? 12 : (medium? 10 : 8),
      child: TextFormField(
        controller: textEditingController,
        keyboardType: keyboardType,
        cursorColor: Colors.orange[200],
        decoration: InputDecoration(
          prefixIcon: Icon(icon, color: Colors.orange[200], size: 20),
          hintText: hint,
          border: OutlineInputBorder(
              borderRadius: BorderRadius.circular(30.0),
              borderSide: BorderSide.none),
        ),
      ),
    );
  }
}

8 commentaires

Pouvez-vous me conseiller une meilleure façon de valider l'e-mail ??


Il y a ce paquet de connexion Google, mais j'ai toujours des erreurs PUB.Dev/Packages/Google_sign_in


Mis à jour, Vérifiez maintenant. Si cela ne fonctionne pas. Je vais donner un meilleur moyen de valider le courrier électronique.


J'ai ajouté static devant la texteditingcontroller et cela m'a résolu mais cela m'a donné ce texteContrôleur: Email => Le type d'argument 'String' ne peut pas être affecté au type de paramètre 'TexteditingController'.


J'ai abandonné, quelle est la meilleure façon, s'il vous plaît.


Puis-je ajouter cette méthode: 'String validateemail (valeur de chaîne) {modèle de chaîne = r' ^ (([^ <> () [] \\.,;: \ S @ \ "] + (\. [^ <> () [] \\.,;: \ s @ \ "] +) *) | (\". + \ ")) @ ([[0-9] {1,3} \. [0-9] {1,3} \. [0-9] {1,3} \. [0-9] {1,3}]) | ((a-za-z \ -0-9] + \.) + [A-za-z] {2,})) $ '; REGEXP REGEXP = NOUVELLE REGEXP (modèle); if (valeur.longueur == 0) {retour "e-mail est requis"; } elier si (! regexp.hasmachch (valeur)) {renvoie "Email non valide"; } else {renvoie null; }} '


C'était la meilleure option que je voulais donner. J'ai trouvé ce qui n'allait pas avec le code. Vérifiez le mis à jour. Fonctionne parfaitement.


Copiez simplement la section des trois derniers codes et tout irait bien