Login API
This commit is contained in:
parent
bf492cbac2
commit
288d3caa9f
@ -1,17 +1,13 @@
|
||||
import 'package:cheminova/provider/collect_kyc_provider.dart';
|
||||
import 'package:cheminova/screens/Attendance_success.dart';
|
||||
import 'package:cheminova/screens/forgot_password_screen.dart';
|
||||
import 'package:cheminova/screens/login_screen.dart';
|
||||
import 'package:cheminova/screens/mark_attendence_screen.dart';
|
||||
import 'package:cheminova/screens/on_leave_screen.dart';
|
||||
import 'package:cheminova/provider/user_provider.dart';
|
||||
import 'package:cheminova/screens/splash_screen.dart';
|
||||
import 'package:cheminova/services/snackbar_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MultiProvider(providers: [
|
||||
ChangeNotifierProvider(create: (context) => CollectKycProvider())
|
||||
ChangeNotifierProvider(create: (context) => CollectKycProvider()),
|
||||
ChangeNotifierProvider(create: (_) => UserProvider()),
|
||||
], child: const MyApp()));
|
||||
}
|
||||
|
||||
|
26
lib/models/user_model.dart
Normal file
26
lib/models/user_model.dart
Normal file
@ -0,0 +1,26 @@
|
||||
class UserModel {
|
||||
String id;
|
||||
String name;
|
||||
String email;
|
||||
String uniqueId;
|
||||
bool isVerified;
|
||||
|
||||
UserModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.email,
|
||||
required this.uniqueId,
|
||||
required this.isVerified,
|
||||
});
|
||||
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
id: json['_id'],
|
||||
name: json['name'],
|
||||
email: json['email'],
|
||||
uniqueId: json['uniqueId'],
|
||||
isVerified: json['isVerified'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,10 @@ class LoginProvider extends ChangeNotifier {
|
||||
Future<(bool, String)> login() async {
|
||||
setLoading(true);
|
||||
try {
|
||||
Response response = await _apiClient.post(ApiUrls.loginUrl,
|
||||
data: {'email': emailController.text.trim(), 'password': passwordController.text.trim()});
|
||||
Response response = await _apiClient.post(ApiUrls.loginUrl, data: {
|
||||
'email': emailController.text.trim(),
|
||||
'password': passwordController.text.trim()
|
||||
});
|
||||
setLoading(false);
|
||||
if (response.statusCode == 200) {
|
||||
await _storageService.write(
|
||||
@ -33,9 +35,22 @@ class LoginProvider extends ChangeNotifier {
|
||||
} else {
|
||||
return (false, response.data['message'].toString());
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
setLoading(false);
|
||||
|
||||
if (e.response?.data is Map<String, dynamic>) {
|
||||
return (
|
||||
false,
|
||||
e.response?.data['message'].toString() ?? 'something went wrong'
|
||||
);
|
||||
} else if (e.response?.data is String) {
|
||||
return (false, e.response?.data.toString() ?? 'something went wrong');
|
||||
} else {
|
||||
return (false, 'something went wrong');
|
||||
}
|
||||
} catch (e) {
|
||||
setLoading(false);
|
||||
return (false, 'Something want wrong');
|
||||
return (false, 'something went wrong');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
48
lib/provider/user_provider.dart
Normal file
48
lib/provider/user_provider.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'package:cheminova/models/user_model.dart';
|
||||
import 'package:cheminova/services/api_client.dart';
|
||||
import 'package:cheminova/services/api_urls.dart';
|
||||
import 'package:cheminova/services/secure__storage_service.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class UserProvider extends ChangeNotifier {
|
||||
final _apiClient = ApiClient();
|
||||
|
||||
UserModel? _user;
|
||||
bool _isLoading = false;
|
||||
|
||||
UserModel? get user => _user;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
void setLoading(bool loading) {
|
||||
_isLoading = loading;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> fetchUserProfile() async {
|
||||
setLoading(true);
|
||||
try {
|
||||
Response response = await _apiClient.get(
|
||||
ApiUrls.profileUrl,
|
||||
);
|
||||
setLoading(false);
|
||||
if (response.statusCode == 200) {
|
||||
final data = response.data['myData'];
|
||||
await SecureStorageService().write(key: 'user', value: data.toString());
|
||||
_user = UserModel.fromJson(data);
|
||||
|
||||
notifyListeners();
|
||||
} else {
|
||||
throw Exception('Failed to load user profile');
|
||||
}
|
||||
} catch (e) {
|
||||
setLoading(false);
|
||||
throw Exception('Failed to load user profile: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> clearUserProfile() async {
|
||||
_user = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
import 'package:cheminova/provider/login_provider.dart';
|
||||
import 'package:cheminova/screens/password_change_screen.dart';
|
||||
import 'package:cheminova/services/api_client.dart';
|
||||
import 'package:cheminova/services/api_urls.dart';
|
||||
import 'package:cheminova/widgets/common_app_bar.dart';
|
||||
import 'package:cheminova/widgets/common_background.dart';
|
||||
import 'package:cheminova/widgets/common_elevated_button.dart';
|
||||
import 'package:cheminova/widgets/common_text_form_field.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../widgets/common_drawer.dart';
|
||||
|
||||
class ChangePasswordPage extends StatefulWidget {
|
||||
@ -19,17 +19,67 @@ class ChangePasswordPage extends StatefulWidget {
|
||||
class _ChangePasswordPageState extends State<ChangePasswordPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
final _oldPasswordController = TextEditingController();
|
||||
final _newPasswordController = TextEditingController();
|
||||
final _confirmPasswordController = TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
|
||||
Future<(bool, String)> _changePassword() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
final apiClient = ApiClient();
|
||||
|
||||
Response response =
|
||||
await apiClient.put(ApiUrls.changePasswordUrl, data: {
|
||||
'oldPassword': _oldPasswordController.text.trim(),
|
||||
'newPassword': _newPasswordController.text.trim(),
|
||||
'confirmPassword': _confirmPasswordController.text.trim(),
|
||||
});
|
||||
if (response.statusCode == 200) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
return (true, response.data['message'].toString());
|
||||
} else {
|
||||
return (false, response.data['message'].toString());
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
if (e.response?.data is Map<String, dynamic>) {
|
||||
return (
|
||||
false,
|
||||
e.response?.data['message'].toString() ?? 'something went wrong'
|
||||
);
|
||||
} else if (e.response?.data is String) {
|
||||
return (false, e.response?.data.toString() ?? 'something went wrong');
|
||||
} else {
|
||||
return (false, 'something went wrong');
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
return (false, 'something went wrong');
|
||||
}
|
||||
} else {
|
||||
return (false, 'something went wrong');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CommonBackground(
|
||||
isFullWidth: true,
|
||||
child: Scaffold(
|
||||
drawer: const CommonDrawer(),
|
||||
|
||||
backgroundColor: Colors.transparent,
|
||||
|
||||
appBar: CommonAppBar(
|
||||
|
||||
title: const Text(''),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
@ -72,30 +122,27 @@ class _ChangePasswordPageState extends State<ChangePasswordPage> {
|
||||
fontFamily: 'Roboto')),
|
||||
const SizedBox(height: 20),
|
||||
CommonTextFormField(
|
||||
// controller: value.emailController,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your email id';
|
||||
}
|
||||
if (!RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$')
|
||||
.hasMatch(value)) {
|
||||
return 'Please enter a valid email id';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
title: 'Current Password'),
|
||||
const SizedBox(height: 20),
|
||||
CommonTextFormField(
|
||||
// controller: value.passwordController,
|
||||
controller: _oldPasswordController,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
title: 'New Password'), const SizedBox(height: 20),
|
||||
title: 'Current Password'),
|
||||
const SizedBox(height: 20),
|
||||
CommonTextFormField(
|
||||
// controller: value.passwordController,
|
||||
controller: _newPasswordController,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
title: 'New Password'),
|
||||
const SizedBox(height: 20),
|
||||
CommonTextFormField(
|
||||
controller: _confirmPasswordController,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your password';
|
||||
@ -112,30 +159,27 @@ class _ChangePasswordPageState extends State<ChangePasswordPage> {
|
||||
width: double.infinity,
|
||||
height: kToolbarHeight - 10,
|
||||
text: 'SIGN IN',
|
||||
isLoading: false,
|
||||
isLoading: _isLoading,
|
||||
onPressed: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder:(context) => const PasswordChangeScreen()));
|
||||
_changePassword().then(
|
||||
(result) {
|
||||
var (status, message) = result;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message)));
|
||||
if (status) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const PasswordChangeScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
// onPressed: value.isLoading
|
||||
// ? null
|
||||
// : () async {
|
||||
// if (_formKey.currentState!.validate()) {
|
||||
// value.login().then((result) {
|
||||
// var (status, message) = result;
|
||||
// ScaffoldMessenger.of(context)
|
||||
// .showSnackBar(SnackBar(
|
||||
// content: Text(message)));
|
||||
// if (status) {
|
||||
// Navigator.pushReplacement(
|
||||
// context,
|
||||
// MaterialPageRoute(
|
||||
// builder: (context) =>
|
||||
// const HomePage()));
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
))
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -1,7 +1,9 @@
|
||||
import 'package:cheminova/screens/verify_phone_screen.dart';
|
||||
import 'package:cheminova/services/api_client.dart';
|
||||
import 'package:cheminova/services/api_urls.dart';
|
||||
import 'package:cheminova/widgets/common_background.dart';
|
||||
import 'package:cheminova/widgets/common_elevated_button.dart';
|
||||
import 'package:cheminova/widgets/common_text_form_field.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ForgotPasswordScreen extends StatefulWidget {
|
||||
@ -12,15 +14,87 @@ class ForgotPasswordScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _emailController = TextEditingController();
|
||||
|
||||
bool isLoading = false;
|
||||
|
||||
void _submitEmail() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Process the form data
|
||||
_forgetPassword();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _forgetPassword() async {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
final apiClient = ApiClient();
|
||||
Response response =
|
||||
await apiClient.post(ApiUrls.forgetPasswordUrl, data: {
|
||||
'email': _emailController.text.trim(),
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(response.data['message'].toString()),
|
||||
),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
if (e.response?.data is Map<String, dynamic>) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(e.response?.data['message'].toString() ??
|
||||
'Something went wrong'),
|
||||
),
|
||||
);
|
||||
} else if (e.response?.data is String) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content:
|
||||
Text(e.response?.data.toString() ?? 'Something went wrong'),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Something went wrong'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CommonBackground(
|
||||
isFullWidth: false,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: AppBar(leading: InkWell(onTap:() {
|
||||
appBar: AppBar(
|
||||
leading: InkWell(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},child: Image.asset('assets/Back_attendance.png')),backgroundColor: Colors.transparent,),
|
||||
},
|
||||
child: Image.asset('assets/Back_attendance.png')),
|
||||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Container(
|
||||
@ -31,6 +105,8 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
||||
color: const Color(0xffB4D1E5).withOpacity(0.9),
|
||||
borderRadius: BorderRadius.circular(26.0),
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@ -63,7 +139,20 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const CommonTextFormField(title: ' Enter Your Email ID'),
|
||||
CommonTextFormField(
|
||||
title: ' Enter Your Email ID',
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your email id';
|
||||
}
|
||||
if (!RegExp(r'^[^@\s]+@[^@\s]+\.[^@\s]+$')
|
||||
.hasMatch(value)) {
|
||||
return 'Please enter a valid email id';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
controller: _emailController,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
@ -71,12 +160,14 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Back to Login',
|
||||
child: const Text(
|
||||
'Back to Login',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400,
|
||||
fontFamily: 'Roboto')),
|
||||
fontFamily: 'Roboto'),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
@ -86,16 +177,10 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
||||
backgroundColor: const Color(0xff004791),
|
||||
borderRadius: 30,
|
||||
width: double.infinity,
|
||||
isLoading: isLoading,
|
||||
height: kToolbarHeight - 10,
|
||||
text: 'SEND',
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const VerifyPhoneScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
onPressed: _submitEmail,
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -104,6 +189,7 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:cheminova/provider/user_provider.dart';
|
||||
import 'package:cheminova/screens/calendar_screen.dart';
|
||||
import 'package:cheminova/screens/collect_kyc_screen.dart';
|
||||
import 'package:cheminova/screens/mark_attendence_screen.dart';
|
||||
@ -12,38 +13,64 @@ import 'package:cheminova/widgets/common_drawer.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cheminova/widgets/common_background.dart';
|
||||
import 'package:cheminova/screens/daily_tasks_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Provider.of<UserProvider>(context, listen: false).fetchUserProfile();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CommonBackground(
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.transparent,
|
||||
appBar: const CommonAppBar(
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
children: [
|
||||
// CircleAvatar(
|
||||
// backgroundImage: AssetImage(
|
||||
// 'assets/profile.png'), // Replace with actual user image
|
||||
// ),
|
||||
SizedBox(width: 10),
|
||||
Column(
|
||||
const SizedBox(width: 10),
|
||||
Consumer<UserProvider>(
|
||||
builder: (context, userProvider, child) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Welcome',
|
||||
const Text(
|
||||
'Welcome',
|
||||
style: TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400)),
|
||||
Text('User Name',
|
||||
style: TextStyle(
|
||||
color: Colors.black87, fontSize: 20)),
|
||||
],
|
||||
fontWeight: FontWeight.w400),
|
||||
),
|
||||
Text(
|
||||
userProvider.user?.name ?? 'User Name',
|
||||
style: const TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
],
|
||||
), backgroundColor: Colors.transparent, elevation: 0,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
),
|
||||
drawer: const CommonDrawer(),
|
||||
body: SafeArea(
|
||||
@ -62,7 +89,8 @@ class HomePage extends StatelessWidget {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const MarkAttendanceScreen(),
|
||||
builder: (context) =>
|
||||
const MarkAttendanceScreen(),
|
||||
));
|
||||
},
|
||||
),
|
||||
@ -79,15 +107,21 @@ class HomePage extends StatelessWidget {
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
_buildCustomCard('Assign Tasks', '', onTap: () {}),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildCustomCard('Display\nSales data',
|
||||
'Quickly display Sales', onTap: () {
|
||||
child: _buildCustomCard(
|
||||
'Display\nSales data', 'Quickly display Sales',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const DisplaySalesScreen(),
|
||||
builder: (context) =>
|
||||
const DisplaySalesScreen(),
|
||||
));
|
||||
}),
|
||||
),
|
||||
@ -100,7 +134,8 @@ class HomePage extends StatelessWidget {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const UpdateInventoryScreen(),
|
||||
builder: (context) =>
|
||||
const UpdateInventoryScreen(),
|
||||
));
|
||||
}),
|
||||
),
|
||||
@ -112,7 +147,8 @@ class HomePage extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildCustomCard('Summary', '\n\n', onTap: () {
|
||||
child:
|
||||
_buildCustomCard('Summary', '\n\n', onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@ -125,11 +161,13 @@ class HomePage extends StatelessWidget {
|
||||
),
|
||||
Expanded(
|
||||
child: _buildCustomCard(
|
||||
'Product\nSales Data Visibility', '', onTap: () {
|
||||
'Product\nSales Data Visibility', '',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ProductSalesData(),
|
||||
builder: (context) =>
|
||||
const ProductSalesData(),
|
||||
));
|
||||
}),
|
||||
),
|
||||
@ -146,7 +184,8 @@ class HomePage extends StatelessWidget {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const CollectKycScreen(),
|
||||
builder: (context) =>
|
||||
const CollectKycScreen(),
|
||||
));
|
||||
}),
|
||||
),
|
||||
@ -156,12 +195,14 @@ class HomePage extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildCustomCard('Notifications',
|
||||
'Tasks & Alerts\n\n', onTap: () {
|
||||
child: _buildCustomCard(
|
||||
'Notifications', 'Tasks & Alerts\n\n',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const NotificationScreen(),
|
||||
builder: (context) =>
|
||||
const NotificationScreen(),
|
||||
));
|
||||
}),
|
||||
),
|
||||
@ -169,10 +210,18 @@ class HomePage extends StatelessWidget {
|
||||
width: 15,
|
||||
),
|
||||
Expanded(
|
||||
child: _buildCustomCard('Calendar',
|
||||
' Upcoming Appointments & Deadlines',onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => const CalendarScreen(),));
|
||||
},),
|
||||
child: _buildCustomCard(
|
||||
'Calendar',
|
||||
' Upcoming Appointments & Deadlines',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const CalendarScreen(),
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -180,12 +229,14 @@ class HomePage extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildCustomCard('Products Manual',
|
||||
'details of products', onTap: () {
|
||||
child: _buildCustomCard(
|
||||
'Products Manual', 'details of products',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ProductsManualScreen(),
|
||||
builder: (context) =>
|
||||
const ProductsManualScreen(),
|
||||
));
|
||||
}),
|
||||
),
|
||||
@ -202,7 +253,8 @@ class HomePage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCustomCard(String title, String subtitle, {void Function()? onTap}) {
|
||||
Widget _buildCustomCard(String title, String subtitle,
|
||||
{void Function()? onTap}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:cheminova/provider/login_provider.dart';
|
||||
import 'package:cheminova/screens/forgot_password_screen.dart';
|
||||
import 'package:cheminova/screens/home_screen.dart';
|
||||
import 'package:cheminova/screens/verify_phone_screen.dart';
|
||||
import 'package:cheminova/widgets/common_background.dart';
|
||||
import 'package:cheminova/widgets/common_elevated_button.dart';
|
||||
@ -44,7 +45,10 @@ class _LoginPageState extends State<LoginPage> {
|
||||
const SizedBox(height: 50),
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: Container(decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(12)),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Image.asset('assets/cheminova_logo.png',
|
||||
height: kToolbarHeight - 25),
|
||||
@ -54,7 +58,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
Container(
|
||||
padding:
|
||||
const EdgeInsets.all(20.0).copyWith(top: 15, bottom: 30),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 30.0).copyWith(bottom: 50),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 30.0)
|
||||
.copyWith(bottom: 50),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.white),
|
||||
color: const Color(0xffB4D1E5).withOpacity(0.9),
|
||||
@ -94,7 +99,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
title: 'Username')),
|
||||
title: 'Username'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Consumer<LoginProvider>(
|
||||
builder: (context, value, child) =>
|
||||
@ -108,7 +114,6 @@ class _LoginPageState extends State<LoginPage> {
|
||||
},
|
||||
title: 'Password')),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
Align(
|
||||
alignment: Alignment.center,
|
||||
child: TextButton(
|
||||
@ -140,7 +145,20 @@ class _LoginPageState extends State<LoginPage> {
|
||||
text: 'SIGN IN',
|
||||
isLoading: value.isLoading,
|
||||
onPressed: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder:(context) => const VerifyPhoneScreen()));
|
||||
loginProvider.login().then((result) {
|
||||
var (status, message) = result;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message)));
|
||||
if (status) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const HomePage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
// onPressed: value.isLoading
|
||||
// ? null
|
||||
|
@ -1,5 +1,7 @@
|
||||
import 'package:cheminova/constants/constant.dart';
|
||||
import 'package:cheminova/screens/home_screen.dart';
|
||||
import 'package:cheminova/screens/login_screen.dart';
|
||||
import 'package:cheminova/services/secure__storage_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
@ -10,12 +12,23 @@ class SplashScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> {
|
||||
void _checkLogin() {
|
||||
SecureStorageService().read(key: 'user').then((value) {
|
||||
if (value != null) {
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (context) => const HomePage()));
|
||||
} else {
|
||||
Navigator.pushReplacement(context,
|
||||
MaterialPageRoute(builder: (context) => const LoginPage()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
Navigator.pushReplacement(
|
||||
context, MaterialPageRoute(builder: (context) => const LoginPage()));
|
||||
_checkLogin();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
class ApiUrls {
|
||||
static const String baseUrl =
|
||||
'https://cheminova-api-2.onrender.com/api/';
|
||||
static const String loginUrl = 'salescoordinator/login';
|
||||
static const String profileUrl = 'my-profile';
|
||||
static const String baseUrl = 'https://cheminova-api-2.onrender.com/api/';
|
||||
static const String loginUrl = 'territorymanager/login';
|
||||
static const String profileUrl = 'territorymanager/my-profile';
|
||||
static const String markAttendanceUrl = 'v1/markattendance/salescoordinator';
|
||||
static const String forgetPasswordUrl = 'territorymanager/forgot-password';
|
||||
static const String changePasswordUrl = 'territorymanager/password/update';
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
import 'package:cheminova/provider/user_provider.dart';
|
||||
import 'package:cheminova/screens/change_password_screen.dart';
|
||||
import 'package:cheminova/screens/home_screen.dart';
|
||||
import 'package:cheminova/screens/login_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CommonDrawer extends StatelessWidget {
|
||||
const CommonDrawer({super.key});
|
||||
@ -12,48 +14,58 @@ class CommonDrawer extends StatelessWidget {
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
SizedBox(
|
||||
height: 150,
|
||||
child: const DrawerHeader(
|
||||
decoration: BoxDecoration(
|
||||
child: DrawerHeader(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.black87,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,mainAxisAlignment: MainAxisAlignment.start,
|
||||
child: Consumer<UserProvider>(
|
||||
builder: (context, userProvider, child) {
|
||||
if (userProvider.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (userProvider.user != null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Username',
|
||||
style: TextStyle(
|
||||
userProvider.user!.name,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),Text(
|
||||
'Employee ID',
|
||||
style: TextStyle(
|
||||
),
|
||||
Text(
|
||||
userProvider.user!.uniqueId,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Text(
|
||||
'No User Data',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
// const UserAccountsDrawerHeader(
|
||||
// accountName: Text("Name"),
|
||||
// accountEmail: Text("Employee ID"),
|
||||
// // currentAccountPicture: CircleAvatar(
|
||||
// // backgroundImage: AssetImage(
|
||||
// // 'assets/profile.png'), // Replace with actual user image
|
||||
// // ),
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.black87,
|
||||
// ),
|
||||
// ),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.home),
|
||||
title: const Text('Home'),
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => const HomePage(),));
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const HomePage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@ -67,15 +79,25 @@ class CommonDrawer extends StatelessWidget {
|
||||
leading: const Icon(Icons.settings),
|
||||
title: const Text('Change Password'),
|
||||
onTap: () {
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => const ChangePasswordPage(),));
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ChangePasswordPage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.exit_to_app),
|
||||
title: const Text('Logout'),
|
||||
onTap: () {
|
||||
Navigator.pushReplacement(context,
|
||||
MaterialPageRoute(builder: (context) => const LoginPage()));
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Provider.of<UserProvider>(context, listen: false)
|
||||
.clearUserProfile();
|
||||
});
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const LoginPage()),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -16,7 +16,8 @@ class CommonElevatedButton extends StatelessWidget {
|
||||
this.borderRadius,
|
||||
this.backgroundColor,
|
||||
this.height,
|
||||
this.width, this.isLoading=false});
|
||||
this.width,
|
||||
this.isLoading = false});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -24,17 +25,18 @@ class CommonElevatedButton extends StatelessWidget {
|
||||
height: height ?? kToolbarHeight - 25,
|
||||
width: width ?? 200,
|
||||
child: ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
onPressed: isLoading ? null : onPressed,
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(borderRadius ?? 6)),
|
||||
backgroundColor: backgroundColor ?? const Color(0xff1E1E1E),
|
||||
side: const BorderSide(color: Colors.transparent)),
|
||||
child: Center(
|
||||
child: isLoading?const CircularProgressIndicator(
|
||||
child: isLoading
|
||||
? const CircularProgressIndicator(
|
||||
backgroundColor: Colors.white,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.black)
|
||||
):Text(text ?? 'Submit',
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.black))
|
||||
: Text(text ?? 'Submit',
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.white,
|
||||
|
@ -13,8 +13,8 @@ class CommonTextFormField extends StatelessWidget {
|
||||
final List<TextInputFormatter>? inputFormatters;
|
||||
final int? maxLength;
|
||||
|
||||
const CommonTextFormField(
|
||||
{super.key,
|
||||
const CommonTextFormField({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.controller,
|
||||
this.validator,
|
||||
@ -23,7 +23,9 @@ const CommonTextFormField(
|
||||
this.maxLines,
|
||||
this.height,
|
||||
this.keyboardType,
|
||||
this.inputFormatters, this.maxLength});
|
||||
this.inputFormatters,
|
||||
this.maxLength,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
Loading…
Reference in New Issue
Block a user