api integration

This commit is contained in:
2025-06-02 10:29:32 +05:30
parent 7c9e089c62
commit 805aa5e015
289 changed files with 40017 additions and 1082 deletions

View File

@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart';
import 'package:kmobile/di/injection.dart';
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
import 'package:kmobile/security/secure_storage.dart';
import '../../../app.dart';
import '../controllers/auth_cubit.dart';
import '../controllers/auth_state.dart';
@@ -27,16 +28,12 @@ class LoginScreenState extends State<LoginScreen> {
}
void _submitForm() {
// if (_formKey.currentState!.validate()) {
// context.read<AuthCubit>().login(
// _customerNumberController.text.trim(),
// _passwordController.text,
// );
// }
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const MPinScreen()),
);
if (_formKey.currentState!.validate()) {
context.read<AuthCubit>().login(
_customerNumberController.text.trim(),
_passwordController.text,
);
}
}
@override
@@ -44,11 +41,30 @@ class LoginScreenState extends State<LoginScreen> {
return Scaffold(
// appBar: AppBar(title: const Text('Login')),
body: BlocConsumer<AuthCubit, AuthState>(
listener: (context, state) {
listener: (context, state) async {
if (state is Authenticated) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const NavigationScaffold()),
);
final storage = getIt<SecureStorage>();
final mpin = await storage.read('mpin');
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()),
);
}
} else if (state is AuthError) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.message)),
@@ -62,18 +78,23 @@ class LoginScreenState extends State<LoginScreen> {
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Bank logo or app branding
SvgPicture.asset('assets/images/kccb_logo.svg', width: 100, height: 100,),
Image.asset('assets/images/logo.png', width: 150, height: 150,
errorBuilder: (context, error, stackTrace) {
return const Icon(Icons.account_balance,
size: 100, color: Colors.blue);
}),
const SizedBox(height: 16),
// Title
const Text(
'KCCB',
style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: Colors.blue),
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: Colors.blue),
),
const SizedBox(height: 48),
TextFormField(
controller: _customerNumberController,
decoration: const InputDecoration(
@@ -99,8 +120,8 @@ class LoginScreenState extends State<LoginScreen> {
return null;
},
),
const SizedBox(height: 16),
const SizedBox(height: 24),
TextFormField(
controller: _passwordController,
decoration: InputDecoration(
@@ -118,8 +139,8 @@ class LoginScreenState extends State<LoginScreen> {
),
suffixIcon: IconButton(
icon: Icon(
_obscurePassword
? Icons.visibility
_obscurePassword
? Icons.visibility
: Icons.visibility_off,
),
onPressed: () {
@@ -138,40 +159,29 @@ class LoginScreenState extends State<LoginScreen> {
return null;
},
),
// Align(
// alignment: Alignment.centerRight,
// child: TextButton(
// onPressed: () {
// // Navigate to forgot password screen
// },
// child: const Text('Forgot Password?'),
// ),
// ),
const SizedBox(height: 24),
SizedBox(
width: 250,
child: ElevatedButton(
onPressed: state is AuthLoading ? null : _submitForm,
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.white,
foregroundColor: Colors.blueAccent,
side: const BorderSide(color: Colors.black, width: 1),
elevation: 0
),
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.white,
foregroundColor: Colors.blueAccent,
side: const BorderSide(color: Colors.black, width: 1),
elevation: 0),
child: state is AuthLoading
? const CircularProgressIndicator()
: const Text('Login', style: TextStyle(fontSize: 16),),
: const Text(
'Login',
style: TextStyle(fontSize: 16),
),
),
),
const SizedBox(height: 15),
// OR Divider
const Padding(
padding: EdgeInsets.symmetric(vertical: 16),
child: Row(
@@ -185,26 +195,22 @@ class LoginScreenState extends State<LoginScreen> {
],
),
),
const SizedBox(height: 25),
// Register Button
SizedBox(
width: 250,
child: ElevatedButton(
onPressed: () {
// Handle register
},
//disable until registration is implemented
onPressed: null,
style: OutlinedButton.styleFrom(
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.lightBlue[100],
foregroundColor: Colors.black
),
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.lightBlue[100],
foregroundColor: Colors.black),
child: const Text('Register'),
),
),
],
),
),
@@ -213,4 +219,4 @@ class LoginScreenState extends State<LoginScreen> {
),
);
}
}
}