Advertisement
dougmo

Codigo MAIN

Jan 19th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.02 KB | None | 0 0
  1. class MyHomePage extends StatefulWidget {
  2.   MyHomePage({Key key, this.title}) : super(key: key);
  3.  
  4.   final String title;
  5.  
  6.   @override
  7.   _MyHomePageState createState() => _MyHomePageState();
  8. }
  9.  
  10. class _MyHomePageState extends State<MyHomePage> {
  11.   CollectionReference userRef =
  12.       Firestore.instance.collection('Users').reference();
  13.   String idGravado = "";
  14.  
  15.   void _incrementCounter() {
  16.     var novoUsuario = {
  17.       "nome": "João",
  18.       "sobrenome": "Pereira",
  19.       "endereco": "Rua endereco",
  20.       "numero": "000",
  21.       "telefones": {"principal ": " (42)2222222", "secundario": " (42)2222222"},
  22.     };
  23.     userRef.add(novoUsuario).then((val) {
  24.       print(val.documentID);
  25.       setState(() {
  26.         idGravado = val.documentID;
  27.       });
  28.     });
  29.   }
  30.  
  31.   TextEditingController nome = new TextEditingController(text: "");
  32.   TextEditingController endereco = new TextEditingController(text: "");
  33.   TextEditingController email = new TextEditingController(text: "");
  34.  
  35.  
  36.   @override
  37.   Widget build(BuildContext context) {
  38.     return Scaffold(
  39.       appBar: AppBar(
  40.         title: Text(widget.title),
  41.       ),
  42.       body: Center(
  43.         child: Column(
  44.           mainAxisAlignment: MainAxisAlignment.center,
  45.           children: <Widget>[
  46.  
  47.             inputField(nome, labelText: "Nome", hintText: "Digite o nome do usuário", icone: Icons.person),
  48.             inputField(endereco, labelText: "Endereço", hintText: "Digite o nome endereço", icone: Icons.map),
  49.             inputField(email, labelText: "Email", hintText: "Digite o email", icone: Icons.email, tipo: TextInputType.emailAddress),
  50.           ],
  51.         ),
  52.       ),
  53.       floatingActionButton: FloatingActionButton(
  54.         onPressed: _incrementCounter,
  55.         tooltip: 'Increment',
  56.         child: Icon(Icons.add),
  57.       ), // This trailing comma makes auto-formatting nicer for build methods.
  58.     );
  59.   }
  60.  
  61.  
  62.   Widget inputField(TextEditingController text, {String hintText = "", String labelText = "", IconData icone = Icons.person, TextInputType tipo = TextInputType.text}) {
  63.     return Padding(
  64.       padding: const EdgeInsets.all(10),
  65.       child: TextFormField(
  66.         controller: text,
  67.         keyboardType: TextInputType.text,
  68.         autovalidate: true,
  69.         autocorrect: true,
  70.         validator: (val){
  71.           print(val);
  72.           if(val.length < 3){
  73.             return "Muito curto";
  74.           }if(labelText == "Email"){
  75.             return validateEmail(val);
  76.           }
  77.         },
  78.         decoration: InputDecoration(
  79.           hintText: hintText,
  80.           icon: Icon(icone),
  81.           labelText: labelText,
  82.  
  83.         ),
  84.       ),
  85.     );
  86.   }
  87.  
  88.   String validateEmail(String value) {
  89.     Pattern pattern =
  90.         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,}))$';
  91.     RegExp regex = new RegExp(pattern);
  92.     if (!regex.hasMatch(value))
  93.       return 'Digite um e-mail válido';
  94.     else
  95.       return null;
  96.   }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement