ente/lib/ui/landing_page_widget.dart

243 lines
6.6 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';
2022-04-21 05:12:18 +00:00
import 'package:photos/ui/common/gradientButton.dart';
2020-11-10 14:55:28 +00:00
import 'package:photos/ui/email_entry_page.dart';
2021-03-30 11:08:41 +00:00
import 'package:photos/ui/login_page.dart';
2021-01-05 14:27:02 +00:00
import 'package:photos/ui/password_entry_page.dart';
import 'package:photos/ui/password_reentry_page.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 {
const LandingPageWidget({Key key}) : super(key: key);
2020-11-10 14:55:28 +00:00
@override
2021-05-29 17:01:59 +00:00
_LandingPageWidgetState 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
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: [
Padding(padding: const EdgeInsets.all(12)),
2022-06-10 12:15:14 +00:00
Text(
"ente",
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 36,
2021-05-12 15:59:07 +00:00
),
2021-03-31 07:45:12 +00:00
),
2021-05-12 15:59:07 +00:00
Padding(
padding: EdgeInsets.all(24),
2021-03-31 07:45:12 +00:00
),
2021-05-12 15:59:07 +00:00
_getFeatureSlider(),
DotsIndicator(
2021-05-12 15:59:07 +00:00
dotsCount: 3,
position: _featureIndex,
decorator: DotsDecorator(
activeColor: Theme.of(context).buttonColor,
),
),
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,
padding: EdgeInsets.fromLTRB(20, 12, 20, 28),
2022-04-06 20:32:41 +00:00
child: Hero(
tag: "log_in",
child: ElevatedButton(
style:
Theme.of(context).colorScheme.optionalActionButtonStyle,
child: Text(
2022-05-30 14:13:19 +00:00
"Existing user",
style: TextStyle(
color: Colors.black, // same for both themes
),
),
2022-04-06 20:32:41 +00:00
onPressed: _navigateToSignInPage,
2021-03-31 07:45:12 +00:00
),
),
),
2021-05-12 15:59:07 +00:00
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-04-21 05:12:18 +00:00
padding: EdgeInsets.symmetric(horizontal: 20),
child: GradientButton(
child: Text(
"New to ente",
style: gradientButtonTextTheme(),
2021-03-31 07:45:12 +00:00
),
2022-04-21 05:12:18 +00:00
linearGradientColors: const [
Color(0xFF2CD267),
Color(0xFF1DB954),
],
onTap: _navigateToSignUpPage,
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(
constraints: BoxConstraints(maxHeight: 320),
2021-03-31 07:45:12 +00:00
child: PageView(
2022-06-10 12:15:14 +00:00
children: [
FeatureItemWidget(
"assets/protected.png",
"Private backups",
"for your memories",
"end-to-end encrypted by default",
),
2021-05-13 20:59:09 +00:00
FeatureItemWidget(
2022-06-10 12:15:14 +00:00
"assets/preserved.png",
"Safely stored",
"at a fallout shelter",
"designed to outlive",
),
2021-05-13 20:59:09 +00:00
FeatureItemWidget(
2022-06-10 12:15:14 +00:00
"assets/synced.png",
"Available",
"everywhere",
Platform.isAndroid
? "android, ios, web, desktop"
: "ios, android, web, desktop",
),
2021-03-31 07:45:12 +00:00
],
onPageChanged: (index) {
setState(() {
_featureIndex = double.parse(index.toString());
});
},
),
);
}
void _navigateToSignUpPage() {
Widget page;
if (Configuration.instance.getEncryptedToken() == null) {
page = EmailEntryPage();
} else {
// No key
if (Configuration.instance.getKeyAttributes() == null) {
// Never had a key
page = PasswordEntryPage();
} else if (Configuration.instance.getKey() == null) {
// Yet to decrypt the key
page = 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() {
Widget page;
if (Configuration.instance.getEncryptedToken() == null) {
page = LoginPage();
} else {
// No key
if (Configuration.instance.getKeyAttributes() == null) {
// Never had a key
page = PasswordEntryPage();
} else if (Configuration.instance.getKey() == null) {
// Yet to decrypt the key
page = PasswordReentryPage();
} else {
// All is well, user just has not subscribed
page = getSubscriptionPage(isOnBoarding: true);
}
}
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
}
2020-11-10 14:55:28 +00:00
}
2021-05-13 20:59:09 +00:00
class FeatureItemWidget extends StatelessWidget {
2022-06-10 12:15:14 +00:00
final String assetPath,
featureTitleFirstLine,
featureTitleSecondLine,
subText;
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, {
2021-05-13 20:59:09 +00:00
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
assetPath,
height: 160,
),
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-06-10 12:15:14 +00:00
Padding(padding: EdgeInsets.all(2)),
Text(
2022-06-10 12:15:14 +00:00
featureTitleSecondLine,
style: Theme.of(context).textTheme.headline5,
),
2022-06-10 12:15:14 +00:00
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
);
}
}