profile_drawer.dart 3.6 KB

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