From 36c161cb55a4a779fc8983d4f38f7c82adf4cd3a Mon Sep 17 00:00:00 2001 From: juan Date: Thu, 24 Oct 2024 00:15:13 -0400 Subject: [PATCH] fix?? --- lib/login.dart | 160 +++++++++++++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 1 + 2 files changed, 161 insertions(+) create mode 100644 lib/login.dart diff --git a/lib/login.dart b/lib/login.dart new file mode 100644 index 0000000..55daed0 --- /dev/null +++ b/lib/login.dart @@ -0,0 +1,160 @@ +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; + +class AuthService { + Future isUserLoggedIn() async { + try { + var url = Uri.http('127.0.0.1:3001', 'is_logged_in'); + var response = await http.get(url); + print(response.body); + if (response.statusCode == 200) { + print('all good in the east!'); + List json = jsonDecode(response.body); + print(json[0]); + return true; + } + } catch (e) { + print(e); + } + return false; + } +} + +class LoginPage extends StatefulWidget { + const LoginPage({super.key}); + + @override + _LoginPageState createState() => _LoginPageState(); +} + +class _LoginPageState extends State { + final AuthService _authService = AuthService(); + // Controllers for capturing user input + final TextEditingController _emailController = TextEditingController(); + final TextEditingController _passwordController = TextEditingController(); + + // Key to identify the form + final _formKey = GlobalKey(); + + void checkLogin() async { + // try { + // var url = Uri.http('127.0.0.1:3001', 'is_logged_in'); + // var response = await http.get(url); + // print(response.body); + // if (response.statusCode == 200) { + // print('all good on the west'); + // } + // } catch (e) { + // print(e); + // } + bool isLoggedIn = await _authService.isUserLoggedIn(); + + } + + // Function to handle login action + void _handleLogin() { + if (_formKey.currentState!.validate()) { + // Perform login action (e.g., authenticate with backend) + String email = _emailController.text; + String password = _passwordController.text; + + // For demonstration, just print the values + print('Email: $email'); + print('Password: $password'); + + // Clear the input fields + _emailController.clear(); + _passwordController.clear(); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Login Page'), + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Form( + key: _formKey, + child: Align( + alignment: Alignment.centerLeft, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('Sign in to your email'), + SizedBox( + height: 5, + ), + // Email Field + Container( + width: 200, + child: TextFormField( + controller: _emailController, + decoration: const InputDecoration( + labelText: 'Email', + hintText: 'Enter your email', + helperMaxLines: 1, + ), + validator: (value) { + // Simple email validation + if (value == null || value.isEmpty) { + return 'Please enter your email'; + } + if (!RegExp(r'^\S+@\S+\.\S+$').hasMatch(value)) { + return 'Please enter a valid email address'; + } + return null; + }, + ), + ), + const SizedBox(height: 16.0), + // Password Field + Container( + width: 200, + child: TextFormField( + controller: _passwordController, + decoration: const InputDecoration( + labelText: 'Password', + hintText: 'Enter your password', + ), + obscureText: true, // Hide the password text + validator: (value) { + // Simple password validation + if (value == null || value.isEmpty) { + return 'Please enter your password'; + } + if (value.length < 6) { + return 'Password must be at least 6 characters long'; + } + return null; + }, + ), + ), + const SizedBox(height: 32.0), + // Login Button + SizedBox( + width: 200, + child: ElevatedButton( + onPressed: _handleLogin, + child: const Text('Login'), + ), + ), + SizedBox( + width: 200, + child: ElevatedButton( + onPressed: checkLogin, + child: const Text('checker'), + ), + ) + ], + ), + ), + ), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 391e473..a985a82 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -18,6 +18,7 @@ dependencies: english_words: ^4.0.0 provider: ^6.0.0 + intl: ^0.19.0 dev_dependencies: flutter_test: