this is the main of my application "import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'login_logic.dart';
import 'signup_logic.dart';


void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Bienvenue à Attendance Manager!',
      builder: EasyLoading.init(),
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: LoginSignupPage(),
    );
  }
}

class LoginSignupPage extends StatefulWidget {
  @override
  _LoginSignupPageState createState() => _LoginSignupPageState();
}

class _LoginSignupPageState extends State<LoginSignupPage> {
  bool _isLoginForm = true;
  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _passwordController = TextEditingController();
  final TextEditingController _usernameController = TextEditingController();
  String _selectedRole = 'Admin';
  List<String> _roleOptions = ['Admin', 'Etudiant', 'Enseignant'];
  final TextEditingController _matriculeController = TextEditingController();

  void _toggleFormMode() {
    setState(() {
      _isLoginForm = !_isLoginForm;
    });
  }

  final loginLogic = LoginLogic();

  void _login() async {
    print('_login method called');
    try {
      final response = await loginLogic.login(
        _usernameController.text,
        _passwordController.text,
      );
      await loginLogic.handleResponse(context, response);
    } catch (e) {
      // Handle any network or server errors
    }
  }

  final _signupLogic = SignupLogic();

  Future<void> _signup() async {
    try {
      final response = await _signupLogic.registerUser(
        context,
        _emailController.text,
        _usernameController.text,
        _passwordController.text,
        _selectedRole,
        _matriculeController.text,
      );
      if (response.statusCode == 200 || response.statusCode == 201) {
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text('Compte créé avec succès'),
              actions: <Widget>[
                ElevatedButton(
                  child: Text('OK'),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                ),
              ],
            );
          },
        );
        print('Registration success');
      } else {
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text('Erreur'),
              content: Text('Veuillez remplir tous les champs et réessayez'),
              actions: <Widget>[
                ElevatedButton(
                  child: Text('OK'),
                  onPressed: () {
                    Navigator.of(context).pop();
                  },
                ),
              ],
            );
          },
        );
        print('Received signup response with status code: ${response.statusCode}');
      }
    } catch (e) {
      // handle network or server errors
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(_isLoginForm ? 'Se connecter' : 'Créer un compte'),
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              SizedBox(height: 48.0),
              if (_isLoginForm)
                TextFormField(
                  controller: _usernameController,
                  decoration: InputDecoration(
                    labelText: "Nom d'utilisateur",
                    hintText: "Entrez votre nom d'utilisateur",
                  ),
                ),
              if (!_isLoginForm)
                TextFormField(
                  controller: _emailController,
                  decoration: InputDecoration(
                    labelText: 'Email',
                    hintText: 'Entrez votre addresse e-mail',
                  ),
                ),
              SizedBox(height: 16.0),
              TextFormField(
                controller: _passwordController,
                obscureText: true,
                decoration: InputDecoration(
                  labelText: 'Mot de passe',
                  hintText: 'Entrez votre mot de passe',
                ),
              ),
              SizedBox(height: 16.0),
              if (!_isLoginForm)
                TextFormField(
                  controller: _usernameController,
                  decoration: InputDecoration(
                    labelText: "nom d'utilisateur",
                    hintText: "Entrez votre nom d'utilisateur",
                  ),
                ),
              SizedBox(height: 16.0),
              if (!_isLoginForm)
                DropdownButtonFormField<String>(
                  decoration: InputDecoration(
                    labelText: 'Role',
                    hintText: 'Sélectionnez votre rôle',
                  ),
                  value: _selectedRole,
                  onChanged: (String? value) {
                    setState(() {
                      _selectedRole = value!;
                    });
                  },
                  items: _roleOptions.map<DropdownMenuItem<String>>((String value) {
                    return DropdownMenuItem<String>(
                      value: value,
                      child: Text(value),
                    );
                  }).toList(),
                ),
              SizedBox(height: 16.0),
              if (!_isLoginForm)
                TextFormField(
                  controller: _matriculeController,
                  decoration: InputDecoration(
                    labelText: 'Matricule',
                    hintText: 'Entrez votre matricule',
                  ),
                ),
              SizedBox(height: 48.0),
              ElevatedButton(
                child: Text(_isLoginForm ? 'Se connecter' : 'Créer un compte'),
                onPressed: () {
                  print('Login button pressed');
                  if (_isLoginForm) {
                    _login();
                  } else {
                    _signup();
                  }
                },
              ),
              TextButton(
                child: Text(_isLoginForm
                    ? 'Ou créer un compte'
                    : 'Vouz avez un compte? vous pouvez vous connecter'),
                onPressed: _toggleFormMode,
              ),
            ],
          ),
        ),
      ),
    );
  }
}" using this "

import 'dart:convert';
import 'package:attendance_app/profile_admin_screen.dart';
import 'package:attendance_app/profile_enseignant_screen.dart';
import 'package:attendance_app/profile_etudiant_screen.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'constants.dart';

class LoginLogic {
  static const String _jwtKey = 'watchme';
  static String get jwtKey => _jwtKey;
  static final _storage = FlutterSecureStorage();
  static FlutterSecureStorage get storage => _storage;

