From 3dd8235784391d5502fa1a09ca7967650e151021 Mon Sep 17 00:00:00 2001 From: axtloss <3alouchi2006@gmail.com> Date: Sun, 6 Feb 2022 21:47:00 +0100 Subject: [PATCH] add user stuff --- lib/functions/users.dart | 224 +++++++++++++++++++++++++++++++++++++++ lib/main.dart | 48 +++++++-- 2 files changed, 265 insertions(+), 7 deletions(-) create mode 100644 lib/functions/users.dart diff --git a/lib/functions/users.dart b/lib/functions/users.dart new file mode 100644 index 0000000..5340cd6 --- /dev/null +++ b/lib/functions/users.dart @@ -0,0 +1,224 @@ +import 'package:flutter/material.dart'; + +final _formKey = GlobalKey(); +RegExp userRegex = RegExp(r'^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$'); +Widget users(setState, enableRoot, setPass, setConfirmPass, password, + confirmPassword, setUsername, username, next) { + return Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const SizedBox(height: 40), + const Text( + 'Create a new user', + style: TextStyle( + fontSize: 60, + fontWeight: FontWeight.bold, + color: Color.fromARGB(255, 169, 0, 255)), + ), + const SizedBox(height: 20), + Container( + height: 125, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.grey, + boxShadow: [ + BoxShadow( + color: Colors.black, + blurRadius: 10, + offset: Offset(-5, 10), + ), + ], + ), + child: const Icon( + Icons.person, + size: 125, + ), + ), + const SizedBox(width: 10), + Form( + key: _formKey, + autovalidateMode: AutovalidateMode.always, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox(width: 10), + SizedBox( + width: 600, + child: Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + border: Border.all(color: Colors.black), + color: const Color.fromARGB(255, 30, 30, 30), + boxShadow: const [ + BoxShadow( + color: Colors.black, + blurRadius: 10, + offset: Offset(-5, 10), + ), + ], + ), + child: Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox(height: 10), + TextFormField( + autovalidateMode: AutovalidateMode.always, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: 'Username', + labelStyle: TextStyle(color: Colors.white), + hintText: 'Enter your username', + iconColor: Colors.white, + focusColor: Color.fromARGB(100, 169, 0, 255), + hoverColor: Colors.blue, + prefixIconColor: Colors.white, + suffixIconColor: Colors.white, + ), + style: const TextStyle(color: Colors.white), + onChanged: (String? value) { + setUsername(value); + debugPrint(value); + debugPrint("Username: $username"); + }, + validator: (String? value) { + return (value != "" && + value != null && + !userRegex.hasMatch(value)) + ? 'Bad username, may not contain spaces, uppercase, or special characters' + : null; + }, + ), + const SizedBox(height: 10), + TextFormField( + //obscureText: true, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: 'Password', + labelStyle: TextStyle(color: Colors.white), + hintText: 'Enter your password', + iconColor: Colors.white, + focusColor: Color.fromARGB(100, 169, 0, 255), + hoverColor: Colors.blue, + prefixIconColor: Colors.white, + suffixIconColor: Colors.white, + ), + style: const TextStyle( + color: Colors.white, + ), + onChanged: (String? value) { + setPass(value); + debugPrint(value); + debugPrint("Password: $password"); + debugPrint("Confirm: $confirmPassword"); + }, + ), + const SizedBox(height: 10), + TextFormField( + //obscureText: true, + autovalidateMode: AutovalidateMode.always, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: 'Repeat password', + labelStyle: TextStyle(color: Colors.white), + hintText: 'Repeat your password', + iconColor: Colors.white, + focusColor: Color.fromARGB(100, 169, 0, 255), + hoverColor: Colors.blue, + prefixIconColor: Colors.white, + suffixIconColor: Colors.white, + ), + style: const TextStyle( + color: Colors.white, + ), + onChanged: (String? value) { + setConfirmPass(value); + debugPrint(password); + debugPrint(confirmPassword); + debugPrint(value); + }, + validator: (String? value) { + debugPrint(value); + debugPrint("Password: $password"); + debugPrint("Confirm: $confirmPassword"); + return (value != password) + ? 'Password does not match' + : null; + }, + ), + const SizedBox(height: 10), + Container( + padding: const EdgeInsets.all(2), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(5), + border: Border.all(color: Colors.black45), + color: const Color.fromARGB(100, 30, 30, 30), + ), + child: CheckboxListTile( + title: const Text('Enable root for user', + style: TextStyle(color: Colors.white)), + value: enableRoot, + onChanged: (bool? value) { + setState(value!); + }, + secondary: Container( + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + ), + padding: const EdgeInsets.fromLTRB(10, 10, 10, 13), + child: const Text( + '#', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ), + ), + ), + ), + ], + ), + ), + ), + ), + const SizedBox(width: 10), + ], + ), + ), + const SizedBox(width: 60), + Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Column( + children: [ + TextButton( + onPressed: () { + next(); + }, + child: const Text('Next'), + style: TextButton.styleFrom( + primary: Colors.white, + backgroundColor: const Color.fromARGB(255, 169, 0, 255), + minimumSize: const Size(80, 50), + padding: const EdgeInsets.all(10), + ), + ), + const SizedBox(height: 10), + ], + ), + const SizedBox(width: 30), + ], + ), + const SizedBox(height: 7) + ], + ), + ], + ); +} diff --git a/lib/main.dart b/lib/main.dart index 7d929e8..5cc6755 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:jade_gui/functions/welcome.dart'; import 'package:jade_gui/functions/locale.dart'; import 'package:jade_gui/functions/keyboard.dart'; import 'package:jade_gui/functions/keymap/variant.dart'; +import 'package:jade_gui/functions/users.dart'; void main() => runApp( const MaterialApp( @@ -23,6 +24,10 @@ class _JadeguiState extends State { int _selectedIndex = 0; bool nextpage = false; bool choseLayout = false; + bool enableRoot = false; + String password = ""; + String confirmPassword = ""; + String username = ""; void nextslide() { setState(() { _selectedIndex = _selectedIndex + 1; @@ -272,13 +277,42 @@ class _JadeguiState extends State { break; case 3: print("${getChosenLayout()} - ${getChosenVariant()}"); - widget = const Text( - 'Showing Timezone screen', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Color.fromARGB(255, 169, 0, 255), - ), + widget = users( + (value) { + setState(() { + enableRoot = value; + }); + }, + enableRoot, + (String? value) { + setState(() { + debugPrint(value); + if (value != null) { + password = value; + } + }); + debugPrint("here"); + debugPrint(password); + debugPrint(value); + }, + (value) { + setState(() { + confirmPassword = value; + }); + }, + password, + confirmPassword, + (value) { + setState(() { + username = value; + }); + }, + username, + () { + setState(() { + _selectedIndex = _selectedIndex + 1; + }); + }, ); break; case 4: