ente/lib/ui/settings_page.dart

178 lines
6 KiB
Dart
Raw Normal View History

import 'dart:io';
2020-09-09 14:04:11 +00:00
import 'package:flutter/foundation.dart';
2020-08-28 23:50:34 +00:00
import 'package:flutter/material.dart';
import "package:flutter_animate/flutter_animate.dart";
2021-07-27 14:51:45 +00:00
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/events/opened_settings_event.dart';
2023-04-07 04:57:54 +00:00
import "package:photos/generated/l10n.dart";
2023-01-09 06:05:27 +00:00
import 'package:photos/services/feature_flag_service.dart';
2023-02-17 08:49:11 +00:00
import "package:photos/services/storage_bonus_service.dart";
import 'package:photos/theme/colors.dart';
import 'package:photos/theme/ente_theme.dart';
2023-02-17 09:18:38 +00:00
import "package:photos/ui/components/notification_widget.dart";
2023-02-17 08:49:11 +00:00
import "package:photos/ui/growth/referral_screen.dart";
import 'package:photos/ui/settings/about_section_widget.dart';
import 'package:photos/ui/settings/account_section_widget.dart';
import 'package:photos/ui/settings/app_version_widget.dart';
2023-06-06 09:57:17 +00:00
import 'package:photos/ui/settings/backup/backup_section_widget.dart';
import 'package:photos/ui/settings/debug_section_widget.dart';
2022-12-06 17:47:37 +00:00
import 'package:photos/ui/settings/general_section_widget.dart';
import 'package:photos/ui/settings/inherited_settings_state.dart';
import 'package:photos/ui/settings/security_section_widget.dart';
import 'package:photos/ui/settings/settings_title_bar_widget.dart';
2022-03-08 07:04:53 +00:00
import 'package:photos/ui/settings/social_section_widget.dart';
import 'package:photos/ui/settings/storage_card_widget.dart';
import 'package:photos/ui/settings/support_section_widget.dart';
import 'package:photos/ui/settings/theme_switch_widget.dart';
2023-02-26 05:58:30 +00:00
import "package:photos/ui/sharing/verify_identity_dialog.dart";
2023-02-17 08:49:11 +00:00
import "package:photos/utils/navigation_util.dart";
2020-08-28 23:50:34 +00:00
class SettingsPage extends StatelessWidget {
final ValueNotifier<String?> emailNotifier;
2023-02-17 08:49:11 +00:00
const SettingsPage({Key? key, required this.emailNotifier}) : super(key: key);
2020-08-28 23:50:34 +00:00
@override
Widget build(BuildContext context) {
Bus.instance.fire(OpenedSettingsEvent());
final enteColorScheme = getEnteColorScheme(context);
2020-08-28 23:50:34 +00:00
return Scaffold(
2022-10-05 13:03:33 +00:00
body: Container(
2022-12-17 05:18:33 +00:00
color: enteColorScheme.backdropMuted,
child: SettingsStateContainer(
child: _getBody(context, enteColorScheme),
),
2022-10-07 04:56:29 +00:00
),
2020-08-28 23:50:34 +00:00
);
}
Widget _getBody(BuildContext context, EnteColorScheme colorScheme) {
2022-10-14 15:03:55 +00:00
final hasLoggedIn = Configuration.instance.isLoggedIn();
final enteTextTheme = getEnteTextTheme(context);
final List<Widget> contents = [];
2022-06-09 09:50:57 +00:00
contents.add(
2023-02-26 05:26:42 +00:00
GestureDetector(
onDoubleTap: () {
2023-02-26 05:58:30 +00:00
_showVerifyIdentityDialog(context);
},
onLongPress: () {
2023-02-26 05:58:30 +00:00
_showVerifyIdentityDialog(context);
},
2023-08-02 11:24:21 +00:00
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Align(
alignment: Alignment.centerLeft,
child: AnimatedBuilder(
// [AnimatedBuilder] accepts any [Listenable] subtype.
animation: emailNotifier,
builder: (BuildContext context, Widget? child) {
return Text(
emailNotifier.value!,
style: enteTextTheme.body.copyWith(
color: colorScheme.textMuted,
overflow: TextOverflow.ellipsis,
),
);
},
),
),
2022-06-09 09:50:57 +00:00
),
),
);
const sectionSpacing = SizedBox(height: 8);
contents.add(const SizedBox(height: 8));
2021-04-05 13:39:54 +00:00
if (hasLoggedIn) {
contents.addAll([
const StorageCardWidget(),
2023-02-17 08:49:11 +00:00
StorageBonusService.instance.shouldShowStorageBonus()
? RepaintBoundary(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: NotificationWidget(
startIcon: Icons.auto_awesome,
actionIcon: Icons.arrow_forward_outlined,
2023-04-07 04:57:54 +00:00
text: S.of(context).doubleYourStorage,
subText: S.of(context).referFriendsAnd2xYourPlan,
type: NotificationType.goldenBanner,
onTap: () async {
StorageBonusService.instance.markStorageBonusAsDone();
routeToPage(context, const ReferralScreen());
},
),
2023-02-22 15:04:03 +00:00
).animate(onPlay: (controller) => controller.repeat()).shimmer(
duration: 1000.ms,
delay: 3200.ms,
size: 0.6,
),
2023-02-17 08:49:11 +00:00
)
2023-02-18 03:59:23 +00:00
: const SizedBox(height: 12),
const BackupSectionWidget(),
sectionSpacing,
const AccountSectionWidget(),
sectionSpacing,
]);
}
contents.addAll([
const SecuritySectionWidget(),
sectionSpacing,
2022-12-07 05:21:47 +00:00
const GeneralSectionWidget(),
sectionSpacing,
]);
if (Platform.isAndroid || kDebugMode) {
contents.addAll([
const ThemeSwitchWidget(),
sectionSpacing,
]);
}
contents.addAll([
2022-07-04 06:02:17 +00:00
const SupportSectionWidget(),
sectionSpacing,
2022-07-04 06:02:17 +00:00
const SocialSectionWidget(),
sectionSpacing,
const AboutSectionWidget(),
]);
2022-05-17 17:23:00 +00:00
2023-01-09 06:05:27 +00:00
if (hasLoggedIn &&
FeatureFlagService.instance.isInternalUserOrDebugBuild()) {
contents.addAll([sectionSpacing, const DebugSectionWidget()]);
}
2022-07-04 06:02:17 +00:00
contents.add(const AppVersionWidget());
2022-06-11 08:23:52 +00:00
contents.add(
2022-07-04 06:02:17 +00:00
const Padding(
2022-06-11 08:23:52 +00:00
padding: EdgeInsets.only(bottom: 60),
),
);
2022-05-17 17:23:00 +00:00
2022-10-12 08:01:08 +00:00
return SafeArea(
bottom: false,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SettingsTitleBarWidget(),
Padding(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 24),
child: Column(
children: contents,
),
2022-06-13 15:14:49 +00:00
),
],
2022-07-03 06:56:43 +00:00
),
),
2020-08-28 23:50:34 +00:00
);
}
2023-02-26 05:58:30 +00:00
Future<void> _showVerifyIdentityDialog(BuildContext context) async {
await showDialog(
context: context,
builder: (BuildContext context) {
return VerifyIdentifyDialog(self: true);
},
);
}
2020-08-28 23:50:34 +00:00
}