Files
GitJournal/lib/screens/purchase_screen.dart
Vishesh Handa 957638d8a1 Change yearly subscription to 'One Time Purchase'
I could have a yearly subscription as well, but the screen is confusing
enough as it is. Also, by next year - I should have the Stripe
Integration running and I can possibly avoid the extra 30%.
2020-08-31 17:28:08 +02:00

232 lines
5.9 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:gitjournal/analytics.dart';
import 'package:gitjournal/screens/feature_timeline_screen.dart';
import 'package:gitjournal/widgets/purchase_widget.dart';
class PurchaseScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
appBar: AppBar(
title: Text(tr('purchase_screen.title')),
),
body: buildBody(context),
),
onWillPop: _onWillPop,
);
}
Widget buildBody(BuildContext context) {
Widget w = Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
child: Text(
tr('purchase_screen.desc'),
style: Theme.of(context).textTheme.bodyText2,
),
),
const SizedBox(height: 32.0),
PurchaseCards(
children: [
const SizedBox(width: 16.0),
const YearlyPurchaseWidget(),
const SizedBox(width: 16.0),
const MonthlyRentalWidget(),
const SizedBox(width: 16.0),
],
),
const SizedBox(height: 32.0),
Padding(
padding: const EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 16.0),
child: Row(
children: [
RestorePurchaseButton(),
OutlineButton(
child: Text(tr("feature_timeline.title")),
onPressed: () {
var route = MaterialPageRoute(
builder: (context) => FeatureTimelineScreen(),
settings: const RouteSettings(name: '/featureTimeline'),
);
Navigator.of(context).push(route);
},
),
],
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
),
),
],
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
);
return CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: w,
),
],
);
}
Future<bool> _onWillPop() async {
logEvent(Event.PurchaseScreenClose);
return true;
}
}
class MonthlyRentalWidget extends StatelessWidget {
const MonthlyRentalWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
var textTheme = Theme.of(context).textTheme;
return PurchaseCard(
child: Column(
children: [
// TODO: Translate this
Text("One Time Purchase", style: textTheme.headline5),
const SizedBox(height: 8.0),
Text("Paid Monthly", style: textTheme.subtitle1),
const SizedBox(height: 32.0),
PurchaseWidget(
skus: _generateSkus(),
defaultSku: "sku_monthly_min3",
timePeriod: "Month",
isSubscription: true,
),
const SizedBox(height: 32.0),
const Text(
"After 12 months or after paying the minimum 'One Time Purchase' amount, you will get all the benefits of a standard 'One Time Purchase'"),
],
mainAxisAlignment: MainAxisAlignment.start,
),
);
}
Set<String> _generateSkus() {
var list = <String>{};
for (var i = 0; i <= 25; i++) {
list.add("sku_monthly_min$i");
}
return list;
}
}
class YearlyPurchaseWidget extends StatelessWidget {
const YearlyPurchaseWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
var textTheme = Theme.of(context).textTheme;
return PurchaseCard(
child: Column(
children: [
Text("One Time Purchase", style: textTheme.headline5),
const Spacer(),
const SizedBox(height: 32.0),
PurchaseWidget(
skus: _generateSkus(),
defaultSku: "sku_yearly_1",
timePeriod: "Year",
isSubscription: false,
),
const SizedBox(height: 32.0),
const Text(
"Permanently enable all Pro features currently in GitJournal and new features added in the following 12 months."),
],
mainAxisAlignment: MainAxisAlignment.start,
),
);
}
Set<String> _generateSkus() {
var list = <String>{};
for (var i = 0; i <= 20; i++) {
list.add("sku_yearly_$i");
}
return list;
}
}
class PurchaseCard extends StatelessWidget {
final Widget child;
PurchaseCard({@required this.child});
@override
Widget build(BuildContext context) {
var mediaQuery = MediaQuery.of(context);
return Container(
width: mediaQuery.size.width * 0.80,
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16.0),
child: child,
),
),
);
}
}
class PurchaseCards extends StatelessWidget {
final List<Widget> children;
PurchaseCards({@required this.children});
@override
Widget build(BuildContext context) {
return _ScrollViewWithoutAnim(
scrollDirection: Axis.horizontal,
child: IntrinsicHeight(
child: Row(
children: children,
mainAxisSize: MainAxisSize.min,
),
),
);
}
}
class _ScrollViewWithoutAnim extends StatelessWidget {
final Widget child;
final Axis scrollDirection;
_ScrollViewWithoutAnim({
@required this.child,
this.scrollDirection,
});
@override
Widget build(BuildContext context) {
return NotificationListener<OverscrollIndicatorNotification>(
onNotification: (OverscrollIndicatorNotification overScroll) {
overScroll.disallowGlow();
return false;
},
child: SingleChildScrollView(
scrollDirection: scrollDirection,
child: child,
),
);
}
}