ente/lib/ui/settings_page.dart

154 lines
5.1 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';
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-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';
import 'package:photos/ui/settings/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-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(
Container(
constraints: const BoxConstraints(maxWidth: 350),
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()
? Padding(
padding: const EdgeInsets.only(top: 4.0),
child: NotificationWidget(
startIcon: Icons.auto_awesome,
actionIcon: Icons.arrow_forward_outlined,
text: "Double your storage",
subText: "Refer friends and 2x your plan",
type: NotificationType.banner,
onTap: () async {
StorageBonusService.instance.markStorageBonusAsDone();
routeToPage(context, const ReferralScreen());
},
),
)
: const SizedBox.shrink(),
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
);
}
}