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.

133 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:flutter_bloc/flutter_bloc.dart';
  12. import '../../../utils/local_storage.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. // );
  24. // Future<void> _initPackageInfo() async {
  25. // final PackageInfo info = await PackageInfo.fromPlatform();
  26. // setState(() {
  27. // _packageInfo = info;
  28. // });
  29. // }
  30. @override
  31. void initState() {
  32. super.initState();
  33. // _initPackageInfo();
  34. }
  35. _clickSignOut() async {
  36. BlocProvider.of<AuthenticationBloc>(context).add(AuthenticationLogoutRequested());
  37. try {
  38. String pushKey = await pref.getString(DATA_CONST.PUSH_KEY);
  39. if (pushKey.isNotEmpty) {
  40. _userRepository.deleteFcmToken(pushKey).then((value) {}).catchError((err) {}).whenComplete(() {
  41. pref.saveString(DATA_CONST.TOKEN_KEY, "");
  42. pref.saveString(DATA_CONST.PUSH_KEY, "");
  43. });
  44. }
  45. pref.saveString(DATA_CONST.CURRENT_FULL_NAME, "");
  46. LocalStorage.save(LocalStorageKey.full_name, '');
  47. } catch (e) {
  48. pref.saveString(DATA_CONST.CURRENT_FULL_NAME, "");
  49. LocalStorage.save(LocalStorageKey.full_name, '');
  50. pref.saveString(DATA_CONST.TOKEN_KEY, "");
  51. pref.saveString(DATA_CONST.PUSH_KEY, "");
  52. }
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. return Scaffold(
  57. backgroundColor: Colors.white,
  58. body: SafeArea(
  59. child: Column(
  60. crossAxisAlignment: CrossAxisAlignment.start,
  61. children: <Widget>[
  62. SizedBox(
  63. height: 8,
  64. ),
  65. Container(
  66. padding: EdgeInsets.all(8),
  67. color: Colors.white,
  68. child: Text(
  69. 'Cá nhân',
  70. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22),
  71. )),
  72. Expanded(
  73. child: Column(children: [
  74. ButtonIconWidget(
  75. title: 'Tài khoản',
  76. leadingIcon: AppIcons.icUser,
  77. trailingIcon: AppIcons.icArrowRight,
  78. isTopBorder: false,
  79. onTap: () {
  80. Get.to(UpdateProfileScreen());
  81. }),
  82. ButtonIconWidget(
  83. title: 'Bảo mật',
  84. leadingIcon: AppIcons.icSecurity,
  85. trailingIcon: AppIcons.icArrowRight,
  86. isTopBorder: false,
  87. isBottomBorder: false,
  88. onTap: () {
  89. Get.to(ChangePasswordScreen());
  90. },
  91. ),
  92. Container(
  93. width: double.infinity,
  94. height: 20,
  95. color: Colors.grey[200],
  96. ),
  97. // Container(
  98. // padding: EdgeInsets.only(left: 12, right: 8, top: 14, bottom: 14),
  99. // child: Row(
  100. // children: [
  101. // 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: TextStyle(fontSize: 16, fontWeight: FontWeight.w100, color: Colors.red),
  113. leadingIcon: AppIcons.icLogout,
  114. // trailingIcon: AppIcons.icArrowRight,
  115. isTopBorder: false,
  116. onTap: () {
  117. _clickSignOut();
  118. }),
  119. ])),
  120. ],
  121. ),
  122. ),
  123. );
  124. }
  125. }