add update phone number and recovery email
This commit is contained in:
114
lib/pages/profile/add_recovery_email.dart
Normal file
114
lib/pages/profile/add_recovery_email.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../domain/entities/user.dart';
|
||||
import '../../helpers/theme.dart';
|
||||
import '../../localization/app_translations.dart';
|
||||
import '../main/util.dart';
|
||||
import '../widgets/input_text.dart';
|
||||
import '../widgets/local_app_bar.dart';
|
||||
import '../widgets/local_text.dart';
|
||||
import '../widgets/progress.dart';
|
||||
import 'confirm_recovery_email.dart';
|
||||
|
||||
class AddRecoveryEmail extends StatefulWidget {
|
||||
final User user;
|
||||
const AddRecoveryEmail({super.key, required this.user});
|
||||
|
||||
@override
|
||||
State<AddRecoveryEmail> createState() => _AddRecoveryEmailState();
|
||||
}
|
||||
|
||||
class _AddRecoveryEmailState extends State<AddRecoveryEmail> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
final TextEditingController _emailCtl = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_emailCtl.text = widget.user.recoveryEmail ?? "";
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final emailBox = InputText(
|
||||
labelTextKey: "profile.email",
|
||||
iconData: Icons.email_outlined,
|
||||
controller: _emailCtl,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return AppTranslations.of(context)!.text('profile.email.empty');
|
||||
}
|
||||
|
||||
if (!isValidEmail(value)) {
|
||||
return AppTranslations.of(context)!
|
||||
.text('profile.email.mismatch_message');
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
final continueBtn = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||
child: fcsButton(
|
||||
context,
|
||||
getLocalString(context, 'btn.continue'),
|
||||
callack: _continue,
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: const LocalAppBar(
|
||||
labelKey: 'profile.recovery_email.title',
|
||||
backgroundColor: Colors.white,
|
||||
labelColor: primaryColor,
|
||||
arrowColor: primaryColor),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(left: 15, right: 15, top: 10),
|
||||
children: [
|
||||
LocalText(context, 'profile.email_instruction',
|
||||
fontSize: 16, color: Colors.black),
|
||||
const SizedBox(height: 15),
|
||||
emailBox,
|
||||
const SizedBox(height: 30),
|
||||
continueBtn
|
||||
],
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _continue() async {
|
||||
if (_formKey.currentState != null && !_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
bool? updated = await Navigator.of(context, rootNavigator: true).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
ConfirmRecoveryEmail(email: _emailCtl.text)));
|
||||
|
||||
if (updated ?? false) {
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user