import 'package:teso/Pages/Sub_Pages/LandingPage/Success.dart'; import 'package:teso/Pages/Sub_Pages/LandingPage/ReferPage.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:teso/Pages/PageWidgets/Login/email.dart'; import 'package:teso/util/consts.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; class ResetPassword extends StatefulWidget { @override _ResetPasswordState createState() => _ResetPasswordState(); } class _ResetPasswordState extends State { var usern = new TextEditingController(); bool visibleT = true; var password = new TextEditingController(); bool loading = false; bool error = false; bool rememberMe = false; bool success = false; String? usernameFor; @override void dispose() { super.dispose(); } void requestReset() async { setState(() { error = false; }); Map requestHeaders = { 'Content-type': 'application/json', }; String email = usern.text; var register2 = serverLocation + 'resetpassword/request'; var client1 = await http.post(Uri.parse(register2), body: json.encode(email), headers: requestHeaders); if (client1.statusCode == 200) { String responseBody = client1.body.trim(); switch (responseBody) { case "sent": await showDialog( context: context, builder: (BuildContext context) => SuccessPage(), ); Navigator.pop(context); break; case "twitter": await showDialog( context: context, builder: (BuildContext context) => ReferPage( accountType: responseBody, ), ); Navigator.pop(context); break; case "google": await showDialog( context: context, builder: (BuildContext context) => ReferPage(accountType: responseBody), ); Navigator.pop(context); break; case "facebook": await showDialog( context: context, builder: (BuildContext context) => ReferPage(accountType: responseBody), ); Navigator.pop(context); break; } } else { setState(() { error = true; }); } } @override Widget build(BuildContext context) { return Dialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(Consts.padding), ), elevation: 0.0, backgroundColor: Colors.transparent, child: SingleChildScrollView( scrollDirection: Axis.vertical, child: Stack( children: [ Container( padding: EdgeInsets.only( top: Consts.avatarRadius + Consts.padding, bottom: Consts.padding, left: Consts.padding, right: Consts.padding, ), margin: EdgeInsets.only(top: Consts.avatarRadius), decoration: new BoxDecoration( color: Colors.white, shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(Consts.padding), gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ accentMain, darkAccent, ], // stops: [0.1, 0.4, 0.7, 0.8], ), boxShadow: [ BoxShadow( color: Colors.black26, blurRadius: 10.0, offset: const Offset(0.0, 10.0), ), ], ), child: Column( mainAxisSize: MainAxisSize.min, // To make the card compact children: [ Visibility( visible: success, child: Text( "A confirmation link has been sent to your mail open the link to continue with the process !!!", style: TextStyle( fontSize: 18.0, fontWeight: FontWeight.w700, color: Colors.green, ), ), ), Visibility( visible: visibleT, child: Text( "Reset your Teso account password", textAlign: TextAlign.center, style: TextStyle( fontSize: 15.0, fontWeight: FontWeight.w700, color: Colors.white, ), ), ), SizedBox(height: 16.0), Visibility( visible: visibleT, child: Text( "Please enter the registered email address for your Teso account", textAlign: TextAlign.center, style: TextStyle( fontSize: 12.0, color: Colors.white, ), ), ), SizedBox(height: 14.0), Visibility( visible: visibleT, child: email(context, "Email address", usern), ), SizedBox(height: 20.0), Visibility( visible: visibleT, child: Align( alignment: Alignment.bottomCenter, child: TextButton( onPressed: requestReset, child: Text( "RESET PASSWORD", style: TextStyle( color: Colors.white, fontSize: 13, ), ), ), ), ), Visibility( visible: error, child: Align( alignment: Alignment.bottomCenter, child: Text( "Oops! An error occurred while trying to reset password, please make sure your email is correct and try again", style: TextStyle(fontSize: 16, color: Colors.red), )), ), Visibility( visible: !visibleT, child: Align( alignment: Alignment.bottomRight, child: TextButton( onPressed: () { Navigator.of(context).pop(); // To close the dialog }, child: Text("OK"), ), ), ), Visibility( visible: loading, child: Align( alignment: Alignment.bottomCenter, child: CupertinoActivityIndicator( animating: true, radius: 15, ), ), ), ], ), ), Positioned( left: Consts.padding, right: Consts.padding, child: CircleAvatar( child: Image.asset( "assets/images/tesoCouponInsignia.png", width: 100, ), backgroundColor: Colors.white, radius: Consts.avatarRadius, ), ), ], ), ), ); } } class Consts { Consts._(); static const double padding = 16.0; static const double avatarRadius = 55.0; }