security_section_widget.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @dart=2.9
  2. import 'package:ente_auth/core/configuration.dart';
  3. import 'package:ente_auth/l10n/l10n.dart';
  4. import 'package:ente_auth/services/local_authentication_service.dart';
  5. import 'package:ente_auth/theme/ente_theme.dart';
  6. import 'package:ente_auth/ui/account/sessions_page.dart';
  7. import 'package:ente_auth/ui/components/captioned_text_widget.dart';
  8. import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';
  9. import 'package:ente_auth/ui/components/menu_item_widget.dart';
  10. import 'package:ente_auth/ui/components/toggle_switch_widget.dart';
  11. import 'package:ente_auth/ui/settings/common_settings.dart';
  12. import 'package:flutter/material.dart';
  13. class SecuritySectionWidget extends StatefulWidget {
  14. const SecuritySectionWidget({Key key}) : super(key: key);
  15. @override
  16. State<SecuritySectionWidget> createState() => _SecuritySectionWidgetState();
  17. }
  18. class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
  19. final _config = Configuration.instance;
  20. @override
  21. void initState() {
  22. super.initState();
  23. }
  24. @override
  25. void dispose() {
  26. super.dispose();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return ExpandableMenuItemWidget(
  31. title: "Security",
  32. selectionOptionsWidget: _getSectionOptions(context),
  33. leadingIcon: Icons.local_police_outlined,
  34. );
  35. }
  36. Widget _getSectionOptions(BuildContext context) {
  37. final l10n = context.l10n;
  38. final List<Widget> children = [];
  39. children.addAll([
  40. MenuItemWidget(
  41. captionedTextWidget: const CaptionedTextWidget(
  42. title: "Lockscreen",
  43. ),
  44. trailingSwitch: ToggleSwitchWidget(
  45. value: _config.shouldShowLockScreen(),
  46. onChanged: (value) async {
  47. final hasAuthenticated = await LocalAuthenticationService.instance
  48. .requestLocalAuthForLockScreen(
  49. context,
  50. value,
  51. "Please authenticate to change lockscreen setting",
  52. "To enable lockscreen, please setup device passcode or screen lock in your system settings.",
  53. );
  54. if (hasAuthenticated) {
  55. setState(() {});
  56. }
  57. },
  58. ),
  59. ),
  60. sectionOptionSpacing,
  61. MenuItemWidget(
  62. captionedTextWidget: const CaptionedTextWidget(
  63. title: "Active sessions",
  64. ),
  65. pressedColor: getEnteColorScheme(context).fillFaint,
  66. trailingIcon: Icons.chevron_right_outlined,
  67. trailingIconIsMuted: true,
  68. onTap: () async {
  69. final hasAuthenticated = await LocalAuthenticationService.instance
  70. .requestLocalAuthentication(
  71. context,
  72. "Please authenticate to view your active sessions",
  73. );
  74. if (hasAuthenticated) {
  75. Navigator.of(context).push(
  76. MaterialPageRoute(
  77. builder: (BuildContext context) {
  78. return const SessionsPage();
  79. },
  80. ),
  81. );
  82. }
  83. },
  84. ),
  85. sectionOptionSpacing,
  86. ]);
  87. return Column(
  88. children: children,
  89. );
  90. }
  91. }