ente/lib/ui/landing_page.dart

419 lines
12 KiB
Dart
Raw Normal View History

2020-11-10 14:55:28 +00:00
import 'dart:async';
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:flutter/widgets.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
2021-02-02 16:35:38 +00:00
import 'package:photos/events/subscription_purchased_event.dart';
2021-01-06 16:09:42 +00:00
import 'package:photos/services/billing_service.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';
2021-01-06 16:09:42 +00:00
import 'package:photos/ui/subscription_page.dart';
2020-11-10 14:55:28 +00:00
2021-05-12 06:06:54 +00:00
class LandingPage extends StatefulWidget {
const LandingPage({Key key}) : super(key: key);
2020-11-10 14:55:28 +00:00
@override
2021-05-12 06:06:54 +00:00
_LandingPageState createState() => _LandingPageState();
2020-11-10 14:55:28 +00:00
}
2021-05-12 06:06:54 +00:00
class _LandingPageState extends State<LandingPage> {
2020-11-10 14:55:28 +00:00
StreamSubscription _userAuthEventSubscription;
2021-03-31 07:45:12 +00:00
double _featureIndex = 0;
2020-11-10 14:55:28 +00:00
@override
void initState() {
_userAuthEventSubscription =
2021-02-02 16:35:38 +00:00
Bus.instance.on<SubscriptionPurchasedEvent>().listen((event) {
2020-11-10 14:55:28 +00:00
setState(() {});
});
super.initState();
}
@override
void dispose() {
_userAuthEventSubscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
2021-01-06 16:09:42 +00:00
var hasConfiguredAccount = Configuration.instance.hasConfiguredAccount();
var hasSubscription = BillingService.instance.getSubscription() != null;
if (hasConfiguredAccount && hasSubscription) {
2020-11-10 14:55:28 +00:00
return Container();
} else {
2021-02-02 16:35:38 +00:00
return _getBody(context);
2020-11-10 14:55:28 +00:00
}
}
2021-03-31 07:45:12 +00:00
Widget _getBody(BuildContext context) {
return Container(
2021-05-12 06:05:57 +00:00
padding: EdgeInsets.fromLTRB(8, 40, 8, 8),
2021-03-31 07:45:12 +00:00
child: Column(
children: [
Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: "with ",
style: TextStyle(
fontSize: 16,
),
2021-03-31 07:45:12 +00:00
),
TextSpan(
text: "ente",
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 16,
),
),
],
),
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.all(2),
),
Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: "your ",
style: TextStyle(
fontSize: 16,
),
),
TextSpan(
text: "memories",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
TextSpan(
text: " are",
style: TextStyle(
fontSize: 16,
),
2021-03-31 07:45:12 +00:00
),
],
),
textAlign: TextAlign.center,
),
Padding(
2021-05-12 06:05:57 +00:00
padding: EdgeInsets.all(24),
2021-03-31 07:45:12 +00:00
),
_getFeatureSlider(),
new DotsIndicator(
dotsCount: 3,
position: _featureIndex,
decorator: DotsDecorator(
color: Colors.white24, // Inactive color
activeColor: Theme.of(context).buttonColor,
),
),
Padding(
2021-05-12 06:05:57 +00:00
padding: EdgeInsets.all(28),
2021-03-31 07:45:12 +00:00
),
_getSignUpButton(context),
2021-05-12 06:05:57 +00:00
Padding(
padding: EdgeInsets.all(4),
),
2021-03-31 07:45:12 +00:00
GestureDetector(
behavior: HitTestBehavior.translucent,
child: Container(
width: double.infinity,
padding: EdgeInsets.all(28),
child: Center(
2021-05-12 10:03:59 +00:00
child: Hero(
tag: "sign_in",
child: Material(
type: MaterialType.transparency,
child: Text(
"sign in",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
letterSpacing: 0.6,
),
),
),
2021-03-31 07:45:12 +00:00
),
),
),
2021-05-12 05:09:08 +00:00
onTap: _navigateToSignInPage,
2021-03-31 07:45:12 +00:00
),
2021-05-12 06:05:57 +00:00
Padding(
padding: EdgeInsets.all(4),
),
2021-03-31 07:45:12 +00:00
Divider(
2021-05-12 06:05:57 +00:00
height: 1,
2021-03-31 07:45:12 +00:00
color: Theme.of(context).buttonColor.withOpacity(0.5),
),
],
),
);
}
Container _getSignUpButton(BuildContext context) {
return Container(
2021-05-12 05:24:34 +00:00
padding: EdgeInsets.only(left: 80, right: 80),
width: double.infinity,
height: 64,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.fromLTRB(50, 16, 50, 16),
side: BorderSide(
width: 2,
color: Theme.of(context).accentColor,
2021-03-31 07:45:12 +00:00
),
),
2021-05-12 05:24:34 +00:00
child: Hero(
tag: "sign_up",
child: Material(
type: MaterialType.transparency,
child: Text(
"sign up",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
2021-05-12 06:05:57 +00:00
letterSpacing: 0.6,
2021-05-12 05:24:34 +00:00
),
),
),
2021-03-31 07:45:12 +00:00
),
2021-05-12 05:24:34 +00:00
onPressed: _navigateToSignUpPage,
2021-03-31 07:45:12 +00:00
),
);
}
2021-05-12 06:05:57 +00:00
Widget _getFeatureSlider() {
return Expanded(
2021-03-31 07:45:12 +00:00
child: PageView(
children: [
_getProtectedFeature(),
_getPreservedFeature(),
_getAccessibleFeature(),
],
onPageChanged: (index) {
setState(() {
_featureIndex = double.parse(index.toString());
});
},
),
);
}
Widget _getProtectedFeature() {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
"assets/protected.png",
height: 170,
),
2021-05-12 06:05:57 +00:00
Padding(padding: EdgeInsets.all(16)),
2021-03-31 07:45:12 +00:00
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"protected",
style: TextStyle(
2021-05-12 06:05:57 +00:00
fontSize: 18,
2021-03-31 07:45:12 +00:00
fontWeight: FontWeight.bold,
2021-05-12 06:05:57 +00:00
color: Theme.of(context).buttonColor,
),
2021-03-31 07:45:12 +00:00
),
2021-05-12 06:05:57 +00:00
Padding(padding: EdgeInsets.all(12)),
2021-03-31 07:45:12 +00:00
Container(
child: Text(
2021-05-12 06:05:57 +00:00
"end-to-end encrypted with your password,",
2021-03-31 07:45:12 +00:00
textAlign: TextAlign.center,
style: TextStyle(
2021-05-12 06:05:57 +00:00
color: Colors.white.withOpacity(0.9),
),
),
2021-03-31 07:45:12 +00:00
),
Padding(padding: EdgeInsets.all(2)),
Container(
child: Text(
2021-05-12 06:05:57 +00:00
"visible only to you",
2021-03-31 07:45:12 +00:00
textAlign: TextAlign.center,
style: TextStyle(
2021-05-12 06:05:57 +00:00
color: Colors.white.withOpacity(0.9),
2021-01-03 10:32:14 +00:00
),
),
2021-01-03 10:24:17 +00:00
),
],
),
2021-03-31 07:45:12 +00:00
),
],
),
);
}
Widget _getPreservedFeature() {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
"assets/protected.png",
height: 170,
),
Padding(padding: EdgeInsets.all(10)),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"preserved",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
Padding(padding: EdgeInsets.all(6)),
Container(
child: Text(
"reliably saved to multiple locations,",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white70,
2021-01-03 10:32:14 +00:00
),
),
2021-01-03 10:24:17 +00:00
),
2021-03-31 07:45:12 +00:00
Padding(padding: EdgeInsets.all(2)),
Container(
child: Text(
"including a fallout shelter",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white70,
2021-01-03 10:32:14 +00:00
),
),
2021-01-03 10:24:17 +00:00
),
],
),
2021-03-31 07:45:12 +00:00
),
],
),
);
}
Widget _getAccessibleFeature() {
return Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(
"assets/protected.png",
height: 170,
),
Padding(padding: EdgeInsets.all(10)),
Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"accessible",
2021-01-26 11:26:35 +00:00
style: TextStyle(
2021-03-31 07:45:12 +00:00
fontSize: 16,
2021-01-26 11:26:35 +00:00
fontWeight: FontWeight.bold,
),
2021-01-26 11:26:35 +00:00
textAlign: TextAlign.center,
),
2021-03-31 07:45:12 +00:00
Padding(padding: EdgeInsets.all(6)),
Container(
2021-03-30 11:08:41 +00:00
child: Text(
2021-03-31 07:45:12 +00:00
"available on all your devices,",
textAlign: TextAlign.center,
2021-03-30 11:08:41 +00:00
style: TextStyle(
2021-03-31 07:45:12 +00:00
color: Colors.white70,
2021-03-30 11:08:41 +00:00
),
),
),
2021-03-31 07:45:12 +00:00
],
2021-03-30 11:08:41 +00:00
),
2021-03-31 07:45:12 +00:00
),
Padding(padding: EdgeInsets.all(2)),
Container(
child: Text(
"android, ios and desktop",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white70,
),
),
),
2021-03-31 07:45:12 +00:00
],
2020-11-10 14:55:28 +00:00
),
);
}
void _navigateToSignUpPage() {
var page;
if (Configuration.instance.getToken() == 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 = SubscriptionPage(isOnboarding: true);
}
}
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
}
void _navigateToSignInPage() {
var page;
if (Configuration.instance.getToken() == 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 = SubscriptionPage(isOnboarding: true);
}
}
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
}
2020-11-10 14:55:28 +00:00
}