ente/lib/ui/email_entry_page.dart

341 lines
11 KiB
Dart
Raw Normal View History

2020-08-25 04:10:05 +00:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
2020-08-25 04:10:05 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
2020-08-25 23:02:43 +00:00
import 'package:photos/core/configuration.dart';
import 'package:photos/models/billing_plan.dart';
import 'package:photos/services/billing_service.dart';
2020-10-03 17:56:18 +00:00
import 'package:photos/services/user_service.dart';
2020-10-24 21:07:12 +00:00
import 'package:photos/ui/common_elements.dart';
import 'package:photos/ui/loading_widget.dart';
import 'package:photos/ui/web_page.dart';
2021-02-01 11:02:30 +00:00
import 'package:photos/utils/data_util.dart';
2020-10-28 19:07:39 +00:00
import 'package:photos/utils/dialog_util.dart';
import 'package:photos/utils/email_util.dart';
2020-08-25 04:10:05 +00:00
class EmailEntryPage extends StatefulWidget {
2020-08-25 23:02:43 +00:00
EmailEntryPage({Key key}) : super(key: key);
2020-08-25 04:10:05 +00:00
@override
_EmailEntryPageState createState() => _EmailEntryPageState();
}
class _EmailEntryPageState extends State<EmailEntryPage> {
2020-10-31 15:33:32 +00:00
final _config = Configuration.instance;
2020-11-01 08:10:35 +00:00
String _email;
String _name;
@override
void initState() {
_email = _config.getEmail();
_name = _config.getName();
super.initState();
}
2020-08-25 04:10:05 +00:00
@override
Widget build(BuildContext context) {
final appBar = AppBar(
2021-01-26 11:26:35 +00:00
title: Text(
"sign up",
style: TextStyle(
fontSize: 18,
),
2020-08-25 04:10:05 +00:00
),
);
return Scaffold(
appBar: appBar,
body: _getBody(appBar.preferredSize.height),
2020-08-25 04:10:05 +00:00
);
}
2021-01-06 16:09:42 +00:00
Widget _getBody(final appBarSize) {
final pageSize = MediaQuery.of(context).size.height;
final notifySize = MediaQuery.of(context).padding.top;
2020-08-25 06:00:19 +00:00
return SingleChildScrollView(
child: Container(
2021-01-06 16:09:42 +00:00
height: pageSize - (appBarSize + notifySize),
2020-08-25 06:00:19 +00:00
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
2021-01-26 11:26:35 +00:00
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
2020-08-25 06:00:19 +00:00
children: [
2020-12-12 00:31:06 +00:00
Padding(
2021-01-26 11:26:35 +00:00
padding: EdgeInsets.all(60),
2020-10-24 21:07:12 +00:00
),
2020-12-12 00:31:06 +00:00
Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
child: TextFormField(
decoration: InputDecoration(
2021-01-05 11:17:09 +00:00
hintText: 'name',
2020-12-12 00:31:06 +00:00
hintStyle: TextStyle(
color: Colors.white30,
),
contentPadding: EdgeInsets.all(12),
),
onChanged: (value) {
setState(() {
_name = value;
});
},
autocorrect: false,
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.words,
initialValue: _name,
2020-10-31 15:33:32 +00:00
),
),
2020-10-31 18:10:18 +00:00
Padding(padding: EdgeInsets.all(8)),
2020-12-12 00:31:06 +00:00
Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
child: TextFormField(
decoration: InputDecoration(
2021-01-05 11:17:09 +00:00
hintText: 'email',
2020-12-12 00:31:06 +00:00
hintStyle: TextStyle(
color: Colors.white30,
),
contentPadding: EdgeInsets.all(12),
),
onChanged: (value) {
setState(() {
_email = value;
});
},
autocorrect: false,
keyboardType: TextInputType.emailAddress,
initialValue: _email,
),
),
Padding(padding: EdgeInsets.all(8)),
Padding(
2020-12-12 00:31:06 +00:00
padding: const EdgeInsets.all(12),
child: RichText(
text: TextSpan(
children: [
2020-12-12 00:31:06 +00:00
TextSpan(
2021-01-05 11:17:09 +00:00
text: "by clicking sign up, I agree to the ",
2020-12-12 00:31:06 +00:00
),
TextSpan(
text: "terms of service",
style: TextStyle(
color: Colors.blue,
2021-01-06 16:09:42 +00:00
fontFamily: 'Ubuntu',
),
recognizer: TapGestureRecognizer()
..onTap = () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return WebPage(
"terms", "https://ente.io/terms");
},
),
);
},
),
TextSpan(text: " and "),
TextSpan(
text: "privacy policy",
style: TextStyle(
color: Colors.blue,
2021-01-06 16:09:42 +00:00
fontFamily: 'Ubuntu',
),
recognizer: TapGestureRecognizer()
..onTap = () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return WebPage(
"privacy", "https://ente.io/privacy");
},
),
);
},
),
],
style: TextStyle(
height: 1.25,
2021-01-03 14:19:30 +00:00
fontSize: 12,
2020-12-12 00:31:06 +00:00
fontFamily: 'Ubuntu',
color: Colors.white70,
),
),
textAlign: TextAlign.center,
),
),
2021-01-03 14:19:30 +00:00
Padding(padding: EdgeInsets.all(4)),
2020-10-24 21:07:12 +00:00
Container(
width: double.infinity,
2020-12-12 00:31:06 +00:00
height: 64,
padding: const EdgeInsets.fromLTRB(80, 0, 80, 0),
child: button(
"sign up",
2021-02-05 11:08:01 +00:00
onPressed: _email != null &&
_email.isNotEmpty &&
_name != null &&
_name.isNotEmpty
2020-12-12 00:31:06 +00:00
? () {
if (!isValidEmail(_email)) {
2021-01-08 17:06:52 +00:00
showErrorDialog(context, "invalid email address",
"please enter a valid email address.");
2020-12-12 00:31:06 +00:00
return;
}
_config.setEmail(_email);
_config.setName(_name);
UserService.instance.getOtt(context, _email);
}
: null,
fontSize: 18,
),
2020-12-12 00:31:06 +00:00
),
Expanded(child: Container()),
Align(
alignment: Alignment.center,
child: GestureDetector(
2021-02-05 11:44:52 +00:00
behavior: HitTestBehavior.opaque,
onTap: () {
showModalBottomSheet<void>(
context: context,
2021-02-05 11:44:52 +00:00
backgroundColor: Theme.of(context).cardColor,
builder: (BuildContext context) {
2021-01-03 14:19:30 +00:00
return PricingWidget();
});
},
child: Container(
padding: EdgeInsets.all(32),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"pricing",
),
Icon(Icons.arrow_drop_up),
],
),
),
),
),
2020-08-25 06:00:19 +00:00
],
2020-08-25 04:10:05 +00:00
),
2020-08-25 06:00:19 +00:00
),
2020-08-25 04:10:05 +00:00
);
}
}
2021-01-03 14:19:30 +00:00
class PricingWidget extends StatelessWidget {
const PricingWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return FutureBuilder<List<BillingPlan>>(
future: BillingService.instance.getBillingPlans(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return _buildPlans(context, snapshot.data);
} else if (snapshot.hasError) {
return Text("Oops, something went wrong.");
}
2021-02-05 11:44:52 +00:00
return loadWidget;
},
);
}
Container _buildPlans(BuildContext context, List<BillingPlan> plans) {
2021-01-06 08:47:18 +00:00
final planWidgets = List<BillingPlanWidget>();
for (final plan in plans) {
2021-01-06 08:47:18 +00:00
planWidgets.add(BillingPlanWidget(plan));
}
2021-01-03 14:19:30 +00:00
return Container(
height: 280,
2021-02-05 11:44:52 +00:00
color: Theme.of(context).cardColor,
2021-01-03 14:19:30 +00:00
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"pricing",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: planWidgets,
2021-01-03 14:19:30 +00:00
),
2021-01-06 11:55:29 +00:00
const Text("we offer a 14 day free trial"),
2021-01-03 14:19:30 +00:00
GestureDetector(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
Icons.close,
size: 12,
color: Colors.white38,
),
Padding(padding: EdgeInsets.all(1)),
Text(
"close",
style: TextStyle(
color: Colors.white38,
),
),
],
),
onTap: () => Navigator.pop(context),
)
],
),
);
}
}
2021-01-06 08:47:18 +00:00
class BillingPlanWidget extends StatelessWidget {
final BillingPlan plan;
const BillingPlanWidget(
this.plan, {
2021-01-03 14:19:30 +00:00
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2021-02-05 11:08:01 +00:00
return Padding(
2021-02-05 11:44:52 +00:00
padding: const EdgeInsets.all(2.0),
2021-02-05 11:08:01 +00:00
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
color: Colors.grey[850],
child: Container(
2021-02-05 11:44:52 +00:00
padding: EdgeInsets.fromLTRB(12, 20, 12, 20),
2021-02-05 11:08:01 +00:00
child: Column(
children: [
Text(
convertBytesToGBs(plan.storage, precision: 0).toString() +
" GB",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
2021-01-03 14:19:30 +00:00
),
2021-02-05 11:08:01 +00:00
Padding(
padding: EdgeInsets.all(4),
2021-01-03 14:19:30 +00:00
),
2021-02-05 11:08:01 +00:00
Text(
plan.price + " / " + plan.period,
style: TextStyle(
fontSize: 12,
2021-02-05 11:44:52 +00:00
color: Colors.white70,
2021-02-05 11:08:01 +00:00
),
),
],
),
2021-01-03 14:19:30 +00:00
),
),
);
}
}