Added components to article

This commit is contained in:
Dennis Nemec
2026-05-11 17:12:05 +02:00
parent 2470299a10
commit ac6b03227d
37 changed files with 1189 additions and 513 deletions

View File

@ -25,6 +25,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
try {
debugPrint("Retrieve user information");
emit(Authenticating());
var response = await service.getUserinfo(event.sessionId);
var state = Authenticated(sessionId: event.sessionId, user: response);
locator.registerSingleton<Authenticated>(state);
@ -34,6 +35,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
debugPrint(err.toString());
debugPrint(st.toString());
emit(Unauthenticated());
operationBloc.add(
FailOperation(
message: "Login war nicht erfolgreich. Probieren Sie es erneut.",

View File

@ -7,6 +7,10 @@ class Unauthenticated extends AuthState {
Unauthenticated({this.sessionExpired = false});
}
/// Transient state while [SetAuthenticatedEvent] is being processed and the
/// user info is being fetched from the server.
class Authenticating extends AuthState {}
class Authenticated extends AuthState {
User user;
String sessionId;

View File

@ -3,7 +3,9 @@ import 'package:app_links/app_links.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_bloc.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_event.dart';
import 'package:hl_lieferservice/feature/authentication/bloc/auth_state.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:hl_lieferservice/util.dart';
import 'dart:async';
class LoginPage extends StatefulWidget {
@ -60,9 +62,7 @@ class _LoginPageState extends State<LoginPage> {
// Small delay to ensure listener is ready
await Future.delayed(const Duration(milliseconds: 500));
debugPrint("🔵 Opening browser to: http://localhost:3000/login");
final loginUrl = Uri.parse('http://192.168.1.9:3000/login');
final loginUrl = Uri.parse('${getConfig().backendUrl}/login');
final launched = await launchUrl(
loginUrl,
mode: LaunchMode.externalApplication,
@ -176,17 +176,30 @@ class _LoginPageState extends State<LoginPage> {
children: [
Padding(
padding: const EdgeInsets.only(top: 15, bottom: 15),
child: _isLoading
? const Column(
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('Warte auf Login...'),
],
)
: OutlinedButton(
onPressed: _onPressLogin,
child: const Text("Anmelden mit Holzleitner Login"),
child: BlocBuilder<AuthBloc, AuthState>(
builder: (context, authState) {
final isBusy =
_isLoading || authState is Authenticating;
if (!isBusy) {
return OutlinedButton(
onPressed: _onPressLogin,
child: const Text(
"Anmelden mit Holzleitner Login",
),
);
}
return Column(
children: [
const CircularProgressIndicator(),
const SizedBox(height: 16),
Text(
authState is Authenticating
? 'Anmeldung wird abgeschlossen…'
: 'Warte auf Login...',
),
],
);
},
),
),
],