  Future<http.Response> login(String email, String password) async {
    if (email.isEmpty && password.isEmpty) {
      return Future.error('Veuillez remplir les champs de l\'identifiant et du mot de passe');
    } else if (email.isEmpty) {
      return Future.error('Veuillez remplir le champ de l\'identifiant');
    } else if (password.isEmpty) {
      return Future.error('Veuillez remplir le champ du mot de passe');
    }

    print('Starting login request with email: $email and password: $password');

    final data = {
      'userName': email,
      'password': password,
    };
    final jsonData = jsonEncode(data);

    try {
      final response = await http.post(
        Uri.parse('$endpointUrl/login'),
        headers: {'Content-Type': 'application/json'},
        body: jsonData,
      ).timeout(Duration(seconds: 5));

      print('Received login response with status code: ${response.statusCode}');
      return response;
    } on TimeoutException catch (e) {
      return Future.error('La requête a expiré');
    } catch (e) {
      return Future.error('Échec de la connexion');
    }
  }

  Future<void> handleResponse(BuildContext context, http.Response response) async {
    if (response.statusCode == 200) {
      final responseBody = json.decode(response.body);
      final token = responseBody['token'];

      try {
        await _storage.write(key: _jwtKey, value: token);
      } catch (e) {
        print('Error writing token to storage: $e');
      }

      print('Token generated and written to storage: $token');

      String? role = await getUserRole();
      if (role != null) {
        if (role.toLowerCase() == 'etudiant') {
          Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => ProfileEtudiantScreen()));
        } else if (role.toLowerCase() == 'enseignant') {
          Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => ProfileEnseignantScreen()));
        } else if (role.toLowerCase() == 'administrateur') {
          Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (_) => ProfileAdminScreen()));
        } else {
          print('Invalid role: $role');
        }
      } else {
        print('Role not found in response');
      }
    } else if (response.statusCode == 401) {
      final responseBody = json.decode(response.body);
      var message = responseBody['message'];

      if (message == null) {
        message = 'Une erreur s\'est produite lors de la connexion.';
      } else if (message == 'Veuillez remplir les champs de l\'identifiant et du mot de passe') {
        message = 'Veuillez remplir les champs de l\'identifiant et du mot de passe';
      } else if (message == 'Veuillez remplir le champ de l\'identifiant') {
        message = 'Veuillez remplir le champ de l\'identifiant';
      } else if (message == 'Veuillez remplir le champ du mot de passe') {
        message = 'Veuillez remplir le champ du mot de passe';
      }

      print('Response message: $message');
      showDialog(
        context: context,
        builder: (_) => AlertDialog(
          title: Text('Erreur'),
          content: Text(message),
          actions: [
            TextButton(
              onPressed: () => Navigator.of(context).pop(),
              child: Text('OK'),
            ),
          ],
        ),
      );
    } else {
      print('Response status code: ${response.statusCode}');
      showDialog(
        context: context,
        builder: (_) => AlertDialog(
          title: Text('Erreur'),
          content: Text('Une erreur s\'est produite lors de la connexion.'),
          actions: [
            TextButton(
              onPressed: () => Navigator.of(context).pop(),
              child: Text('OK'),
            ),
          ],
        ),
      );
    }
  }

  static Future<String?> getToken() async {
    try {
      final token = await _storage.read(key: _jwtKey);
      return token;
    } catch (e) {
      print('Error reading token from storage: $e');
      return null;
    }
  }

  Future<String?> getUserRole() async {
    final token = await getToken();
    if (token != null) {
      try {
        final response = await http.get(
          Uri.parse('$endpointUrl/getusernamerole'),
          headers: {'Authorization': 'Bearer $token'},
        );

        if (response.statusCode == 200) {
          final responseBody = json.decode(response.body);
          final role = responseBody['role'];
          return role;
        } else {
          print('Failed to retrieve user role');
          return null;
        }
      } catch (e) {
        print('Error fetching user role: $e');
        return null;
      }
    } else {
      print('No token found');
      return null;
    }
  }
}

" and this "import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'constants.dart' as Constants;

class SignupLogic {


  Future<http.Response> registerUser(BuildContext context,String email, String username, String password, String role, String matricule) async {
    final url = Uri.parse('${Constants.endpointUrl}/register');
    final headers = <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    };
    final body = jsonEncode(<String, String>{
      'email': email,
      'username': username,
      'password': password,
      'role': role,
      'matricule': matricule,
    });
    final response = await http.post(url, headers: headers, body: body);
    print('Received Registration response with status code: ${response.statusCode}');

    if (response.statusCode == 201) {
      Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false);
      return response;
    } else {
      // Handle errors
      print('Received Registration response with status code: ${response.statusCode}');
      return response;
    }
  }
}

", I want to encapsulate as maximum as possible the login and signup logics in their files while keeping the main less dense, can you suggest the most efficient, concise  implementations of the 3 pieces of code while providing me with the full versions of those 3 files ?