Skip to content

Instantly share code, notes, and snippets.

@the-dagger
Created July 4, 2018 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-dagger/48840d0896e346d8bf19d655dca662b7 to your computer and use it in GitHub Desktop.
Save the-dagger/48840d0896e346d8bf19d655dca662b7 to your computer and use it in GitHub Desktop.
Login
import 'package:flutter/material.dart';
import 'package:http/http.dart' show post;
import 'package:login_stateful/src/mixins/validation_mixin.dart';
class LoginScreen extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return LoginScreenState();
}
}
class LoginScreenState extends State<LoginScreen> with ValidationMixin {
final formKey = GlobalKey<FormState>();
String email, password;
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(20.0),
child: Form(
key: formKey,
child: Column(
children: <Widget>[
emailField(),
passwordField(),
submitButton(),
],
),
),
);
}
Widget emailField() => Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(
color: Colors.black,
fontSize: 20.0,
),
decoration: InputDecoration(
labelText: "Email Address",
hintText: "you@example.com",
border: OutlineInputBorder(),
),
validator: validateEmail,
onSaved: (String value) {
email = value;
},
),
);
Widget passwordField() => Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
style: TextStyle(
color: Colors.black,
fontSize: 20.0,
),
obscureText: true,
decoration: InputDecoration(
labelText: "Password",
hintText: "Enter the password here",
border: OutlineInputBorder()),
validator: validatePassword,
onSaved: (String value) {
password = value;
},
),
);
Widget submitButton() => RaisedButton(
color: Colors.lightBlue,
onPressed: () {
if (formKey.currentState.validate()) {
formKey.currentState.save();
makeNetworkCall(email, password);
}
},
textColor: Colors.white,
child: Text("Submit"),
);
makeNetworkCall(String email, String password) async {
String body = "{ email : $email, password : $password }";
var result =
await post("http://ptsv2.com/t/1jrcm-1530596508/post", body: body);
print(result.body);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment