Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:rezervisanje/login/connect.dart' as conn;
- class FirstTime extends StatefulWidget {
- final Color primaryColor;
- final Color backgroundColor;
- FirstTime({Key key, this.primaryColor, this.backgroundColor});
- @override
- _FirstTimeState createState() => new _FirstTimeState();
- }
- class _FirstTimeState extends State<FirstTime> {
- var exe = "exe";
- var pass, email;
- bool _autoValidate = false;
- String _validateEmail(String value) {
- if (value.isEmpty) {
- return "Email";
- }
- String p = "[a-zA-Z0-9+._%-+]{1,256}" +
- "\@" +
- "[a-zA-Z0-9][a-zA-Z0-9\-]{0,64}" +
- "(" +
- "\." +
- "[a-zA-Z0-9][a-zA-Z0-9\-]{0,25}" +
- ")+";
- RegExp regExp = new RegExp(p);
- if (regExp.hasMatch(value)) {
- return null;
- }
- return 'bad email!';
- }
- void _submit() {
- if (formKey.currentState.validate()) {
- try {
- formKey.currentState.save();
- conn.validateAndSubmit(email, pass);
- if (globals.userID != "") {
- Navigator.of(context).push(new MaterialPageRoute(
- builder: (BuildContext context) => new HomePage()));
- }
- } catch (e) {
- exe = e.toString();
- print(exe);
- if (exe != "") {
- new Text(exe);
- }
- if (globals.conex != "") {
- new Text(globals.conex);
- }
- }
- } else {
- setState(() => _autoValidate = true);
- }
- }
- final formKey = GlobalKey<FormState>();
- @override
- Widget build(BuildContext context) {
- return new Scaffold(
- backgroundColor: Colors.orange,
- body: Container(
- color: Colors.orange,
- child: Padding(
- padding: EdgeInsets.all(34.0),
- child: Form(
- autovalidate: _autoValidate,
- key: formKey,
- child:
- Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
- TextFormField(
- decoration: InputDecoration(
- icon: Icon(Icons.person_outline),
- hintText: globals.firstName,
- hintStyle: TextStyle(color: Colors.black54),
- labelText: "Email"),
- validator: _validateEmail,
- keyboardType: TextInputType.emailAddress,
- onSaved: (input) => email = input,
- ),
- new TextFormField(
- decoration: InputDecoration(
- icon: Icon(Icons.lock_outline),
- labelStyle: new TextStyle(color: Colors.black54),
- hintText: globals.lastName,
- labelText: "password"),
- validator: (input) =>
- input.length <= 0 ? 'password needed' : null,
- onSaved: (input) => pass = input,
- ),
- //Last Name TextBox
- Column(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: RaisedButton(
- shape: new RoundedRectangleBorder(
- borderRadius: new BorderRadius.circular(30.0)),
- color: Colors.deepOrange,
- onPressed: _submit,
- textColor: Colors.black,
- child: Text("login"),
- ) //Submit Button
- )
- ],
- ),
- Column(
- mainAxisAlignment: MainAxisAlignment.end,
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: RaisedButton(
- shape: new RoundedRectangleBorder(
- borderRadius: new BorderRadius.circular(30.0)),
- color: Colors.deepOrange,
- textColor: Colors.black,
- onPressed: () => Navigator.of(context).push(
- new MaterialPageRoute(
- builder: (BuildContext context) =>
- new Register())),
- child: Text("register"),
- ) //Submit Button
- ),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: FlatButton(
- onPressed: () => Navigator.of(context).push(
- new MaterialPageRoute(
- builder: (BuildContext context) =>
- new PassReset())),
- child: Text("forgot password?"),
- )),
- ],
- )
- ]),
- ),
- )));
- }
- }
- void validateAndSubmit(String email, String password) async {
- try {
- FirebaseUser user = await FirebaseAuth.instance
- .signInWithEmailAndPassword(email: email, password: password);
- globals.userID = user.uid;
- if (globals.userID == "") {
- globals.conex = "check your pass or email";
- }
- } catch (e) {
- if (Platform.isIOS) {
- globals.conex = e.details;
- } else
- globals.conex = e.message;
- }
- }
Add Comment
Please, Sign In to add comment