Initial draft
This commit is contained in:
25
lib/feature/authentication/presentation/login_enforcer.dart
Normal file
25
lib/feature/authentication/presentation/login_enforcer.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/presentation/login_page.dart';
|
||||
|
||||
import '../bloc/auth_bloc.dart';
|
||||
import '../bloc/auth_state.dart';
|
||||
|
||||
class LoginEnforcer extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const LoginEnforcer({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is Authenticated) {
|
||||
return child;
|
||||
}
|
||||
|
||||
return LoginPage();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
121
lib/feature/authentication/presentation/login_page.dart
Normal file
121
lib/feature/authentication/presentation/login_page.dart
Normal file
@ -0,0 +1,121 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hl_lieferservice/feature/authentication/bloc/auth_event.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/presentation/operation_view_enforcer.dart';
|
||||
|
||||
import '../bloc/auth_bloc.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
const LoginPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _LoginPageState();
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
final _loginFormKey = GlobalKey<FormState>();
|
||||
final TextEditingController _passwordEditingController =
|
||||
TextEditingController();
|
||||
final TextEditingController _userIdEditingController =
|
||||
TextEditingController();
|
||||
|
||||
bool _isEmpty = false;
|
||||
|
||||
void onChanged(String value) {
|
||||
setState(() {
|
||||
_isEmpty = value.isEmpty;
|
||||
});
|
||||
}
|
||||
|
||||
void _onPressLogin(BuildContext context) async {
|
||||
if (context.mounted) {
|
||||
context.read<AuthBloc>().add(
|
||||
Authenticate(
|
||||
username: _userIdEditingController.text,
|
||||
password: _passwordEditingController.text,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(50),
|
||||
child: Column(
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/holzleitner_Logo_2017_RZ_transparent.png",
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Text(
|
||||
"Auslieferservice",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Form(
|
||||
key: _loginFormKey,
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: 0.8,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Personalnummer",
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
),
|
||||
),
|
||||
),
|
||||
controller: _userIdEditingController,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: "Passwort",
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10.0)),
|
||||
),
|
||||
),
|
||||
controller: _passwordEditingController,
|
||||
obscureText: true,
|
||||
onChanged: onChanged,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 15, bottom: 15),
|
||||
child: OutlinedButton(
|
||||
onPressed:
|
||||
!_isEmpty ? () => _onPressLogin(context) : null,
|
||||
child: const Text("Anmelden"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user