profile_drawer.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import 'package:auto_route/auto_route.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_hooks/flutter_hooks.dart';
  4. import 'package:hooks_riverpod/hooks_riverpod.dart';
  5. import 'package:immich_mobile/shared/providers/asset.provider.dart';
  6. import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
  7. import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
  8. import 'package:immich_mobile/shared/models/server_info_state.model.dart';
  9. import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
  10. import 'package:immich_mobile/shared/providers/server_info.provider.dart';
  11. import 'package:immich_mobile/shared/providers/websocket.provider.dart';
  12. import 'package:package_info_plus/package_info_plus.dart';
  13. class ProfileDrawer extends HookConsumerWidget {
  14. const ProfileDrawer({Key? key}) : super(key: key);
  15. @override
  16. Widget build(BuildContext context, WidgetRef ref) {
  17. AuthenticationState _authState = ref.watch(authenticationProvider);
  18. ServerInfoState _serverInfoState = ref.watch(serverInfoProvider);
  19. final appInfo = useState({});
  20. _getPackageInfo() async {
  21. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  22. appInfo.value = {
  23. "version": packageInfo.version,
  24. "buildNumber": packageInfo.buildNumber,
  25. };
  26. }
  27. useEffect(() {
  28. _getPackageInfo();
  29. return null;
  30. }, []);
  31. return Drawer(
  32. shape: const RoundedRectangleBorder(
  33. borderRadius: BorderRadius.only(
  34. topRight: Radius.circular(5),
  35. bottomRight: Radius.circular(5),
  36. ),
  37. ),
  38. child: Column(
  39. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  40. children: [
  41. ListView(
  42. shrinkWrap: true,
  43. padding: EdgeInsets.zero,
  44. children: [
  45. DrawerHeader(
  46. decoration: BoxDecoration(
  47. color: Colors.grey[200],
  48. ),
  49. child: Column(
  50. mainAxisAlignment: MainAxisAlignment.center,
  51. crossAxisAlignment: CrossAxisAlignment.center,
  52. children: [
  53. const Image(
  54. image: AssetImage('assets/immich-logo-no-outline.png'),
  55. width: 50,
  56. filterQuality: FilterQuality.high,
  57. ),
  58. const Padding(padding: EdgeInsets.all(8)),
  59. Text(
  60. _authState.userEmail,
  61. style: TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold),
  62. )
  63. ],
  64. ),
  65. ),
  66. ListTile(
  67. tileColor: Colors.grey[100],
  68. leading: const Icon(
  69. Icons.logout_rounded,
  70. color: Colors.black54,
  71. ),
  72. title: const Text(
  73. "Sign Out",
  74. style: TextStyle(color: Colors.black54, fontSize: 14, fontWeight: FontWeight.bold),
  75. ),
  76. onTap: () async {
  77. bool res = await ref.read(authenticationProvider.notifier).logout();
  78. if (res) {
  79. ref.watch(backupProvider.notifier).cancelBackup();
  80. ref.watch(assetProvider.notifier).clearAllAsset();
  81. ref.watch(websocketProvider.notifier).disconnect();
  82. AutoRouter.of(context).popUntilRoot();
  83. }
  84. },
  85. )
  86. ],
  87. ),
  88. Padding(
  89. padding: const EdgeInsets.all(8.0),
  90. child: Card(
  91. color: Colors.grey[100],
  92. child: Padding(
  93. padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8),
  94. child: Column(
  95. crossAxisAlignment: CrossAxisAlignment.center,
  96. children: [
  97. Padding(
  98. padding: const EdgeInsets.all(8.0),
  99. child: Text(
  100. _serverInfoState.isVersionMismatch
  101. ? _serverInfoState.versionMismatchErrorMessage
  102. : "Client and Server are up-to-date",
  103. textAlign: TextAlign.center,
  104. style:
  105. TextStyle(fontSize: 11, color: Theme.of(context).primaryColor, fontWeight: FontWeight.w600),
  106. ),
  107. ),
  108. const Divider(),
  109. Row(
  110. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  111. children: [
  112. Text(
  113. "App Version",
  114. style: TextStyle(
  115. fontSize: 11,
  116. color: Colors.grey[500],
  117. fontWeight: FontWeight.bold,
  118. ),
  119. ),
  120. Text(
  121. "${appInfo.value["version"]} build.${appInfo.value["buildNumber"]}",
  122. style: TextStyle(
  123. fontSize: 11,
  124. color: Colors.grey[500],
  125. fontWeight: FontWeight.bold,
  126. ),
  127. ),
  128. ],
  129. ),
  130. const Divider(),
  131. Row(
  132. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  133. children: [
  134. Text(
  135. "Server Version",
  136. style: TextStyle(
  137. fontSize: 11,
  138. color: Colors.grey[500],
  139. fontWeight: FontWeight.bold,
  140. ),
  141. ),
  142. Text(
  143. "${_serverInfoState.serverVersion.major}.${_serverInfoState.serverVersion.minor}.${_serverInfoState.serverVersion.patch}",
  144. style: TextStyle(
  145. fontSize: 11,
  146. color: Colors.grey[500],
  147. fontWeight: FontWeight.bold,
  148. ),
  149. ),
  150. ],
  151. ),
  152. ],
  153. ),
  154. ),
  155. ),
  156. )
  157. ],
  158. ),
  159. );
  160. }
  161. }