test base project
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../Utils/color_constants.dart';
|
||||
import '../../Utils/image_constant.dart';
|
||||
import '../../Utils/size_utils.dart';
|
||||
import '../../providers/token_manager.dart';
|
||||
import '../../resources/api_constants.dart';
|
||||
import '../../theme/app_style.dart';
|
||||
import '../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../widgets/custom_button.dart';
|
||||
import '../../widgets/custom_text_form_field.dart';
|
||||
import '../Login Screen/login_screen.dart';
|
||||
|
||||
class ForgotPasswordPage extends StatefulWidget {
|
||||
@override
|
||||
_ForgotPasswordPageState createState() => _ForgotPasswordPageState();
|
||||
}
|
||||
|
||||
class _ForgotPasswordPageState extends State<ForgotPasswordPage> {
|
||||
final TextEditingController emailController = TextEditingController();
|
||||
String message = '';
|
||||
bool isLoading = false; // Added to track loading state
|
||||
|
||||
Future<void> sendForgotPasswordRequest() async {
|
||||
setState(() {
|
||||
isLoading = true; // Show loading indicator when sending request
|
||||
});
|
||||
|
||||
final email = emailController.text;
|
||||
final token = await TokenManager.getToken();
|
||||
const String baseUrl = ApiConstants.baseUrl;
|
||||
|
||||
final response = await http.post(
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
Uri.parse('$baseUrl/api/resources/forgotpassword?email=$email'),
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
setState(() {
|
||||
message = 'An email with a reset link has been sent to $email.';
|
||||
});
|
||||
|
||||
// Delay for 3 seconds and then navigate to the login page
|
||||
Future.delayed(Duration(seconds: 3), () {
|
||||
Navigator.push(
|
||||
context, MaterialPageRoute(builder: (context) => LoginScreen()));
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
message = 'Failed to send the reset link. Please try again.';
|
||||
});
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isLoading = false; // Hide loading indicator when the request is complete
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: CustomAppBar(
|
||||
height: getVerticalSize(49),
|
||||
leadingWidth: 40,
|
||||
leading: AppbarImage(
|
||||
height: getSize(24),
|
||||
width: getSize(24),
|
||||
svgPath: ImageConstant.imgArrowleftBlueGray900,
|
||||
margin: getMargin(left: 16, top: 12, bottom: 13),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
centerTitle: true,
|
||||
title: AppbarTitle(text: "Forgot Password")),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: getPadding(top: 19),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text("Email",
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: TextAlign.left,
|
||||
style: AppStyle.txtGilroyMedium16Bluegray900),
|
||||
CustomTextFormField(
|
||||
focusNode: FocusNode(),
|
||||
hintText: "Enter Email",
|
||||
controller: emailController,
|
||||
margin: getMargin(top: 6))
|
||||
])),
|
||||
CustomButton(
|
||||
height: getVerticalSize(50),
|
||||
text: "Send me an access link",
|
||||
margin: getMargin(top: 24, bottom: 5),
|
||||
onTap: () async {
|
||||
sendForgotPasswordRequest();
|
||||
},
|
||||
),
|
||||
isLoading
|
||||
? CircularProgressIndicator(
|
||||
color: ColorConstant.blue700,
|
||||
) // Show loading indicator when isLoading is true
|
||||
: Text(message, style: AppStyle.txtGilroyMedium16Bluegray900),
|
||||
if (message.contains('An email with a reset link'))
|
||||
InkWell(
|
||||
child: Text('Click here to return to login',
|
||||
style: AppStyle.txtGilroyMedium16Bluegray900),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const LoginScreen()));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user