added 3 screen mod to login
This commit is contained in:
@@ -1,103 +1,24 @@
|
||||
// lib/views/login_screen.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tm_app/core/routes/app_routes.dart';
|
||||
import 'package:tm_app/core/utils/display_size_detector.dart';
|
||||
import 'package:tm_app/views/login/login_desktop_screen.dart';
|
||||
import 'package:tm_app/views/login/login_mobile_screen.dart';
|
||||
import 'package:tm_app/views/login/login_tablet_screen.dart';
|
||||
|
||||
import '../../core/constants/assets.dart';
|
||||
import '../../core/constants/strings.dart';
|
||||
import '../../core/utils/size_config.dart';
|
||||
import 'widgets/widgets.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
class LoginScreen extends StatelessWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
final _usernameController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
|
||||
final _usernameFocus = FocusNode();
|
||||
final _passwordFocus = FocusNode();
|
||||
|
||||
bool _obscurePassword = true;
|
||||
|
||||
bool get _isLoginEnabled =>
|
||||
_usernameController.text.isNotEmpty &&
|
||||
_passwordController.text.isNotEmpty;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_usernameController.addListener(_updateState);
|
||||
_passwordController.addListener(_updateState);
|
||||
_usernameFocus.addListener(_updateState);
|
||||
_passwordFocus.addListener(_updateState);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameController.dispose();
|
||||
_passwordController.dispose();
|
||||
_usernameFocus.dispose();
|
||||
_passwordFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _updateState() => setState(() {});
|
||||
|
||||
void _togglePasswordVisibility() =>
|
||||
setState(() => _obscurePassword = !_obscurePassword);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SizeConfig.init(context);
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const LoginLogo(),
|
||||
SizedBox(height: 32.0.h()),
|
||||
const LoginTitle(),
|
||||
SizedBox(height: 32.0.h()),
|
||||
LoginTextField(
|
||||
controller: _usernameController,
|
||||
focusNode: _usernameFocus,
|
||||
label: AppStrings.usernameLabel,
|
||||
iconPath: AssetsManager.userIcon,
|
||||
),
|
||||
final displaySize = MediaQuery.of(context).size.displaySize;
|
||||
|
||||
SizedBox(height: 16.0.h()),
|
||||
|
||||
LoginTextField(
|
||||
controller: _passwordController,
|
||||
focusNode: _passwordFocus,
|
||||
label: AppStrings.passwordLabel,
|
||||
iconPath: AssetsManager.passwordIcon,
|
||||
isPassword: true,
|
||||
obscureText: _obscurePassword,
|
||||
onToggleVisibility: _togglePasswordVisibility,
|
||||
),
|
||||
|
||||
SizedBox(height: 32.0.h()),
|
||||
BaseButton(
|
||||
isEnabled: _isLoginEnabled,
|
||||
onPressed:
|
||||
_isLoginEnabled
|
||||
? () {
|
||||
HomeRouteData().go(context);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
switch (displaySize) {
|
||||
case DisplaySize.large:
|
||||
case DisplaySize.medium:
|
||||
return const LoginDesktopScreen();
|
||||
case DisplaySize.small:
|
||||
return const LoginTabletScreen();
|
||||
case DisplaySize.extraSmall:
|
||||
return const LoginMobileScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user