server_info_box.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_hooks/flutter_hooks.dart';
  3. import 'package:hooks_riverpod/hooks_riverpod.dart';
  4. import 'package:immich_mobile/shared/models/server_info_state.model.dart';
  5. import 'package:easy_localization/easy_localization.dart';
  6. import 'package:immich_mobile/shared/providers/server_info.provider.dart';
  7. import 'package:package_info_plus/package_info_plus.dart';
  8. class ServerInfoBox extends HookConsumerWidget {
  9. const ServerInfoBox({
  10. Key? key,
  11. }) : super(key: key);
  12. @override
  13. Widget build(BuildContext context, WidgetRef ref) {
  14. ServerInfoState serverInfoState = ref.watch(serverInfoProvider);
  15. final appInfo = useState({});
  16. getPackageInfo() async {
  17. PackageInfo packageInfo = await PackageInfo.fromPlatform();
  18. appInfo.value = {
  19. "version": packageInfo.version,
  20. "buildNumber": packageInfo.buildNumber,
  21. };
  22. }
  23. useEffect(
  24. () {
  25. getPackageInfo();
  26. return null;
  27. },
  28. [],
  29. );
  30. return Padding(
  31. padding: const EdgeInsets.all(8.0),
  32. child: Card(
  33. elevation: 0,
  34. color: Theme.of(context).scaffoldBackgroundColor,
  35. shape: RoundedRectangleBorder(
  36. borderRadius: BorderRadius.circular(5), // if you need this
  37. side: const BorderSide(
  38. color: Color.fromARGB(101, 201, 201, 201),
  39. width: 1,
  40. ),
  41. ),
  42. child: Padding(
  43. padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8),
  44. child: Column(
  45. crossAxisAlignment: CrossAxisAlignment.center,
  46. children: [
  47. Padding(
  48. padding: const EdgeInsets.all(8.0),
  49. child: Text(
  50. serverInfoState.isVersionMismatch
  51. ? serverInfoState.versionMismatchErrorMessage
  52. : "profile_drawer_client_server_up_to_date".tr(),
  53. textAlign: TextAlign.center,
  54. style: TextStyle(
  55. fontSize: 11,
  56. color: Theme.of(context).primaryColor,
  57. fontWeight: FontWeight.w600,
  58. ),
  59. ),
  60. ),
  61. const Divider(
  62. color: Color.fromARGB(101, 201, 201, 201),
  63. thickness: 1,
  64. ),
  65. Row(
  66. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  67. children: [
  68. Text(
  69. "server_info_box_app_version".tr(),
  70. style: TextStyle(
  71. fontSize: 11,
  72. color: Colors.grey[500],
  73. fontWeight: FontWeight.bold,
  74. ),
  75. ),
  76. Text(
  77. "${appInfo.value["version"]} build.${appInfo.value["buildNumber"]}",
  78. style: TextStyle(
  79. fontSize: 11,
  80. color: Colors.grey[500],
  81. fontWeight: FontWeight.bold,
  82. ),
  83. ),
  84. ],
  85. ),
  86. const Divider(
  87. color: Color.fromARGB(101, 201, 201, 201),
  88. thickness: 1,
  89. ),
  90. Row(
  91. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  92. children: [
  93. Text(
  94. "server_info_box_server_version".tr(),
  95. style: TextStyle(
  96. fontSize: 11,
  97. color: Colors.grey[500],
  98. fontWeight: FontWeight.bold,
  99. ),
  100. ),
  101. Text(
  102. "${serverInfoState.serverVersion.major}.${serverInfoState.serverVersion.minor}.${serverInfoState.serverVersion.patch_}",
  103. style: TextStyle(
  104. fontSize: 11,
  105. color: Colors.grey[500],
  106. fontWeight: FontWeight.bold,
  107. ),
  108. ),
  109. ],
  110. ),
  111. ],
  112. ),
  113. ),
  114. ),
  115. );
  116. }
  117. }