You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.5KB

  1. import 'package:farm_tpf/authentication/bloc/authentication_bloc.dart';
  2. import 'package:farm_tpf/data/repository/user_repository.dart';
  3. import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
  4. import 'package:farm_tpf/presentation/custom_widgets/button_icon_widget.dart';
  5. import 'package:farm_tpf/presentation/screens/profile/sc_change_password.dart';
  6. import 'package:farm_tpf/presentation/screens/profile/sc_update_profile.dart';
  7. import 'package:farm_tpf/utils/const_icons.dart';
  8. import 'package:farm_tpf/utils/pref.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:get/get.dart';
  11. import 'package:package_info/package_info.dart';
  12. import 'package:flutter_bloc/flutter_bloc.dart';
  13. class AccountScreen extends StatefulWidget {
  14. @override
  15. _AccountScreenState createState() => _AccountScreenState();
  16. }
  17. class _AccountScreenState extends State<AccountScreen> {
  18. var pref = LocalPref();
  19. UserRepository _userRepository = UserRepository();
  20. PackageInfo _packageInfo = PackageInfo(
  21. version: '1.0.0',
  22. buildNumber: '1.',
  23. appName: '',
  24. packageName: '',
  25. );
  26. Future<void> _initPackageInfo() async {
  27. final PackageInfo info = await PackageInfo.fromPlatform();
  28. setState(() {
  29. _packageInfo = info;
  30. });
  31. }
  32. @override
  33. void initState() {
  34. super.initState();
  35. _initPackageInfo();
  36. }
  37. _clickSignOut() async {
  38. BlocProvider.of<AuthenticationBloc>(context).add(AuthenticationLogoutRequested());
  39. // context.bloc<AuthenticationBloc>().add(AuthenticationLogoutRequested());
  40. try {
  41. var pushKey = await pref.getString(DATA_CONST.PUSH_KEY);
  42. if (pushKey.isNotEmpty) {
  43. _userRepository.deleteFcmToken(pushKey).then((value) {}).catchError((err) {}).whenComplete(() {
  44. pref.saveString(DATA_CONST.TOKEN_KEY, "");
  45. pref.saveString(DATA_CONST.PUSH_KEY, "");
  46. pref.saveString(DATA_CONST.CURRENT_FULL_NAME, "");
  47. });
  48. }
  49. } catch (e) {
  50. pref.saveString(DATA_CONST.CURRENT_FULL_NAME, "");
  51. pref.saveString(DATA_CONST.TOKEN_KEY, "");
  52. pref.saveString(DATA_CONST.PUSH_KEY, "");
  53. }
  54. }
  55. @override
  56. Widget build(BuildContext context) {
  57. return Scaffold(
  58. backgroundColor: Colors.white,
  59. body: SafeArea(
  60. child: Column(
  61. crossAxisAlignment: CrossAxisAlignment.start,
  62. children: <Widget>[
  63. const SizedBox(
  64. height: 8,
  65. ),
  66. Container(
  67. padding: const EdgeInsets.all(8),
  68. color: Colors.white,
  69. child: const Text(
  70. 'Cá nhân',
  71. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22),
  72. )),
  73. Expanded(
  74. child: Column(children: [
  75. ButtonIconWidget(
  76. title: 'Tài khoản',
  77. leadingIcon: AppIcons.icUser,
  78. trailingIcon: AppIcons.icArrowRight,
  79. isTopBorder: false,
  80. onTap: () {
  81. Get.to(UpdateProfileScreen());
  82. }),
  83. ButtonIconWidget(
  84. title: 'Bảo mật',
  85. leadingIcon: AppIcons.icSecurity,
  86. trailingIcon: AppIcons.icArrowRight,
  87. isTopBorder: false,
  88. isBottomBorder: false,
  89. onTap: () {
  90. Get.to(ChangePasswordScreen());
  91. }),
  92. Container(
  93. width: double.infinity,
  94. height: 20,
  95. color: Colors.grey[200],
  96. ),
  97. Container(
  98. padding: const EdgeInsets.only(left: 12, right: 8, top: 14, bottom: 14),
  99. child: Row(
  100. children: [
  101. const Expanded(
  102. child: Text(
  103. 'Phiên bản',
  104. style: TextStyle(fontSize: 16, fontWeight: FontWeight.w100),
  105. )),
  106. Text("${_packageInfo.version}.${_packageInfo.buildNumber}")
  107. ],
  108. ),
  109. ),
  110. ButtonIconWidget(
  111. title: 'Đăng xuất',
  112. titleStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w100, color: Colors.red),
  113. leadingIcon: AppIcons.icLogout,
  114. trailingIcon: AppIcons.icArrowRight,
  115. onTap: () {
  116. _clickSignOut();
  117. }),
  118. ])),
  119. ],
  120. ),
  121. ),
  122. );
  123. }
  124. }