ente/lib/ui/settings/about_section_widget.dart

129 lines
4.3 KiB
Dart
Raw Normal View History

2023-04-15 05:53:45 +00:00
import 'package:ente_auth/l10n/l10n.dart';
2022-11-01 06:13:06 +00:00
import 'package:ente_auth/services/update_service.dart';
import 'package:ente_auth/theme/ente_theme.dart';
import 'package:ente_auth/ui/common/web_page.dart';
import 'package:ente_auth/ui/components/captioned_text_widget.dart';
import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
import 'package:ente_auth/ui/components/menu_item_widget.dart';
import 'package:ente_auth/ui/settings/app_update_dialog.dart';
import 'package:ente_auth/ui/settings/common_settings.dart';
import 'package:ente_auth/utils/dialog_util.dart';
import 'package:ente_auth/utils/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
class AboutSectionWidget extends StatelessWidget {
2023-04-15 05:53:45 +00:00
const AboutSectionWidget({Key? key}) : super(key: key);
2022-11-01 06:13:06 +00:00
@override
Widget build(BuildContext context) {
return ExpandableMenuItemWidget(
2023-04-15 05:53:45 +00:00
title: context.l10n.about,
2022-11-01 06:13:06 +00:00
selectionOptionsWidget: _getSectionOptions(context),
leadingIcon: Icons.info_outline,
);
}
Widget _getSectionOptions(BuildContext context) {
return Column(
children: [
sectionOptionSpacing,
MenuItemWidget(
2023-04-15 05:53:45 +00:00
captionedTextWidget: CaptionedTextWidget(
title: context.l10n.weAreOpenSource,
2022-11-01 06:13:06 +00:00
),
pressedColor: getEnteColorScheme(context).fillFaint,
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
2023-08-09 06:30:37 +00:00
launchUrl(Uri.parse("https://github.com/ente-io/auth"));
2022-11-01 06:13:06 +00:00
},
),
sectionOptionSpacing,
2023-04-15 05:53:45 +00:00
AboutMenuItemWidget(
title: context.l10n.privacy,
url: "https://ente.io/privacy",
),
sectionOptionSpacing,
AboutMenuItemWidget(
title: context.l10n.termsOfServicesTitle,
url: "https://ente.io/terms",
),
sectionOptionSpacing,
2022-11-01 06:13:06 +00:00
UpdateService.instance.isIndependent()
? Column(
children: [
MenuItemWidget(
2023-04-15 05:53:45 +00:00
captionedTextWidget: CaptionedTextWidget(
title: context.l10n.checkForUpdates,
2022-11-01 06:13:06 +00:00
),
pressedColor: getEnteColorScheme(context).fillFaint,
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
final dialog =
2023-04-15 05:53:45 +00:00
createProgressDialog(context, context.l10n.checking);
2022-11-01 06:13:06 +00:00
await dialog.show();
final shouldUpdate =
await UpdateService.instance.shouldUpdate();
await dialog.hide();
if (shouldUpdate) {
showDialog(
context: context,
builder: (BuildContext context) {
return AppUpdateDialog(
UpdateService.instance.getLatestVersionInfo(),
);
},
barrierColor: Colors.black.withOpacity(0.85),
);
} else {
2023-04-15 05:53:45 +00:00
showShortToast(
context,
context.l10n.youAreOnTheLatestVersion,
);
2022-11-01 06:13:06 +00:00
}
},
),
sectionOptionSpacing,
],
)
: const SizedBox.shrink(),
],
);
}
}
class AboutMenuItemWidget extends StatelessWidget {
final String title;
final String url;
2023-04-09 13:40:34 +00:00
final String? webPageTitle;
2022-11-01 06:13:06 +00:00
const AboutMenuItemWidget({
2023-04-09 13:40:34 +00:00
required this.title,
required this.url,
2022-11-01 06:13:06 +00:00
this.webPageTitle,
2023-04-09 13:40:34 +00:00
Key? key,
2022-11-01 06:13:06 +00:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MenuItemWidget(
captionedTextWidget: CaptionedTextWidget(
title: title,
),
pressedColor: getEnteColorScheme(context).fillFaint,
trailingIcon: Icons.chevron_right_outlined,
trailingIconIsMuted: true,
onTap: () async {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return WebPage(webPageTitle ?? title, url);
},
),
);
},
);
}
}