|  | 
|  | 1 | + | 
|  | 2 | +import 'package:flutter/material.dart'; | 
|  | 3 | +import 'package:go_router/go_router.dart'; | 
|  | 4 | + | 
|  | 5 | +// Note: There's a small issue regarding the flex Spacer widget, it's not too important | 
|  | 6 | +// but would be nice to find a way that makes it so the UI elements | 
|  | 7 | +// don't shift when a validator fails. | 
|  | 8 | + | 
|  | 9 | +class Login extends StatefulWidget { | 
|  | 10 | +  const Login({super.key}); | 
|  | 11 | + | 
|  | 12 | +  @override | 
|  | 13 | +  LoginState createState() => LoginState(); | 
|  | 14 | +} | 
|  | 15 | + | 
|  | 16 | +class LoginState extends State<Login> { | 
|  | 17 | +  final _formKey = GlobalKey<FormState>(); | 
|  | 18 | +  bool _obscureText = true; | 
|  | 19 | + | 
|  | 20 | +  @override | 
|  | 21 | +  Widget build(BuildContext context) { | 
|  | 22 | +    return Scaffold( | 
|  | 23 | +      resizeToAvoidBottomInset: false, | 
|  | 24 | +      body: Container( | 
|  | 25 | +        padding: EdgeInsets.all(16.0), | 
|  | 26 | +        child: Form( | 
|  | 27 | +          key: _formKey, | 
|  | 28 | +          child: Column( | 
|  | 29 | +            crossAxisAlignment: CrossAxisAlignment.center, | 
|  | 30 | +            mainAxisAlignment: MainAxisAlignment.center, | 
|  | 31 | +            children: <Widget>[ | 
|  | 32 | +              Spacer(flex: 1), | 
|  | 33 | +              Text( | 
|  | 34 | +                'UTMarketplace', | 
|  | 35 | +                style: TextStyle( | 
|  | 36 | +                  fontSize: 40.0, | 
|  | 37 | +                  color: Theme.of(context).colorScheme.primary, | 
|  | 38 | +                  fontWeight: FontWeight.w900, | 
|  | 39 | +                  letterSpacing: 2, | 
|  | 40 | +                ), | 
|  | 41 | +              ), | 
|  | 42 | +              Spacer(flex: 1), | 
|  | 43 | +              Align( | 
|  | 44 | +                alignment: Alignment.centerLeft, | 
|  | 45 | +                child: Text( | 
|  | 46 | +                  'UofT Email Address', | 
|  | 47 | +                  style: TextStyle( | 
|  | 48 | +                    fontSize: 16.0, | 
|  | 49 | +                    fontWeight: FontWeight.w700, | 
|  | 50 | +                  ), | 
|  | 51 | +                ), | 
|  | 52 | +              ), | 
|  | 53 | +              TextFormField( | 
|  | 54 | +                decoration: InputDecoration( | 
|  | 55 | +                  border: OutlineInputBorder(), | 
|  | 56 | +                  labelText: 'Enter your UofT email', | 
|  | 57 | +                  errorMaxLines: 1,  | 
|  | 58 | +                  errorStyle: TextStyle( | 
|  | 59 | +                    height: 0.0, | 
|  | 60 | +                  ), | 
|  | 61 | +                ), | 
|  | 62 | +                // TODO: REGEX for valid UofT domain email, uncomment when ready | 
|  | 63 | +                // validator: (value) { | 
|  | 64 | +                //   if (value == null || value.isEmpty) { | 
|  | 65 | +                //     return 'Please a valid UofT email address'; | 
|  | 66 | +                //   } | 
|  | 67 | +                //   return null; | 
|  | 68 | +                // }, | 
|  | 69 | +              ), | 
|  | 70 | +              SizedBox(height: 16.0), | 
|  | 71 | +              Align( | 
|  | 72 | +                alignment: Alignment.centerLeft, | 
|  | 73 | +                child: Text( | 
|  | 74 | +                  'Password', | 
|  | 75 | +                  style: TextStyle( | 
|  | 76 | +                    fontSize: 16.0, | 
|  | 77 | +                    fontWeight: FontWeight.w700, | 
|  | 78 | +                  ), | 
|  | 79 | +                ), | 
|  | 80 | +              ), | 
|  | 81 | +              TextFormField( | 
|  | 82 | +                obscureText: _obscureText, | 
|  | 83 | +                decoration: InputDecoration( | 
|  | 84 | +                  border: OutlineInputBorder(), | 
|  | 85 | +                  labelText: 'Enter your password', | 
|  | 86 | +                  errorMaxLines: 1,  | 
|  | 87 | +                  errorStyle: TextStyle( | 
|  | 88 | +                    height: 0.0, | 
|  | 89 | +                  ), | 
|  | 90 | +                  suffixIcon: IconButton( | 
|  | 91 | +                    icon: Icon( | 
|  | 92 | +                      _obscureText ? Icons.visibility_off : Icons.visibility, | 
|  | 93 | +                    ), | 
|  | 94 | +                    onPressed: () { | 
|  | 95 | +                      setState(() { | 
|  | 96 | +                        _obscureText = !_obscureText; | 
|  | 97 | +                      }); | 
|  | 98 | +                    }, | 
|  | 99 | +                  ), | 
|  | 100 | +                ), | 
|  | 101 | +                // TODO: Implement email validation and password validation (backend), uncomment when ready | 
|  | 102 | +                // validator: (value) { | 
|  | 103 | +                //   if (value == null || value.isEmpty) { | 
|  | 104 | +                //     return 'Password or email is incorrect'; | 
|  | 105 | +                //   } | 
|  | 106 | +                //   return null; | 
|  | 107 | +                // }, | 
|  | 108 | +              ), | 
|  | 109 | +              SizedBox(height: 16.0), | 
|  | 110 | +              ElevatedButton( | 
|  | 111 | +                onPressed: () { | 
|  | 112 | +                  if (_formKey.currentState!.validate()) { | 
|  | 113 | +                    // TODO: Implement login functionality (backend) | 
|  | 114 | +                    // If this condition passed, a redirect call to the home  | 
|  | 115 | +                    // page should be made | 
|  | 116 | +                    context.go('/temp_view'); | 
|  | 117 | +                  } | 
|  | 118 | +                }, | 
|  | 119 | +                style: ElevatedButton.styleFrom( | 
|  | 120 | +                  minimumSize: Size(double.infinity, 50), | 
|  | 121 | +                ), | 
|  | 122 | +                child: Text('Log In'), | 
|  | 123 | +              ), | 
|  | 124 | +              Row( | 
|  | 125 | +                mainAxisAlignment: MainAxisAlignment.center, | 
|  | 126 | +                children: <Widget>[ | 
|  | 127 | +                  Text('Don\'t have an account?'), | 
|  | 128 | +                  TextButton( | 
|  | 129 | +                    onPressed: () { | 
|  | 130 | +                      // TODO: Implement redirect to sign up page | 
|  | 131 | +                    }, | 
|  | 132 | +                    child: Text('Sign Up'), | 
|  | 133 | +                  ), | 
|  | 134 | +                ], | 
|  | 135 | +              ), | 
|  | 136 | +              TextButton( | 
|  | 137 | +                onPressed: () { | 
|  | 138 | +                  // TODO: Implement forgot password functionality | 
|  | 139 | +                }, | 
|  | 140 | +                child: Text('Forgot Password?'), | 
|  | 141 | +              ), | 
|  | 142 | +              Spacer(flex: 1), | 
|  | 143 | +            ], | 
|  | 144 | +          ), | 
|  | 145 | +        ), | 
|  | 146 | +      ), | 
|  | 147 | +    ); | 
|  | 148 | +  } | 
|  | 149 | +} | 
0 commit comments