T&C #1
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import 'package:kmobile/app.dart';
|
||||
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
||||
import 'package:kmobile/features/auth/screens/set_password_screen.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import '../../../app.dart';
|
||||
import 'package:kmobile/features/auth/screens/tnc_required_screen.dart';
|
||||
import 'package:kmobile/widgets/tnc_dialog.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../controllers/auth_cubit.dart';
|
||||
import '../controllers/auth_state.dart';
|
||||
|
||||
@@ -23,7 +22,6 @@ class LoginScreenState extends State<LoginScreen>
|
||||
final _customerNumberController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
bool _obscurePassword = true;
|
||||
//bool _showWelcome = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -44,36 +42,51 @@ class LoginScreenState extends State<LoginScreen>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
// appBar: AppBar(title: const Text('Login')),
|
||||
body: BlocConsumer<AuthCubit, AuthState>(
|
||||
listener: (context, state) async {
|
||||
if (state is Authenticated) {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final mpin = await storage.read('mpin');
|
||||
if (!context.mounted) return;
|
||||
if (mpin == null) {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) {
|
||||
Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const NavigationScaffold(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
);
|
||||
if (state is ShowTncDialog) {
|
||||
// The dialog now returns a boolean for the 'disagree' case,
|
||||
// or it completes when the 'proceed' action is finished.
|
||||
final agreed = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (dialogContext) => TncDialog(
|
||||
onProceed: () async {
|
||||
// This function is passed to the dialog.
|
||||
// It calls the cubit and completes when the cubit's work is done.
|
||||
await context
|
||||
.read<AuthCubit>()
|
||||
.onTncDialogResult(true, state.authToken, state.users);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
// If 'agreed' is false, it means the user clicked 'Disagree'.
|
||||
if (agreed == false) {
|
||||
if (!context.mounted) return;
|
||||
context
|
||||
.read<AuthCubit>()
|
||||
.onTncDialogResult(false, state.authToken, state.users);
|
||||
}
|
||||
} else if (state is NavigateToTncRequiredScreen) {
|
||||
Navigator.of(context).pushNamed(TncRequiredScreen.routeName);
|
||||
} else if (state is NavigateToMpinSetupScreen) {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
onCompleted: (_) {
|
||||
Navigator.of(context, rootNavigator: true).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (state is NavigateToDashboardScreen) {
|
||||
Navigator.of(context).pushReplacement(
|
||||
MaterialPageRoute(builder: (_) => const NavigationScaffold()),
|
||||
);
|
||||
} else if (state is AuthError) {
|
||||
if (state.message == 'MIGRATED_USER_HAS_NO_PASSWORD') {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
@@ -87,6 +100,7 @@ class LoginScreenState extends State<LoginScreen>
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
// The commented out section is removed for clarity, the logic is now above.
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Form(
|
||||
@@ -107,7 +121,6 @@ class LoginScreenState extends State<LoginScreen>
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Title
|
||||
Text(
|
||||
AppLocalizations.of(context).kccb,
|
||||
style: TextStyle(
|
||||
@@ -117,12 +130,10 @@ class LoginScreenState extends State<LoginScreen>
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 48),
|
||||
|
||||
TextFormField(
|
||||
controller: _customerNumberController,
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).customerNumber,
|
||||
// prefixIcon: Icon(Icons.person),
|
||||
border: const OutlineInputBorder(),
|
||||
isDense: true,
|
||||
filled: true,
|
||||
@@ -147,7 +158,6 @@ class LoginScreenState extends State<LoginScreen>
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Password
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
@@ -189,7 +199,6 @@ class LoginScreenState extends State<LoginScreen>
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
//Login Button
|
||||
SizedBox(
|
||||
width: 250,
|
||||
child: ElevatedButton(
|
||||
@@ -216,40 +225,7 @@ class LoginScreenState extends State<LoginScreen>
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// const Expanded(child: Divider()),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
// child: Text(AppLocalizations.of(context).or),
|
||||
// ),
|
||||
// //const Expanded(child: Divider()),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// Register Button
|
||||
// SizedBox(
|
||||
// width: 250,
|
||||
// child: ElevatedButton(
|
||||
// //disable until registration is implemented
|
||||
// onPressed: null,
|
||||
// style: OutlinedButton.styleFrom(
|
||||
// shape: const StadiumBorder(),
|
||||
// padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
// backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
// foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
// ),
|
||||
// child: Text(AppLocalizations.of(context).register,
|
||||
// style: TextStyle(color: Theme.of(context).colorScheme.onPrimary),),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user