profile_drawer.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:easy_localization/easy_localization.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
  6. import 'package:immich_mobile/modules/backup/providers/manual_upload.provider.dart';
  7. import 'package:immich_mobile/modules/home/ui/profile_drawer/profile_drawer_header.dart';
  8. import 'package:immich_mobile/modules/home/ui/profile_drawer/server_info_box.dart';
  9. import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
  10. import 'package:immich_mobile/routing/router.dart';
  11. import 'package:immich_mobile/shared/providers/asset.provider.dart';
  12. import 'package:immich_mobile/shared/providers/websocket.provider.dart';
  13. class ProfileDrawer extends HookConsumerWidget {
  14. const ProfileDrawer({Key? key}) : super(key: key);
  15. @override
  16. Widget build(BuildContext context, WidgetRef ref) {
  17. buildSignOutButton() {
  18. return ListTile(
  19. leading: SizedBox(
  20. height: double.infinity,
  21. child: Icon(
  22. Icons.logout_rounded,
  23. color: Theme.of(context).textTheme.labelMedium?.color,
  24. size: 20,
  25. ),
  26. ),
  27. title: Text(
  28. "profile_drawer_sign_out",
  29. style: Theme.of(context)
  30. .textTheme
  31. .labelLarge
  32. ?.copyWith(fontWeight: FontWeight.bold),
  33. ).tr(),
  34. onTap: () async {
  35. await ref.watch(authenticationProvider.notifier).logout();
  36. ref.read(manualUploadProvider.notifier).cancelBackup();
  37. ref.watch(backupProvider.notifier).cancelBackup();
  38. ref.watch(assetProvider.notifier).clearAllAsset();
  39. ref.watch(websocketProvider.notifier).disconnect();
  40. AutoRouter.of(context).replace(const LoginRoute());
  41. },
  42. );
  43. }
  44. buildSettingButton() {
  45. return ListTile(
  46. leading: SizedBox(
  47. height: double.infinity,
  48. child: Icon(
  49. Icons.settings_rounded,
  50. color: Theme.of(context).textTheme.labelMedium?.color,
  51. size: 20,
  52. ),
  53. ),
  54. title: Text(
  55. "profile_drawer_settings",
  56. style: Theme.of(context)
  57. .textTheme
  58. .labelLarge
  59. ?.copyWith(fontWeight: FontWeight.bold),
  60. ).tr(),
  61. onTap: () {
  62. AutoRouter.of(context).push(const SettingsRoute());
  63. },
  64. );
  65. }
  66. buildAppLogButton() {
  67. return ListTile(
  68. leading: SizedBox(
  69. height: double.infinity,
  70. child: Icon(
  71. Icons.assignment_outlined,
  72. color: Theme.of(context).textTheme.labelMedium?.color,
  73. size: 20,
  74. ),
  75. ),
  76. title: Text(
  77. "profile_drawer_app_logs",
  78. style: Theme.of(context)
  79. .textTheme
  80. .labelLarge
  81. ?.copyWith(fontWeight: FontWeight.bold),
  82. ).tr(),
  83. onTap: () {
  84. AutoRouter.of(context).push(const AppLogRoute());
  85. },
  86. );
  87. }
  88. return Drawer(
  89. shape: const RoundedRectangleBorder(
  90. borderRadius: BorderRadius.zero,
  91. ),
  92. child: Column(
  93. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  94. children: [
  95. ListView(
  96. shrinkWrap: true,
  97. padding: EdgeInsets.zero,
  98. children: [
  99. const ProfileDrawerHeader(),
  100. buildSettingButton(),
  101. buildAppLogButton(),
  102. buildSignOutButton(),
  103. ],
  104. ),
  105. const ServerInfoBox(),
  106. ],
  107. ),
  108. );
  109. }
  110. }