import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:go_router/go_router.dart'; import 'package:manager_app/Components/common_loader.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/rounded_input_field.dart'; import 'package:manager_app/client.dart'; import 'package:manager_app/constants.dart'; import 'package:manager_app/l10n/app_localizations.dart'; class ForgotPasswordScreen extends StatefulWidget { ForgotPasswordScreen({Key? key}) : super(key: key); @override _ForgotPasswordScreenState createState() => _ForgotPasswordScreenState(); } class _ForgotPasswordScreenState extends State { final String host = "http://localhost:5000"; String email = ""; bool isLoading = false; bool isSent = false; Future submit() async { if (email.trim().isEmpty) return; setState(() => isLoading = true); try { final clientAPI = Client(host); await clientAPI.authenticationApi!.authenticationForgotPassword(email.trim()); setState(() { isSent = true; isLoading = false; }); } catch (e) { setState(() => isLoading = false); showNotification(Colors.orange, kWhite, AppLocalizations.of(context)!.loginError, context, null); } } @override Widget build(BuildContext context) { final l = AppLocalizations.of(context)!; return Scaffold( body: LayoutBuilder( builder: (context, constraints) { final isMobile = constraints.maxWidth < 550; final cardWidth = isMobile ? constraints.maxWidth - 32.0 : 440.0; return Container( width: double.infinity, height: double.infinity, decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ kPrimaryColor.withValues(alpha: 0.12), kBackgroundColor, kBackgroundColor, ], ), ), child: Center( child: SingleChildScrollView( padding: EdgeInsets.all(isMobile ? 16.0 : 24.0), child: Container( width: cardWidth, decoration: BoxDecoration( color: kWhite, borderRadius: BorderRadius.circular(16.0), boxShadow: [ BoxShadow( color: Colors.black.withValues(alpha: 0.08), spreadRadius: 0, blurRadius: 32, offset: Offset(0, 8), ), ], ), child: Padding( padding: EdgeInsets.symmetric(horizontal: isMobile ? 24.0 : 40.0, vertical: 40.0), child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( constraints: BoxConstraints(maxHeight: 64, minHeight: 40), child: SvgPicture.asset('assets/images/MyInfoMate_logo_only.svg'), ), SizedBox(height: 24), if (!isSent) ...[ Text( l.forgotPasswordTitle, style: TextStyle(color: kPrimaryColor, fontSize: 22, fontWeight: FontWeight.w600), textAlign: TextAlign.center, ), SizedBox(height: 8), Text( l.forgotPasswordDesc, style: TextStyle(fontSize: 14, color: Colors.grey[700]), textAlign: TextAlign.center, ), SizedBox(height: 24), RoundedInputField( hintText: "E-mail", autofill: "email", isEmail: true, initialValue: email, onChanged: (value) => email = value, ), SizedBox(height: 24), !isLoading ? SizedBox( width: double.infinity, child: RoundedButton( text: l.forgotPasswordSubmit, fontSize: 16, vertical: 15, horizontal: 30, press: submit, ), ) : CommonLoader(iconSize: 40), ] else ...[ Icon(Icons.mark_email_read_outlined, color: kSuccess, size: 48), SizedBox(height: 16), Text( l.forgotPasswordSuccess, style: TextStyle(fontSize: 15), textAlign: TextAlign.center, ), ], SizedBox(height: 24), TextButton( onPressed: () => context.go('/login'), child: Text(l.backToLogin, style: TextStyle(color: kPrimaryColor)), ), ], ), ), ), ), ), ); }, ), ); } }