Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:_http';
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:restaurant_app/globalVar.dart';
- import 'package:restaurant_app/homescreen.dart';
- import 'package:restaurant_app/models/auth.dart';
- import 'package:restaurant_app/signup.dart';
- import 'package:http/http.dart' as http;
- class SignIn extends StatefulWidget {
- final Post post;
- SignIn({Key key, this.post}) : super(key: key);
- @override
- _SignInState createState() => _SignInState();
- }
- class _SignInState extends State<SignIn> with SingleTickerProviderStateMixin {
- TabController controller;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- controller = new TabController(length: 2, vsync: this);
- }
- @override
- void dispose() {
- // TODO: implement dispose
- super.dispose();
- controller.dispose();
- }
- Future<Post> getAuth() async {
- final response = await http.get(
- "${GlobalVar.Ip}wp-json/jwt-auth/v1/token",
- headers: {HttpHeaders.authorizationHeader: ''});
- final responseJson = json.decode(response.body);
- return Post.fromJson(responseJson);
- }
- String validateEmail(String value) {
- Pattern pattern =
- 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 regex = new RegExp(pattern);
- if (!regex.hasMatch(value))
- return 'Enter Valid Email';
- else
- return null;
- }
- String validatePassword(String value) {
- if (value.length < 4)
- return 'Password must be more than 2 charater';
- else
- return null;
- }
- final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
- bool _autoValidate = false;
- String _password;
- String _email;
- void _validateInputs() {
- if (_formKey.currentState.validate()) {
- // If all data are correct then save data to out variables
- _formKey.currentState.save();
- Navigator.push(
- context, MaterialPageRoute(builder: (context) => HomePage()));
- } else {
- // If all data are not valid then start auto validation.
- setState(() {
- _autoValidate = true;
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- resizeToAvoidBottomPadding: false,
- body: Container(
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage('images/art.png'),
- fit: BoxFit.fill,
- colorFilter: ColorFilter.mode(
- Colors.white12.withOpacity(0.2), BlendMode.dstATop),
- ),
- ),
- child: ListView(
- shrinkWrap: true,
- physics: BouncingScrollPhysics(),
- children: <Widget>[
- SizedBox(
- height: MediaQuery.of(context).size.height / 30,
- ),
- Align(
- alignment: Alignment.topCenter,
- child: CircleAvatar(
- backgroundColor: Colors.grey,
- radius: 55.0,
- backgroundImage: AssetImage('images/logo.png'),
- ),
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 30,
- ),
- Stack(
- alignment: Alignment.center,
- children: <Widget>[
- SizedBox(
- height: MediaQuery.of(context).size.height / 300,
- child: new Center(
- child: new Container(
- height: 10.0,
- color: Colors.black12,
- ),
- ),
- ),
- Row(
- children: <Widget>[
- SizedBox(
- width: MediaQuery.of(context).size.width / 4,
- ),
- Chip(
- label: Text(
- "SIGN IN",
- style: TextStyle(color: Colors.white, fontSize: 18.0),
- ),
- backgroundColor: Color(0xFFD1A155),
- ),
- SizedBox(
- width: MediaQuery.of(context).size.width / 35,
- child: Container(
- width: MediaQuery.of(context).size.height / 12,
- height: 2.0,
- color: Colors.white,
- ),
- ),
- Chip(
- label: Text(
- "SIGN UP",
- style: TextStyle(color: Colors.white, fontSize: 18.0),
- ),
- backgroundColor: Colors.black87,
- ),
- ],
- )
- ],
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 35,
- ),
- Align(
- alignment: Alignment.center,
- child: Text(
- "Welcome back!",
- style: TextStyle(
- fontSize: 20.0,
- color: Color(0xFFD1A155),
- ),
- )),
- SizedBox(
- height: MediaQuery.of(context).size.height / 30,
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 15,
- ),
- Stack(
- alignment: Alignment.center,
- children: <Widget>[
- SizedBox(
- height: 2.0,
- child: new Center(
- child: new Container(
- height: 10.0,
- color: Colors.black12,
- ),
- ),
- ),
- Container(
- height: MediaQuery.of(context).size.height / 18,
- width: MediaQuery.of(context).size.height / 11,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(23.0),
- color: Colors.white,
- border: Border.all(color: Colors.black12)),
- child: Center(
- child: Text(
- "OR",
- style: TextStyle(fontSize: 18.0),
- )),
- ),
- ],
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 30,
- ),
- Padding(
- padding: const EdgeInsets.only(left: 15.0, right: 15.0),
- child: Row(
- children: <Widget>[
- Container(
- height: MediaQuery.of(context).size.height / 13,
- width: MediaQuery.of(context).size.width / 2.2,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(5.0),
- color: Colors.white,
- border: Border.all(color: Colors.black12)),
- child: Row(
- children: <Widget>[
- SizedBox(
- width: 18.0,
- ),
- Icon(Icons.tag_faces),
- SizedBox(
- width: 10.0,
- ),
- Text(
- "Facebook",
- style: TextStyle(fontSize: 22.0, color: Colors.blue),
- ),
- ],
- ),
- ),
- SizedBox(
- width: MediaQuery.of(context).size.width / 40,
- ),
- Container(
- height: MediaQuery.of(context).size.height / 13,
- width: MediaQuery.of(context).size.width / 2.3,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(5.0),
- color: Colors.white,
- border: Border.all(color: Colors.black12)),
- child: Row(
- children: <Widget>[
- SizedBox(
- width: 18.0,
- ),
- Icon(Icons.tag_faces),
- SizedBox(
- width: 10.0,
- ),
- Text(
- "Google+",
- style: TextStyle(fontSize: 22.0, color: Colors.red),
- ),
- ],
- ),
- ),
- ],
- ),
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 20,
- ),
- Align(
- alignment: Alignment.center,
- child: InkWell(
- onTap: () => Navigator.push(
- context, MaterialPageRoute(builder: (context) => SignUp())),
- child: RichText(
- text: TextSpan(
- text: "Don't have an account?",
- style: TextStyle(fontSize: 20.0, color: Colors.black87),
- children: <TextSpan>[
- TextSpan(
- text: ' Sign up',
- style: TextStyle(
- color: Color(0xFFD1A155),
- fontWeight: FontWeight.bold)),
- ])),
- ),
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 30,
- ),
- ],
- ),
- ),
- );
- }
- Widget buildForm() {
- return FutureBuilder<Post>(builder: (context, snapshot) {
- if(snapshot.hasData){
- Post articles = snapshot.data;
- return Form(
- key: _formKey,
- autovalidate: _autoValidate,
- child: Column(
- children: <Widget>[
- Theme(
- data: ThemeData(
- hintColor: Colors.black26,
- primaryColor: Color(0xFFD1A155),
- ),
- child: Padding(
- padding: const EdgeInsets.only(left: 15.0, right: 15.0),
- child: TextFormField(
- keyboardType: TextInputType.emailAddress,
- validator: validateEmail,
- onSaved: (String val) {
- articles.userName = val;
- },
- decoration: InputDecoration(
- border:
- OutlineInputBorder(borderSide: BorderSide()),
- prefixIcon: Icon(
- Icons.email,
- color: Color(0xFFD1A155),
- ),
- hintText: 'Email Address',
- hintStyle: TextStyle(
- color: Colors.black,
- fontWeight: FontWeight.w400)),
- ),
- ),
- ),
- SizedBox(
- height: MediaQuery.of(context).size.height / 45,
- ),
- Theme(
- data: ThemeData(
- primaryColor: Color(0xFFD1A155),
- hintColor: Colors.black26),
- child: Padding(
- padding: const EdgeInsets.only(left: 15.0, right: 15.0),
- child: TextFormField(
- keyboardType: TextInputType.text,
- obscureText: true,
- validator: validatePassword,
- onSaved: (String val) {
- articles.password = val;
- },
- decoration: InputDecoration(
- border:
- OutlineInputBorder(borderSide: BorderSide()),
- prefixIcon: Icon(
- Icons.lock,
- color: Color(0xFFD1A155),
- ),
- hintText: 'Password',
- hintStyle: TextStyle(
- color: Colors.black,
- fontWeight: FontWeight.w400)),
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(right: 15.0, left: 10.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Row(
- children: <Widget>[
- ActionChip(
- onPressed: () {},
- avatar: Checkbox(
- value: false,
- onChanged: (bool z) {
- print(z);
- },
- activeColor: Color(0xFFD1A155),
- ),
- label: Text("Remember Me"),
- backgroundColor: Colors.transparent,
- ),
- ],
- ),
- Text(
- "Forgot Password?",
- style: TextStyle(
- color: Color(0xFFD1A155),
- ),
- ),
- ],
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(left: 15.0, right: 15.0),
- child: InkWell(
- onTap: _validateInputs,
- child: Container(
- height: MediaQuery.of(context).size.height / 13,
- //width: MediaQuery.of(context).size.height / 1.8,
- decoration: BoxDecoration(
- color: Color(0xFFD1A155),
- borderRadius: BorderRadius.circular(5.0),
- ),
- child: Center(
- child: Text(
- "LOGIN",
- style:
- TextStyle(color: Colors.white, fontSize: 18.0),
- ),
- ),
- ),
- ),
- )
- ],
- ),
- );
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment