about_section_widget.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/services/update_service.dart';
  3. import 'package:photos/theme/ente_theme.dart';
  4. import 'package:photos/ui/common/web_page.dart';
  5. import 'package:photos/ui/components/captioned_text_widget.dart';
  6. import 'package:photos/ui/components/expandable_menu_item_widget.dart';
  7. import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
  8. import 'package:photos/ui/settings/app_update_dialog.dart';
  9. import 'package:photos/ui/settings/common_settings.dart';
  10. import 'package:photos/utils/dialog_util.dart';
  11. import 'package:photos/utils/toast_util.dart';
  12. import 'package:url_launcher/url_launcher.dart';
  13. class AboutSectionWidget extends StatelessWidget {
  14. const AboutSectionWidget({Key? key}) : super(key: key);
  15. @override
  16. Widget build(BuildContext context) {
  17. return ExpandableMenuItemWidget(
  18. title: "About",
  19. selectionOptionsWidget: _getSectionOptions(context),
  20. leadingIcon: Icons.info_outline,
  21. );
  22. }
  23. Widget _getSectionOptions(BuildContext context) {
  24. return Column(
  25. children: [
  26. sectionOptionSpacing,
  27. MenuItemWidget(
  28. captionedTextWidget: const CaptionedTextWidget(
  29. title: "We are open source!",
  30. ),
  31. pressedColor: getEnteColorScheme(context).fillFaint,
  32. trailingIcon: Icons.chevron_right_outlined,
  33. trailingIconIsMuted: true,
  34. onTap: () async {
  35. launchUrl(Uri.parse("https://github.com/ente-io/photos-app"));
  36. },
  37. ),
  38. sectionOptionSpacing,
  39. const AboutMenuItemWidget(
  40. title: "Privacy",
  41. url: "https://ente.io/privacy",
  42. ),
  43. sectionOptionSpacing,
  44. const AboutMenuItemWidget(
  45. title: "Terms",
  46. url: "https://ente.io/terms",
  47. ),
  48. sectionOptionSpacing,
  49. UpdateService.instance.isIndependent()
  50. ? Column(
  51. children: [
  52. MenuItemWidget(
  53. captionedTextWidget: const CaptionedTextWidget(
  54. title: "Check for updates",
  55. ),
  56. pressedColor: getEnteColorScheme(context).fillFaint,
  57. trailingIcon: Icons.chevron_right_outlined,
  58. trailingIconIsMuted: true,
  59. onTap: () async {
  60. final dialog =
  61. createProgressDialog(context, "Checking...");
  62. await dialog.show();
  63. final shouldUpdate =
  64. await UpdateService.instance.shouldUpdate();
  65. await dialog.hide();
  66. if (shouldUpdate) {
  67. showDialog(
  68. context: context,
  69. builder: (BuildContext context) {
  70. return AppUpdateDialog(
  71. UpdateService.instance.getLatestVersionInfo(),
  72. );
  73. },
  74. barrierColor: Colors.black.withOpacity(0.85),
  75. );
  76. } else {
  77. showShortToast(
  78. context,
  79. "You are on the latest version",
  80. );
  81. }
  82. },
  83. ),
  84. sectionOptionSpacing,
  85. ],
  86. )
  87. : const SizedBox.shrink(),
  88. ],
  89. );
  90. }
  91. }
  92. class AboutMenuItemWidget extends StatelessWidget {
  93. final String title;
  94. final String url;
  95. final String? webPageTitle;
  96. const AboutMenuItemWidget({
  97. required this.title,
  98. required this.url,
  99. this.webPageTitle,
  100. Key? key,
  101. }) : super(key: key);
  102. @override
  103. Widget build(BuildContext context) {
  104. return MenuItemWidget(
  105. captionedTextWidget: CaptionedTextWidget(
  106. title: title,
  107. ),
  108. pressedColor: getEnteColorScheme(context).fillFaint,
  109. trailingIcon: Icons.chevron_right_outlined,
  110. trailingIconIsMuted: true,
  111. onTap: () async {
  112. Navigator.of(context).push(
  113. MaterialPageRoute(
  114. builder: (BuildContext context) {
  115. return WebPage(webPageTitle ?? title, url);
  116. },
  117. ),
  118. );
  119. },
  120. );
  121. }
  122. }