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.

127 lines
4.3KB

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