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.

132 lines
4.4KB

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