about_section_widget.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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.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, "You are on the latest version");
  79. }
  80. },
  81. ),
  82. sectionOptionSpacing,
  83. ],
  84. )
  85. : const SizedBox.shrink(),
  86. ],
  87. );
  88. }
  89. }
  90. class AboutMenuItemWidget extends StatelessWidget {
  91. final String title;
  92. final String url;
  93. final String? webPageTitle;
  94. const AboutMenuItemWidget({
  95. required this.title,
  96. required this.url,
  97. this.webPageTitle,
  98. Key? key,
  99. }) : super(key: key);
  100. @override
  101. Widget build(BuildContext context) {
  102. return MenuItemWidget(
  103. captionedTextWidget: CaptionedTextWidget(
  104. title: title,
  105. ),
  106. pressedColor: getEnteColorScheme(context).fillFaint,
  107. trailingIcon: Icons.chevron_right_outlined,
  108. trailingIconIsMuted: true,
  109. onTap: () {
  110. Navigator.of(context).push(
  111. MaterialPageRoute(
  112. builder: (BuildContext context) {
  113. return WebPage(webPageTitle ?? title, url);
  114. },
  115. ),
  116. );
  117. },
  118. );
  119. }
  120. }