213 lines
6.1 KiB
Dart
213 lines
6.1 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:mnemo_cards/main.dart';
|
|
import 'package:mnemo_cards/utils/string_helper.dart';
|
|
import 'package:mnemo_cards_common/mnemo_cards_common.dart';
|
|
import 'package:mnemo_cards_frontend_common/mnemo_cards_frontend_common.dart';
|
|
|
|
import '../di/injector.dart';
|
|
import '../di/locator.dart';
|
|
import '../domain/router/app_router.dart';
|
|
import '../features/packs/packs_api.dart';
|
|
import '../theme/themes.dart';
|
|
|
|
class MobileBuySubscriptionWidget extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BuySubscriptionWidget(onBuySubscription: onBuySubscription);
|
|
}
|
|
|
|
Future<void> onBuySubscription() async {
|
|
final user = locator.userManager.userStateHolder.user;
|
|
if (user == null) {
|
|
AppRouter.openAuthOrProfile();
|
|
return;
|
|
}
|
|
final api = locator.subscriptionApi;
|
|
final buyDto = await api.getBuySubscription().catchError((_) => null);
|
|
if (buyDto != null) {
|
|
showDialog(
|
|
context: scaffoldKey.currentContext!,
|
|
builder: (_) => SubscriptionPage(buyDto.page!),
|
|
);
|
|
}
|
|
}
|
|
|
|
const MobileBuySubscriptionWidget();
|
|
}
|
|
|
|
class SubscriptionPage extends StatelessWidget {
|
|
final SubscriptionPageDto dto;
|
|
|
|
SubscriptionPage(this.dto);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Column(
|
|
children: [
|
|
Header(dto.title, hasPopButton: true, center: true),
|
|
...dto.items.build(),
|
|
...dto.plans.map(_SubscriptionPlanWidget.new),
|
|
BigBackButton(),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _SubscriptionPlanWidget extends StatelessWidget {
|
|
final SubscriptionPlanDto plan;
|
|
|
|
_SubscriptionPlanWidget(this.plan);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: EdgeInsets.only(left: 10.0, right: 10.0),
|
|
height: (90 + (plan.tip == null ? 0 : 13)).h,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
|
|
},
|
|
child: Stack(
|
|
alignment: Alignment.topCenter,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.only(top: plan.tip == null ? 0 : 13.h),
|
|
child: Container(
|
|
height: 80.h,
|
|
decoration: BoxDecoration(
|
|
color: Theme.of(context).scaffoldBackgroundColor,
|
|
border: Border.all(color: borderGray),
|
|
borderRadius: BorderRadius.circular(12.0),
|
|
),
|
|
padding: EdgeInsets.only(
|
|
left: 10.0.w,
|
|
right: 20.w,
|
|
top: 10.h,
|
|
bottom: 10.h,
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(child: _lead(plan)),
|
|
SizedBox(
|
|
width: 85.w,
|
|
child: _trail(plan),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
if (plan.tip != null)
|
|
Container(
|
|
height: 26.h,
|
|
width: 110.w,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: plan.tipColor?.asColor ?? progressBlue,
|
|
border: Border.all(color: borderGray),
|
|
borderRadius: BorderRadius.circular(16.0),
|
|
),
|
|
padding: EdgeInsets.all(2.0.w),
|
|
child: Text(
|
|
plan.tip!,
|
|
style: TextStyle(color: white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _lead(SubscriptionPlanDto plan) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text.rich(
|
|
TextSpan(
|
|
children: [
|
|
if (plan.titleLead != null)
|
|
TextSpan(
|
|
text: plan.titleLead,
|
|
style: TextStyle(fontSize: 32),
|
|
),
|
|
if (plan.title != null)
|
|
TextSpan(
|
|
text: ' ${plan.title}',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
],
|
|
style: TextStyle(
|
|
height: 0.85,
|
|
)),
|
|
),
|
|
Text.rich(
|
|
TextSpan(
|
|
children: [
|
|
if (plan.subtitleCrossed != null)
|
|
TextSpan(
|
|
text: plan.subtitleCrossed,
|
|
style: TextStyle(
|
|
fontSize: 20,
|
|
color: borderGray,
|
|
decoration: TextDecoration.lineThrough,
|
|
height: 0.85,
|
|
),
|
|
),
|
|
if (plan.subtitleCrossed != null && plan.subtitle != null)
|
|
TextSpan(text: ' '),
|
|
if (plan.subtitle != null)
|
|
TextSpan(
|
|
text: plan.subtitle,
|
|
style: TextStyle(
|
|
fontSize: 20.h,
|
|
height: 0.85,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _trail(SubscriptionPlanDto plan) {
|
|
if (plan.pricePerMonth != null)
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Text.rich(
|
|
TextSpan(children: [
|
|
TextSpan(
|
|
text: plan.pricePerMonth!,
|
|
style: TextStyle(fontSize: 24),
|
|
),
|
|
TextSpan(
|
|
text: ' ${plan.currency}',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
], style: TextStyle(height: 0.85)),
|
|
),
|
|
Text(
|
|
'в месяц',
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
return SizedBox.shrink();
|
|
}
|
|
}
|