Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:restaurant_management/employee/employee.dart';
- import '../firebase/authentication.dart';
- import '../firebase/db.dart';
- class Signup extends StatelessWidget {
- const Signup({super.key});
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- elevation: 0,
- automaticallyImplyLeading: true,
- leading: IconButton(
- icon: Icon(Icons.arrow_back),
- onPressed: () => Navigator.of(context).pop(),
- ),
- backgroundColor: const Color(0xFF68A268),
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.only(
- bottomLeft: Radius.circular(50.0),
- bottomRight: Radius.circular(50.0),
- ),
- ),
- toolbarHeight: 100,
- flexibleSpace: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Center(
- child: Container(
- height: 85,
- width: 110,
- decoration: const BoxDecoration(
- image: DecorationImage(
- image: AssetImage('assets/logo.png'), fit: BoxFit.cover),
- ),
- ),
- )
- ],
- ),
- ),
- body: SingleChildScrollView(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.spaceAround,
- children: <Widget>[
- const SizedBox(height: 50),
- const Text('Restaurant',
- textAlign: TextAlign.center,
- style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30)),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: SignupForm(),
- ),
- ],
- ),
- ),
- );
- }
- }
- class SignupForm extends StatefulWidget {
- SignupForm({Key? key}) : super(key: key);
- @override
- _SignupFormState createState() => _SignupFormState();
- }
- class _SignupFormState extends State<SignupForm> {
- final _formKey = GlobalKey<FormState>();
- TextEditingController email = TextEditingController();
- TextEditingController name = TextEditingController();
- TextEditingController lastName = TextEditingController();
- TextEditingController password = TextEditingController();
- String? selectedRole; // Variable to hold the selected role
- List<String> roles = [
- 'Manager',
- 'Chef',
- 'Waiter',
- 'Cleaner'
- ]; // List of roles
- bool _obscureText = false;
- bool agree = false;
- snapBarBuilder(String message) {
- final snackBar = SnackBar(
- content: Text(message),
- );
- // Find the ScaffoldMessenger in the widget tree
- // and use it to show a SnackBar.
- ScaffoldMessenger.of(context).showSnackBar(snackBar);
- }
- @override
- Widget build(BuildContext context) {
- var border = const OutlineInputBorder(
- borderRadius: BorderRadius.all(
- Radius.circular(100.0),
- ),
- );
- var space = const SizedBox(height: 10);
- return Form(
- key: _formKey,
- child: SingleChildScrollView(
- child: Column(
- children: <Widget>[
- TextFormField(
- controller: name,
- decoration: InputDecoration(
- prefixIcon: const Icon(Icons.person),
- labelText: 'Name',
- border: border),
- validator: (value) {
- if (value!.isEmpty) {
- return 'Please enter some text';
- }
- return null;
- },
- keyboardType: TextInputType.emailAddress,
- ),
- space,
- TextFormField(
- controller: lastName,
- decoration: InputDecoration(
- prefixIcon: const Icon(Icons.person),
- labelText: 'Last Name',
- border: border),
- validator: (value) {
- if (value!.isEmpty) {
- return 'Please enter some text';
- }
- return null;
- },
- keyboardType: TextInputType.emailAddress,
- ),
- space,
- // email
- TextFormField(
- controller: email,
- decoration: InputDecoration(
- prefixIcon: const Icon(Icons.email_outlined),
- labelText: 'Email',
- border: border),
- validator: (value) {
- if (value!.isEmpty) {
- return 'Please enter some text';
- }
- return null;
- },
- keyboardType: TextInputType.emailAddress,
- ),
- space,
- // password
- TextFormField(
- controller: password,
- decoration: InputDecoration(
- labelText: 'Password',
- prefixIcon: const Icon(Icons.lock_outline),
- border: border,
- suffixIcon: GestureDetector(
- onTap: () {
- setState(() {
- _obscureText = !_obscureText;
- });
- },
- child: Icon(
- _obscureText ? Icons.visibility_off : Icons.visibility,
- ),
- ),
- ),
- obscureText: !_obscureText,
- validator: (value) {
- if (value!.isEmpty) {
- return 'Please enter some text';
- }
- return null;
- },
- ),
- space,
- // confirm passwords
- TextFormField(
- decoration: InputDecoration(
- labelText: 'Confirm Password',
- prefixIcon: const Icon(Icons.lock_outline),
- border: border,
- ),
- obscureText: true,
- validator: (value) {
- if (value != password.text) {
- return 'password not match';
- }
- return null;
- },
- ),
- space,
- // name
- const SizedBox(
- height: 10,
- ),
- DropdownButtonFormField(
- decoration: InputDecoration(
- labelText: 'Select Role',
- border: border,
- prefixIcon: const Icon(Icons.person_outline),
- ),
- value: selectedRole,
- onChanged: (String? newValue) {
- setState(() {
- selectedRole = newValue;
- });
- },
- validator: (value) =>
- value == null ? 'Please select a role' : null,
- items: roles.map<DropdownMenuItem<String>>((String value) {
- return DropdownMenuItem<String>(
- value: value,
- child: Text(value),
- );
- }).toList(),
- ),
- space,
- // signUP button
- SizedBox(
- height: 50,
- width: double.infinity,
- child: ElevatedButton(
- onPressed: () {
- if (_formKey.currentState!.validate()) {
- _formKey.currentState!.save();
- AuthenticationHelper()
- .signUp(
- email: email.text.trim()!,
- password: password.text.trim()!)
- .then((result) {
- try {
- if (result) {
- if (selectedRole == 'Manager') {
- editUserInfo({'role': selectedRole});
- } else {
- String uid = AuthenticationHelper().uid;
- Employee employee = Employee(
- name: name.text.trim(),
- lastName: lastName.text.trim(),
- email: email.text.trim(),
- role: selectedRole,
- uid: uid);
- editUserInfo(employee.toMap());
- reset_info();
- }
- snapBarBuilder('user was been added');
- }
- } catch (e) {
- snapBarBuilder(result);
- }
- });
- }
- },
- style: ElevatedButton.styleFrom(
- backgroundColor: const Color(0xFF68A268),
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.all(Radius.circular(24.0)))),
- child: const Text(
- 'Add user',
- style: TextStyle(color: Colors.white, fontSize: 20),
- ),
- ),
- ),
- SizedBox(
- height: 10,
- )
- ],
- ),
- ),
- );
- }
- void reset_info() {
- name.text = '';
- lastName.text = '';
- email.text = '';
- selectedRole = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement