add account delection page

This commit is contained in:
tzw
2024-03-05 17:09:04 +06:30
parent d2db1d60d0
commit 7622cce151
9 changed files with 170 additions and 31 deletions

View File

@@ -13,6 +13,7 @@
"btn.ok": "Ok",
"btn.continue":"Continue",
"btn.previous":"Previous",
"btn.delete":"Continue to account deletion",
"feet":"Feet",
"inch":"Inch",
"back.button_confirm":"Are you sure you want to continue without submitting changes?",
@@ -170,7 +171,8 @@
"profile.edit.currency.title":"Preferred Currency",
"profile.name": "Name",
"profile.phone": "Phone",
"profile.delete": "Delete Account",
"profile.delete.title": "Delete Account",
"delete.confirm.label":"Are you sure to delete your account?",
"profile.language": "Languages",
"profile.logout": "logout",
"profile.currency":"Preferred currency",

View File

@@ -12,6 +12,7 @@
"btn.ok": "အိုကေ",
"btn.continue":"ဆက်ရန်",
"btn.previous":"နောက်သို့",
"btn.delete":"အကောင့်ဖျက်ခြင်းကို ဆက်လက်လုပ်ဆောင်မည်",
"feet":"ပေ",
"inch":"လက်မ",
"back.button_confirm":"Are you sure you want to continue without submitting changes?",
@@ -171,7 +172,8 @@
"profile.edit.currency.title":"နှစ်သက်သော ငွေအမျိုးအစား",
"profile.name":"နာမည်",
"profile.phone": "ဖုန်းနံပါတ်",
"profile.delete": "အကောင့်ကို ဖျက်မည်",
"profile.delete.title": "အကောင့်ဖျက်ခြင်း",
"delete.confirm.label":"သင့်အကောင့်ကို ဖျက်ရန် သေချာပြီလား?",
"profile.language": "ဘာသာစကားများ",
"profile.logout": "အကောင့်ထွက်ရန်",
"profile.currency":"နှစ်သက်သော ငွေအမျိုးအစား",

View File

@@ -202,6 +202,10 @@ class AuthFb {
payload: {"preferred_currency": currency}, token: await getToken());
}
Future<void> deleteAccount() async {
return await requestAPI("/accounts", "DELETE", token: await getToken());
}
Stream<Setting> settings() async* {
Stream<DocumentSnapshot> snapshot = FirebaseFirestore.instance
.collection(config_collection)

View File

@@ -69,4 +69,9 @@ class AuthServiceImp implements AuthService {
Future<void> signoutStart() {
return authFb.signoutStart();
}
@override
Future<void> deleteAccount() {
return authFb.deleteAccount();
}
}

View File

@@ -14,4 +14,5 @@ abstract class AuthService {
Future<bool> hasInvite();
Stream<User?> getUserStream();
Stream<Setting> getSetting();
Future<void> deleteAccount();
}

View File

@@ -23,6 +23,8 @@ class Setting {
final String? termsMm;
String? about;
String? courierWebsite;
String? deactivateTextEn;
String? deactivateTextMm;
List<String> shipmentTypes;
@@ -40,7 +42,9 @@ class Setting {
this.termsMm,
this.about,
this.shipmentTypes = const [],
this.courierWebsite});
this.courierWebsite,
this.deactivateTextEn,
this.deactivateTextMm});
factory Setting.fromMap(Map<String, dynamic> map) {
return Setting(
@@ -58,6 +62,8 @@ class Setting {
termsMm: map['terms_mm_markdown'],
shipmentTypes: List.from(map['shipment_types']),
courierWebsite: map['courier_website'],
deactivateTextEn: map['deactivate_text_en']??"",
deactivateTextMm: map['deactivate_text_mm']??""
);
}

View File

@@ -192,4 +192,8 @@ class MainModel extends ChangeNotifier {
await Services.instance.authService.updatePreferredCurrency(currency);
notifyListeners();
}
Future<void> deleteAccount() async {
return await Services.instance.authService.deleteAccount();
}
}

View File

