feat: check for correct version

This commit is contained in:
alzalia1 2025-08-13 14:16:34 +02:00
parent b751d93be6
commit 8e379241ee
6 changed files with 169 additions and 92 deletions

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:seshat/routing/routes.dart';
import 'package:seshat/ui/auth/viewmodel/login_view_model.dart';
import 'package:seshat/ui/core/ui/await_loading.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key, required this.viewModel});
@ -40,100 +41,104 @@ class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListenableBuilder(
listenable: widget.viewModel.login,
builder: (context, child) {
return Form(
key: _formKey,
child: SingleChildScrollView(
child: SizedBox(
width: 300,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Bienvenue", style: TextStyle(fontSize: 40)),
SizedBox(height: 50),
TextFormField(
decoration: InputDecoration(
labelText: "Identifiant de section",
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return "Veuillez entrer un identifiant";
}
return null;
},
onSaved: (newValue) {
username = newValue!;
},
),
SizedBox(height: 10),
TextFormField(
decoration: InputDecoration(
labelText: "Mot de passe",
border: OutlineInputBorder(),
suffixIcon: IconButton(
onPressed: () {
setState(() {
hidePassword = !hidePassword;
});
},
icon: Icon(
(hidePassword)
? Icons.visibility
: Icons.visibility_off,
),
),
),
obscureText: hidePassword,
enableSuggestions: false,
autocorrect: false,
validator: (value) {
if (value == null || value.isEmpty) {
return "Veuillez entrer un mot de passe";
}
return null;
},
onSaved: (newValue) {
password = newValue!;
},
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
_formKey.currentState!.validate();
_formKey.currentState!.save();
widget.viewModel.login.execute((username, password));
},
child: Text("Valider"),
),
],
),
body: ListenableBuilder(
listenable: widget.viewModel,
builder: (context, child) => switch (widget.viewModel.isLoaded) {
false => AwaitLoading(),
true => switch (widget.viewModel.isUpToDate) {
false => Center(
child: SizedBox(
width: 300,
child: Text(
"L'application que vous utilisez n'est pas à jour. Si aucune mise à jour n'est disponible, contactez dev@ueauvergne.fr",
),
),
);
),
true => Center(
child: ListenableBuilder(
listenable: widget.viewModel.login,
builder: (context, child) {
return Form(
key: _formKey,
child: SingleChildScrollView(
child: SizedBox(
width: 300,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Bienvenue", style: TextStyle(fontSize: 40)),
SizedBox(height: 50),
TextFormField(
decoration: InputDecoration(
labelText: "Identifiant de section",
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return "Veuillez entrer un identifiant";
}
return null;
},
onSaved: (newValue) {
username = newValue!;
},
),
SizedBox(height: 10),
TextFormField(
decoration: InputDecoration(
labelText: "Mot de passe",
border: OutlineInputBorder(),
suffixIcon: IconButton(
onPressed: () {
setState(() {
hidePassword = !hidePassword;
});
},
icon: Icon(
(hidePassword)
? Icons.visibility
: Icons.visibility_off,
),
),
),
obscureText: hidePassword,
enableSuggestions: false,
autocorrect: false,
validator: (value) {
if (value == null || value.isEmpty) {
return "Veuillez entrer un mot de passe";
}
return null;
},
onSaved: (newValue) {
password = newValue!;
},
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
_formKey.currentState!.save();
widget.viewModel.login.execute((
username,
password,
));
}
},
child: Text("Valider"),
),
],
),
),
),
);
},
),
),
},
),
// TextField(controller: _username),
// TextField(controller: _password),
// ListenableBuilder(
// listenable: widget.viewModel.login,
// builder: (context, child) {
// return FilledButton(
// onPressed: () {
// widget.viewModel.login.execute((
// _username.value.text,
// _password.value.text,
// ));
// },
// child: Text("Connexion"),
// );
// },
// ),
},
),
);
}