2022-02-03 09:06:44 -07:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2022-03-18 18:23:05 -07:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
2022-03-21 23:22:04 -07:00
|
|
|
import 'package:immich_mobile/shared/models/server_info_state.model.dart';
|
2022-02-13 14:10:42 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/backup.provider.dart';
|
2022-03-21 23:22:04 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/server_info.provider.dart';
|
2022-02-14 09:40:41 -07:00
|
|
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
2022-03-18 18:23:05 -07:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2022-02-03 09:06:44 -07:00
|
|
|
|
2022-03-18 18:23:05 -07:00
|
|
|
class ProfileDrawer extends HookConsumerWidget {
|
2022-02-03 09:06:44 -07:00
|
|
|
const ProfileDrawer({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
AuthenticationState _authState = ref.watch(authenticationProvider);
|
2022-03-21 23:22:04 -07:00
|
|
|
ServerInfoState _serverInfoState = ref.watch(serverInfoProvider);
|
|
|
|
|
2022-03-18 18:23:05 -07:00
|
|
|
final appInfo = useState({});
|
|
|
|
|
|
|
|
_getPackageInfo() async {
|
|
|
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
|
|
|
|
|
|
|
appInfo.value = {
|
|
|
|
"version": packageInfo.version,
|
|
|
|
"buildNumber": packageInfo.buildNumber,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() {
|
|
|
|
_getPackageInfo();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}, []);
|
2022-02-03 09:06:44 -07:00
|
|
|
|
|
|
|
return Drawer(
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topRight: Radius.circular(5),
|
|
|
|
bottomRight: Radius.circular(5),
|
|
|
|
),
|
|
|
|
),
|
2022-03-18 18:23:05 -07:00
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-02-03 09:06:44 -07:00
|
|
|
children: [
|
2022-03-18 18:23:05 -07:00
|
|
|
ListView(
|
|
|
|
shrinkWrap: true,
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
children: [
|
|
|
|
DrawerHeader(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.grey[200],
|
2022-02-03 09:06:44 -07:00
|
|
|
),
|
2022-03-18 18:23:05 -07:00
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Image(
|
|
|
|
image: AssetImage('assets/immich-logo-no-outline.png'),
|
|
|
|
width: 50,
|
|
|
|
filterQuality: FilterQuality.high,
|
|
|
|
),
|
|
|
|
const Padding(padding: EdgeInsets.all(8)),
|
|
|
|
Text(
|
|
|
|
_authState.userEmail,
|
|
|
|
style: TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
tileColor: Colors.grey[100],
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.logout_rounded,
|
|
|
|
color: Colors.black54,
|
|
|
|
),
|
|
|
|
title: const Text(
|
|
|
|
"Sign Out",
|
|
|
|
style: TextStyle(color: Colors.black54, fontSize: 14),
|
|
|
|
),
|
|
|
|
onTap: () async {
|
|
|
|
bool res = await ref.read(authenticationProvider.notifier).logout();
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
ref.watch(backupProvider.notifier).cancelBackup();
|
|
|
|
ref.watch(assetProvider.notifier).clearAllAsset();
|
|
|
|
ref.watch(websocketProvider.notifier).disconnect();
|
|
|
|
AutoRouter.of(context).popUntilRoot();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
2022-02-03 09:06:44 -07:00
|
|
|
),
|
2022-03-18 18:23:05 -07:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
2022-03-21 23:22:04 -07:00
|
|
|
child: Card(
|
|
|
|
color: Colors.grey[100],
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Text(
|
|
|
|
_serverInfoState.isVersionMismatch
|
|
|
|
? _serverInfoState.versionMismatchErrorMessage
|
|
|
|
: "Client and Server are up-to-date",
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style:
|
|
|
|
TextStyle(fontSize: 11, color: Theme.of(context).primaryColor, fontWeight: FontWeight.w600),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"App Version",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: Colors.grey[500],
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${appInfo.value["version"]} build.${appInfo.value["buildNumber"]}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: Colors.grey[500],
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Server Version",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: Colors.grey[500],
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
"${_serverInfoState.serverVersion.major}.${_serverInfoState.serverVersion.minor}.${_serverInfoState.serverVersion.patch}",
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: Colors.grey[500],
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-03-18 18:23:05 -07:00
|
|
|
),
|
2022-02-03 09:06:44 -07:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|