@@ -0,0 +1,105 @@
import 'package:fcs/domain/entities/setting.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/model/main_model.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:provider/provider.dart';
import '../main/model/language_model.dart';
import '../main/util.dart';
import '../widgets/local_text.dart';
class AccountDelectionPage extends StatefulWidget {
final Function onlogout;
const AccountDelectionPage({Key? key, required this.onlogout})
: super(key: key);
@override
_AccountDelectionPageState createState() => _AccountDelectionPageState();
}
class _AccountDelectionPageState extends State<AccountDelectionPage> {
bool _isLoading = false;
@override
Widget build(BuildContext context) {
bool isEng = Provider.of<LanguageModel>(context).isEng;
Setting? setting = Provider.of<MainModel>(context).setting;
String? text = isEng
? (setting!.deactivateTextEn ?? "")
: (setting!.deactivateTextMm ?? "");
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: 'profile.delete.title',
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
),
body: SafeArea(
child: ScrollConfiguration(
behavior: const ScrollBehavior().copyWith(overscroll: false),
child: ListView(
padding: const EdgeInsets.all(10),
children: [
Markdown(
shrinkWrap: true,
softLineBreak: true,
physics: const BouncingScrollPhysics(),
data: (text).replaceAll("\\n", '\n'),
styleSheet: MarkdownStyleSheet.fromTheme(ThemeData(
textTheme: TextTheme(
bodyMedium: TextStyle(
fontSize: isEng ? 15 : 14,
color: Colors.black87))))),
const SizedBox(
height: 50,
),
Container(
padding: const EdgeInsets.all(20),
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: buttonColor,
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
)),
onPressed: () {
showConfirmDialog(context, 'delete.confirm.label',
() {
_deactivate();
});
},
child: LocalText(context, "btn.delete",
fontSize: 15, color: buttonColor))),
],
),
),
),
),
);
}
_deactivate() async {
try {
setState(() {
_isLoading = true;
});
// await context.read<MainModel>().deleteAccount();
// await widget.onlogout();
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
if (mounted) {
setState(() {
_isLoading = false;
});
}
}
}
}

View File

@@ -24,6 +24,8 @@ import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import '../../helpers/theme.dart';
import 'package:collection/collection.dart';
import 'account_delection_page.dart';
typedef void ProfileCallback();
class Profile extends StatefulWidget {
@@ -82,8 +84,8 @@ class _ProfileState extends State<Profile> {
labelTextKey: "profile.currency",
iconData: FontAwesome5Regular.money_bill_alt,
);
final deleteacbox = DisplayText(
labelTextKey: "profile.delete",
final deleteAccountBox = DisplayText(
labelTextKey: "profile.delete.title",
iconData: MaterialCommunityIcons.delete,
);
@@ -128,8 +130,11 @@ class _ProfileState extends State<Profile> {
);
final logoutbutton = fcsButton(
context, getLocalString(context, "profile.logout"),
callack: _logout, iconData: Icons.exit_to_app);
context, getLocalString(context, "profile.logout"), callack: () {
showConfirmDialog(context, "profile.logout.confirm", () async {
await _logout();
});
}, iconData: Icons.exit_to_app);
return LocalProgress(
inAsyncCall: _isLoading,
@@ -187,7 +192,9 @@ class _ProfileState extends State<Profile> {
),
Row(
children: <Widget>[
Expanded(child: deleteacbox,),
Expanded(
child: deleteAccountBox,
),
Padding(
padding: const EdgeInsets.only(right: 0),
child: IconButton(
@@ -196,7 +203,6 @@ class _ProfileState extends State<Profile> {
)
],
),
getPrivilegeBox(context),
SizedBox(height: 15),
logoutbutton,
@@ -359,10 +365,16 @@ class _ProfileState extends State<Profile> {
),
);
}
_editDelete() {
Navigator.of(context)
.push<void>(CupertinoPageRoute(builder: (context) => ProfileEdit()));
Navigator.of(context).push<void>(CupertinoPageRoute(
builder: (context) => AccountDelectionPage(
onlogout: () {
_logout();
},
)));
}
_editName() {
Navigator.of(context)
.push<void>(CupertinoPageRoute(builder: (context) => ProfileEdit()));
@@ -373,8 +385,7 @@ _editDelete() {
CupertinoPageRoute(builder: (context) => ProfileCurrencyEdit()));
}
_logout() {
showConfirmDialog(context, "profile.logout.confirm", () async {
_logout() async {
setState(() {
_isLoading = true;
});
@@ -389,9 +400,8 @@ _editDelete() {
});
}
});
Navigator.of(context).pushNamedAndRemoveUntil(
"/welcome", ModalRoute.withName('/welcome'));
}
});
Navigator.of(context)
.pushNamedAndRemoveUntil("/welcome", ModalRoute.withName('/welcome'));
}
}
}