Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:einventorycomputer/modules/authentication/sign_in.dart';
- import 'package:einventorycomputer/shared/constants.dart';
- import 'package:einventorycomputer/shared/loading.dart';
- import 'package:flutter/material.dart';
- import 'package:einventorycomputer/services/auth.dart';
- class SignUp extends StatefulWidget {
- final Function toggleView;
- SignUp({required this.toggleView});
- @override
- _SignUpState createState() => _SignUpState();
- }
- class _SignUpState extends State<SignUp> {
- final AuthService _auth = AuthService();
- final _formKey = GlobalKey<FormState>();
- bool loading = false;
- // text field state
- String email = '';
- String password = '';
- String error = '';
- @override
- Widget build(BuildContext context) {
- return loading ? Loading() : Scaffold(
- backgroundColor: Colors.brown[100],
- appBar: AppBar(
- backgroundColor: Colors.brown[400],
- elevation: 0.0,
- title: Text('Sign Up to e-Inventory'),
- ),
- body: Container(
- padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 50.0),
- child: Form(
- key: _formKey,
- child: Column(
- children: <Widget>[
- SizedBox(height: 20.0),
- TextFormField(
- decoration: InputDecoration(
- labelText: 'Username',
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(40.0), // Rounded corners
- borderSide: const BorderSide(color: Colors.grey),
- ),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(40.0),
- borderSide: const BorderSide(color: Colors.blue),
- ),
- prefixIcon: const Icon(Icons.person),
- ),
- validator: (val) => val!.isEmpty ? 'Enter an email' : null,
- onChanged: (val){
- setState(() => email = val);
- }
- ),
- SizedBox(height: 20.0),
- TextFormField(
- decoration: textDecoration.copyWith(hintText: 'Password'),
- obscureText: true,
- validator: (val) => val!.length < 6 ? 'Enter a password 6+ chars long' : null,
- onChanged: (val){
- setState(() => password = val);
- }
- ),
- ElevatedButton(
- child: Text(
- 'Register',
- style: TextStyle(color: Colors.white),
- ),
- onPressed: () async {
- if (_formKey.currentState!.validate()){
- setState(() => loading = true);
- dynamic result = await _auth.registerWithEmailAndPassword(email, password);
- if(result == null){
- setState(() {
- error = 'Please supply a valid email';
- loading = false;
- });
- }
- }
- }
- ),
- SizedBox(height: 12.0),
- Text(
- error,
- style: TextStyle(color: Colors.red, fontSize: 14.0),
- ),
- SizedBox(height: 20.0),
- ElevatedButton(
- child: Text(
- 'Sign In',
- style: TextStyle(color: Colors.white),
- ),
- onPressed: () {
- widget.toggleView();
- }
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement