ente/lib/ui/home/landing_page_widget.dart

286 lines
8.5 KiB
Dart
Raw Normal View History

2022-06-10 12:15:14 +00:00
import 'dart:io';
2021-03-31 07:45:12 +00:00
import 'package:dots_indicator/dots_indicator.dart';
2020-11-10 14:55:28 +00:00
import 'package:flutter/material.dart';
import 'package:photos/core/configuration.dart';
2022-04-08 05:59:20 +00:00
import 'package:photos/ente_theme_data.dart';
import "package:photos/generated/l10n.dart";
import 'package:photos/services/update_service.dart';
import 'package:photos/ui/account/email_entry_page.dart';
import 'package:photos/ui/account/login_page.dart';
import 'package:photos/ui/account/password_entry_page.dart';
import 'package:photos/ui/account/password_reentry_page.dart';
2022-07-03 10:09:01 +00:00
import 'package:photos/ui/common/gradient_button.dart';
import 'package:photos/ui/components/buttons/button_widget.dart';
2022-12-31 05:16:58 +00:00
import 'package:photos/ui/components/dialog_widget.dart';
import 'package:photos/ui/components/models/button_type.dart';
import 'package:photos/ui/payment/subscription.dart';
2020-11-10 14:55:28 +00:00
2021-05-29 17:01:59 +00:00
class LandingPageWidget extends StatefulWidget {
2022-12-28 08:07:07 +00:00
const LandingPageWidget({Key? key}) : super(key: key);
2020-11-10 14:55:28 +00:00
@override
2022-07-03 09:45:00 +00:00
State<LandingPageWidget> createState() => _LandingPageWidgetState();
2020-11-10 14:55:28 +00:00
}
2021-05-29 17:01:59 +00:00
class _LandingPageWidgetState extends State<LandingPageWidget> {
2021-03-31 07:45:12 +00:00
double _featureIndex = 0;
2020-11-10 14:55:28 +00:00
@override
void initState() {
super.initState();
Future(_showAutoLogoutDialogIfRequired);
}
2020-11-10 14:55:28 +00:00
@override
Widget build(BuildContext context) {
2021-05-12 15:59:07 +00:00
return Scaffold(body: _getBody(), resizeToAvoidBottomInset: false);
}
2021-05-12 15:59:07 +00:00
Widget _getBody() {
return Center(
child: SingleChildScrollView(
2021-05-12 15:59:07 +00:00
child: Column(
children: [
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.all(12)),
const Text(
2022-06-10 12:15:14 +00:00
"ente",
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
2022-06-10 13:55:41 +00:00
fontSize: 42,
2021-05-12 15:59:07 +00:00
),
2021-03-31 07:45:12 +00:00
),
2022-07-04 06:02:17 +00:00
const Padding(
2022-06-10 12:51:25 +00:00
padding: EdgeInsets.all(28),
2021-03-31 07:45:12 +00:00
),
2021-05-12 15:59:07 +00:00
_getFeatureSlider(),
2022-07-04 06:02:17 +00:00
const Padding(
2022-06-10 12:51:25 +00:00
padding: EdgeInsets.all(12),
),
DotsIndicator(
2021-05-12 15:59:07 +00:00
dotsCount: 3,
position: _featureIndex,
decorator: DotsDecorator(
2022-07-03 09:49:33 +00:00
activeColor:
Theme.of(context).colorScheme.dotsIndicatorActiveColor,
2022-06-10 12:51:25 +00:00
color: Theme.of(context).colorScheme.dotsIndicatorInactiveColor,
activeShape: RoundedRectangleBorder(
2022-06-11 08:23:52 +00:00
borderRadius: BorderRadius.circular(3),
),
2022-06-10 12:51:25 +00:00
shape: RoundedRectangleBorder(
2022-06-11 08:23:52 +00:00
borderRadius: BorderRadius.circular(3),
),
2022-07-04 06:02:17 +00:00
size: const Size(100, 5),
activeSize: const Size(100, 5),
spacing: const EdgeInsets.all(3),
2021-05-12 15:59:07 +00:00
),
),
2022-07-04 06:02:17 +00:00
const Padding(
2021-03-31 07:45:12 +00:00
padding: EdgeInsets.all(28),
2021-05-12 15:59:07 +00:00
),
_getSignUpButton(context),
2022-04-06 20:32:41 +00:00
Container(
width: double.infinity,
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.fromLTRB(20, 12, 20, 28),
2022-04-06 20:32:41 +00:00
child: Hero(
tag: "log_in",
child: ElevatedButton(
2022-07-03 09:49:33 +00:00
style:
Theme.of(context).colorScheme.optionalActionButtonStyle,
2022-07-03 09:45:00 +00:00
onPressed: _navigateToSignInPage,
child: Text(
S.of(context).existingUser,
style: const TextStyle(
color: Colors.black, // same for both themes
),
),
2021-03-31 07:45:12 +00:00
),
),
),
2022-07-04 06:02:17 +00:00
const Padding(
padding: EdgeInsets.all(20),
2021-05-12 15:59:07 +00:00
),
],
),
2021-03-31 07:45:12 +00:00
),
);
}
Widget _getSignUpButton(BuildContext context) {
2022-04-06 20:32:41 +00:00
return Container(
width: double.infinity,
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.symmetric(horizontal: 20),
2022-04-21 05:12:18 +00:00
child: GradientButton(
onTap: _navigateToSignUpPage,
text: S.of(context).newToEnte,
2021-03-31 07:45:12 +00:00
),
);
}
2021-05-12 06:05:57 +00:00
Widget _getFeatureSlider() {
2021-05-12 15:59:07 +00:00
return ConstrainedBox(
2022-07-04 06:02:17 +00:00
constraints: const BoxConstraints(maxHeight: 320),
2021-03-31 07:45:12 +00:00
child: PageView(
2022-06-10 12:15:14 +00:00
children: [
FeatureItemWidget(
2022-06-24 15:29:24 +00:00
"assets/onboarding_lock.png",
S.of(context).privateBackups,
S.of(context).forYourMemories,
S.of(context).endtoendEncryptedByDefault,
2022-06-10 12:15:14 +00:00
),
FeatureItemWidget(
2022-06-24 15:29:24 +00:00
"assets/onboarding_safe.png",
S.of(context).safelyStored,
S.of(context).atAFalloutShelter,
S.of(context).designedToOutlive,
2022-06-10 12:15:14 +00:00
),
2021-05-13 20:59:09 +00:00
FeatureItemWidget(
2022-07-07 08:44:03 +00:00
"assets/onboarding_sync.png",
S.of(context).available,
S.of(context).everywhere,
2022-07-03 09:49:33 +00:00
Platform.isAndroid
? S.of(context).androidIosWebDesktop
: S.of(context).mobileWebDesktop,
2022-06-10 12:15:14 +00:00
),
2021-03-31 07:45:12 +00:00
],
onPageChanged: (index) {
setState(() {
_featureIndex = double.parse(index.toString());
});
},
),
);
}
2022-12-31 05:16:58 +00:00
Future<void> _navigateToSignUpPage() async {
UpdateService.instance.hideChangeLog().ignore();
Widget page;
if (Configuration.instance.getEncryptedToken() == null) {
page = const EmailEntryPage();
} else {
// No key
if (Configuration.instance.getKeyAttributes() == null) {
// Never had a key
page = const PasswordEntryPage();
} else if (Configuration.instance.getKey() == null) {
// Yet to decrypt the key
page = const PasswordReentryPage();
} else {
// All is well, user just has not subscribed
page = getSubscriptionPage(isOnBoarding: true);
}
}
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
}
void _navigateToSignInPage() {
UpdateService.instance.hideChangeLog().ignore();
Widget page;
if (Configuration.instance.getEncryptedToken() == null) {
page = const LoginPage();
} else {
// No key
if (Configuration.instance.getKeyAttributes() == null) {
// Never had a key
page = const PasswordEntryPage();
} else if (Configuration.instance.getKey() == null) {
// Yet to decrypt the key
page = const PasswordReentryPage();
} else {
// All is well, user just has not subscribed
page = getSubscriptionPage(isOnBoarding: true);
}
}
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
}
Future<void> _showAutoLogoutDialogIfRequired() async {
final bool autoLogout = Configuration.instance.showAutoLogoutDialog();
if (autoLogout) {
final result = await showDialogWidget(
2022-12-31 05:16:58 +00:00
context: context,
title: S.of(context).pleaseLoginAgain,
body: S.of(context).devAccountChanged,
2022-12-31 05:16:58 +00:00
buttons: const [
ButtonWidget(
buttonType: ButtonType.neutral,
buttonAction: ButtonAction.first,
2023-02-14 09:48:28 +00:00
labelText: "OK",
2022-12-31 05:16:58 +00:00
isInAlert: true,
),
],
);
2022-12-31 05:16:58 +00:00
Configuration.instance.clearAutoLogoutFlag().ignore();
if (result?.action != null && result!.action == ButtonAction.first) {
2022-09-16 07:03:33 +00:00
_navigateToSignInPage();
}
}
}
2020-11-10 14:55:28 +00:00
}
2021-05-13 20:59:09 +00:00
class FeatureItemWidget extends StatelessWidget {
2022-07-03 09:49:33 +00:00
final String assetPath,
featureTitleFirstLine,
featureTitleSecondLine,
subText;
2022-06-10 12:15:14 +00:00
2021-05-13 20:59:09 +00:00
const FeatureItemWidget(
this.assetPath,
2022-06-10 12:15:14 +00:00
this.featureTitleFirstLine,
this.featureTitleSecondLine,
this.subText, {
2022-12-28 08:07:07 +00:00
Key? key,
2021-05-13 20:59:09 +00:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
assetPath,
height: 160,
),
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.all(16)),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
2022-06-10 12:15:14 +00:00
featureTitleFirstLine,
style: Theme.of(context).textTheme.headline5,
2021-05-13 20:59:09 +00:00
),
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.all(2)),
Text(
2022-06-10 12:15:14 +00:00
featureTitleSecondLine,
style: Theme.of(context).textTheme.headline5,
),
2022-07-04 06:02:17 +00:00
const Padding(padding: EdgeInsets.all(12)),
Text(
2022-06-10 12:15:14 +00:00
subText,
textAlign: TextAlign.center,
style: TextStyle(
2022-06-10 12:15:14 +00:00
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.5),
fontSize: 16,
),
),
],
),
],
2021-05-13 20:59:09 +00:00
);
}
}