ente/lib/ui/sign_in_header_widget.dart

213 lines
6.7 KiB
Dart
Raw Normal View History

2020-11-10 14:55:28 +00:00
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/events/user_authenticated_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-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-03 10:24:17 +00:00
import 'package:expansion_card/expansion_card.dart';
2021-01-06 16:09:42 +00:00
import 'package:photos/ui/subscription_page.dart';
2020-11-10 14:55:28 +00:00
class SignInHeader extends StatefulWidget {
const SignInHeader({Key key}) : super(key: key);
@override
_SignInHeaderState createState() => _SignInHeaderState();
}
class _SignInHeaderState extends State<SignInHeader> {
StreamSubscription _userAuthEventSubscription;
@override
void initState() {
_userAuthEventSubscription =
Bus.instance.on<UserAuthenticatedEvent>().listen((event) {
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 hasValidSubscription = BillingService.instance.hasActiveSubscription();
if (hasConfiguredAccount && hasValidSubscription) {
2020-11-10 14:55:28 +00:00
return Container();
}
return SingleChildScrollView(
child: Container(
padding: EdgeInsets.fromLTRB(8, 20, 8, 8),
child: Column(
children: [
Text.rich(
TextSpan(
children: <TextSpan>[
TextSpan(
text: "with ",
style: TextStyle(
fontSize: 16,
),
),
TextSpan(
text: "ente",
style: TextStyle(
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
fontSize: 16,
),
),
],
),
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.all(6),
),
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,
),
),
],
),
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.all(8),
2020-11-10 14:55:28 +00:00
),
2021-01-03 10:24:17 +00:00
ExpansionCard(
title: Text('protected'),
margin: EdgeInsets.all(0),
children: <Widget>[
2021-01-03 10:32:14 +00:00
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Text(
'only visible to you as they are encrypted by your master key',
),
),
2021-01-03 10:24:17 +00:00
),
],
),
2021-01-03 10:24:17 +00:00
ExpansionCard(
title: Text('preserved'),
margin: EdgeInsets.all(0),
children: <Widget>[
2021-01-03 10:32:14 +00:00
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Text(
'stored in multiple locations including an underground fallout shelter',
),
),
2021-01-03 10:24:17 +00:00
),
],
),
2021-01-03 10:24:17 +00:00
ExpansionCard(
title: Text('accessible'),
margin: EdgeInsets.all(0),
children: <Widget>[
2021-01-03 10:32:14 +00:00
Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
child: Text(
'available on all your devices',
),
),
2021-01-03 10:24:17 +00:00
),
],
),
Padding(
padding: EdgeInsets.all(10),
),
Padding(
padding: const EdgeInsets.fromLTRB(60, 0, 60, 0),
),
Container(
width: double.infinity,
height: 64,
child: RaisedButton(
child: Hero(
tag: "sign_up_hero_text",
child: Material(
color: Colors.transparent,
child: Text(
2021-01-06 16:09:42 +00:00
!hasConfiguredAccount ? "sign up" : "subscribe",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
textAlign: TextAlign.center,
),
),
),
onPressed: () {
var page;
if (Configuration.instance.getToken() == null) {
page = EmailEntryPage();
} else {
// No key
2021-01-06 16:09:42 +00:00
if (Configuration.instance.getKeyAttributes() == null) {
// Never had a key
2021-01-05 14:27:02 +00:00
page = PasswordEntryPage();
2021-01-06 16:09:42 +00:00
} else if (Configuration.instance.getKey() == null) {
// Yet to decrypt the key
page = PasswordReentryPage();
} else {
page = SubscriptionPage();
2020-12-12 00:31:06 +00:00
}
}
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return page;
},
),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
2020-12-12 00:31:06 +00:00
),
2020-11-10 14:55:28 +00:00
),
Padding(padding: EdgeInsets.all(10)),
Divider(
height: 2,
),
],
),
2020-11-10 14:55:28 +00:00
),
);
}
}