Last active
January 27, 2021 13:52
-
-
Save andrempeixoto/9f8dffe6c8a291eb0252b6e7bbe8062d to your computer and use it in GitHub Desktop.
Primeiro App Flutter com DartPad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
final _form = GlobalKey<FormState>(); | |
void _realizarLogin() { | |
final isValid = _form.currentState.validate(); | |
if (isValid) { | |
_form.currentState.save(); | |
} | |
} | |
void main() { | |
runApp( | |
MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text( | |
'APP Test - Login', | |
), | |
), | |
body: Center( | |
child: Padding( | |
padding: EdgeInsets.all(20), | |
child: Form( | |
key: _form, | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Container( | |
child: TextFormField( | |
decoration: InputDecoration(labelText: 'Usuário'), | |
validator: (value) { | |
if (value.isEmpty || value == null) { | |
return 'Informar Usuário'; | |
} | |
return null; | |
}, | |
), | |
), | |
Container( | |
child: TextFormField( | |
decoration: InputDecoration(labelText: 'Senha'), | |
validator: (value) { | |
if (value.isEmpty || value == null) { | |
return 'É necessário informar a senha'; | |
} else { | |
if (value.length < 6) { | |
return 'A senha deve conter mais de 6 caracteres'; | |
} | |
} | |
return null; | |
}, | |
), | |
), | |
Container( | |
child: FlatButton( | |
child: Text('Login'), | |
onPressed: () { | |
_realizarLogin(); | |
}, | |
)), | |
], | |
), | |
), | |
), | |
), | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment