created login form

main
Nilo Roberto C Paim 2023-08-27 20:09:47 -03:00
parent 30c69dd5a8
commit a231b8614d
5 changed files with 188 additions and 6 deletions

View File

@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class NCFormField extends StatelessWidget {
final String label;
final String value;
final bool? obscureText;
final void Function(String)? onChanged;
final String? Function(String?)? validator;
final List<TextInputFormatter>? inputFormatters;
const NCFormField({
super.key,
required this.label,
required this.value,
this.onChanged,
this.validator,
this.inputFormatters,
this.obscureText,
});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 80,
child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
initialValue: value,
validator: validator,
onChanged: onChanged,
inputFormatters: inputFormatters,
obscureText: obscureText ?? false,
decoration: InputDecoration(
labelText: label,
border: const OutlineInputBorder(),
),
),
);
}
}

View File

@ -1,20 +1,154 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:lixo/components/nc_base_page.dart'; import 'package:validatorless/validatorless.dart';
import 'package:velocity_x/velocity_x.dart';
class LoginPage extends StatelessWidget { // import 'package:velocity_x/velocity_x.dart';
import '../components/nc_form_field.dart';
// import '../stores/login_store.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key}); const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return const NcBasePage( // LoginStore store = VxState.store as LoginStore;
body: Center(
final formKey = GlobalKey<FormState>();
String email = '';
String password = '';
return Container(
color: const Color.fromRGBO(166, 0, 249, 1),
child: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text("Login Page"), Card(
elevation: 20,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: const BorderSide(
width: 1,
color: Colors.black,
),
),
child: Column(
children: [
const SizedBox(
height: 32.0,
),
"Login".text.xl5.bold.make(),
const SizedBox(
height: 32.0,
),
SizedBox(
width: MediaQuery.of(context).size.width / 3,
child: Form(
key: formKey,
child: Padding(
padding: const EdgeInsets.only(
left: 64.0,
right: 64,
bottom: 32,
),
child: Column(
children: [
NCFormField(
label: 'Email',
value: email,
validator: Validatorless.multiple(
[
Validatorless.email('Email inválido'),
Validatorless.required('Email é obrigatório'),
],
),
onChanged: (value) => email = value,
),
const SizedBox(
height: 16.0,
),
NCFormField(
label: 'Senha',
value: password,
obscureText: true,
validator: Validatorless.required('Senha é obrigatória'),
onChanged: (value) => password = value,
),
const SizedBox(
height: 32.0,
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromRGBO(166, 0, 249, 1),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
onPressed: () async {
//await verifyLogin(formKey, store, email, password);
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Entrar', style: TextStyle(fontSize: 24)),
),
),
],
),
),
),
),
],
),
),
], ],
), ),
), ),
); );
} }
/*
Future<void> verifyLogin(GlobalKey<FormState> formKey, LoginStore store, String email, String password) async {
processAuth(formKey, store, email, password);
}
Future<bool> processAuth(GlobalKey<FormState> formKey, LoginStore store, String email, String password) async {
Function? close;
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
store.email = email;
store.password = password;
try {
close = context.showLoading(
msg: '',
bgColor: Colors.transparent,
textSize: 20,
);
await store.login();
close();
if (store.isLogged) {
return true;
}
if (store.message != "") {
SnackBarService.showSnackBar(content: store.message!, error: true);
return false;
}
} catch (e) {
close!();
SnackBarService.showSnackBar(content: e.toString().replaceAll("Exception: ", ""), error: true);
return false;
}
}
return false;
}
*/
} }

View File

@ -15,7 +15,7 @@ final router = GoRouter(
GoRoute( GoRoute(
name: 'login', name: 'login',
path: '/login', path: '/login',
builder: (context, state) => const LoginPage(), builder: (context, state) => LoginPage(),
), ),
GoRoute( GoRoute(
name: 'register', name: 'register',

View File

@ -205,6 +205,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.6.0" version: "0.6.0"
validatorless:
dependency: "direct main"
description:
name: validatorless
sha256: ddb46df636114b3322d289489164cac309767b157191ba43c7ad49b28c2b57c7
url: "https://pub.dev"
source: hosted
version: "1.2.3"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:

View File

@ -37,6 +37,7 @@ dependencies:
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
velocity_x: ^4.1.1 velocity_x: ^4.1.1
go_router: ^10.1.0 go_router: ^10.1.0
validatorless: ^1.2.3
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: