lot of work on rfplus

This commit is contained in:
Kima
2024-02-28 22:37:21 +01:00
parent 55a9a41722
commit 25464eff79
8 changed files with 214 additions and 30 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter_stripe/flutter_stripe.dart' as stripe;
import 'package:refilc/api/client.dart';
import 'package:refilc/theme/colors/colors.dart';
import 'package:refilc_plus/providers/premium_provider.dart';
import 'package:refilc_plus/ui/mobile/premium/activation_view/activation_view.dart';
@@ -6,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_feather_icons/flutter_feather_icons.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
class GithubLoginButton extends StatelessWidget {
const GithubLoginButton({super.key});
@@ -40,10 +42,21 @@ class GithubLoginButton extends StatelessWidget {
// Navigator.of(context).push(MaterialPageRoute(builder: (context) {
// return const PremiumActivationView();
// }));
bool initFinished = await initPaymentSheet(context);
if (initFinished) {
await stripe.Stripe.instance.presentPaymentSheet();
}
// bool initFinished = await initPaymentSheet(context);
// if (initFinished) {
// stripe.PaymentSheetPaymentOption? result =
// await stripe.Stripe.instance.presentPaymentSheet();
// print(result == null);
// print(result?.label ?? 'nem label');
// }
launchUrl(
Uri.parse(
'https://api.refilc.hu/v3/payment/stripe-create-checkout?product=asdasd'),
mode: LaunchMode.inAppBrowserView,
);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
@@ -121,6 +134,10 @@ class GithubLoginButton extends StatelessWidget {
// 1. create payment intent on the server
final data = await _createPaymentSheet();
if (data == null) {
throw "API error, can't create payment sheet!";
}
// 2. initialize the payment sheet
await stripe.Stripe.instance.initPaymentSheet(
paymentSheetParameters: stripe.SetupPaymentSheetParameters(
@@ -133,9 +150,9 @@ class GithubLoginButton extends StatelessWidget {
customerEphemeralKeySecret: data['ephemeralKey'],
customerId: data['customer'],
// Extra options
applePay: const stripe.PaymentSheetApplePay(
merchantCountryCode: 'HU',
),
// applePay: const stripe.PaymentSheetApplePay(
// merchantCountryCode: 'HU',
// ),
googlePay: const stripe.PaymentSheetGooglePay(
merchantCountryCode: 'HU',
testEnv: true,
@@ -145,6 +162,7 @@ class GithubLoginButton extends StatelessWidget {
);
return true;
} catch (e) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: $e')),
);
@@ -152,9 +170,8 @@ class GithubLoginButton extends StatelessWidget {
}
}
Future<Map<String, String>> _createPaymentSheet() async {
Map<String, String> asdasd = {};
return asdasd;
Future<Map?> _createPaymentSheet() async {
Map? data = await FilcAPI.createPaymentSheet("refilcplus");
return data;
}
}

View File

@@ -100,6 +100,8 @@ extension SettingsLocalization on String {
"fonts": "Fonts",
"font_family": "Font Family",
"calendar_sync": "Calendar Sync",
"choose_account": "Choose Account",
"your_account": "Your Account",
},
"hu_hu": {
"personal_details": "Személyes információk",
@@ -198,6 +200,8 @@ extension SettingsLocalization on String {
"fonts": "Betűk",
"font_family": "Betűtípus",
"calendar_sync": "Naptár szinkronizálás",
"choose_account": "Válassz fiókot",
"your_account": "Fiókod",
},
"de_de": {
"personal_details": "Persönliche Angaben",
@@ -295,7 +299,9 @@ extension SettingsLocalization on String {
"show_breaks": "Pausen anzeigen",
"fonts": "Schriftarten",
"font_family": "Schriftfamilie",
"calendar_sync": "heil hitler",
"calendar_sync": "Kalender-Synchronisation",
"choose_account": "Konto auswählen",
"your_account": "Ihr Konto",
},
};

View File

@@ -70,6 +70,7 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
late SettingsProvider settingsProvider;
late UserProvider user;
late ShareProvider shareProvider;
late ThirdPartyProvider thirdPartyProvider;
late AnimationController _hideContainersController;
@@ -87,6 +88,7 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
Widget build(BuildContext context) {
settingsProvider = Provider.of<SettingsProvider>(context);
user = Provider.of<UserProvider>(context);
thirdPartyProvider = Provider.of<ThirdPartyProvider>(context);
return AnimatedBuilder(
animation: _hideContainersController,
@@ -164,9 +166,7 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
height: 18.0,
),
// choose account if not logged in
if (Provider.of<ThirdPartyProvider>(context)
.linkedAccounts
.isEmpty)
if (thirdPartyProvider.linkedAccounts.isEmpty)
Column(
children: [
SplittedPanel(
@@ -180,6 +180,8 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
await Provider.of<ThirdPartyProvider>(context,
listen: false)
.googleSignIn();
setState(() {});
},
title: Text(
'Google',
@@ -241,16 +243,121 @@ class CalendarSyncScreenState extends State<CalendarSyncScreen>
],
),
const SizedBox(
height: 18.0,
),
// own paints
SplittedPanel(
title: Text('public_paint'.i18n),
padding: EdgeInsets.zero,
cardPadding: const EdgeInsets.all(4.0),
children: [],
),
// show options if logged in
if (thirdPartyProvider.linkedAccounts.isNotEmpty)
Column(
children: [
SplittedPanel(
title: Text('your_account'.i18n),
padding: EdgeInsets.zero,
cardPadding: const EdgeInsets.all(4.0),
children: [
PanelButton(
onPressed: null,
title: Text(
thirdPartyProvider
.linkedAccounts.first.username,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
leading: Image.asset(
'assets/images/ext_logo/${thirdPartyProvider.linkedAccounts.first.type == AccountType.google ? "google" : "apple"}.png',
width: 24.0,
height: 24.0,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
PanelButton(
onPressed: () async {
await thirdPartyProvider.signOutAll();
setState(() {});
},
title: Text(
'change_account'.i18n,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
trailing: Icon(
FeatherIcons.chevronRight,
size: 22.0,
color: AppColors.of(context)
.text
.withOpacity(0.95),
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
],
),
const SizedBox(
height: 18.0,
),
SplittedPanel(
title: Text('choose_calendar'.i18n),
padding: EdgeInsets.zero,
cardPadding: const EdgeInsets.all(4.0),
children: [
PanelButton(
onPressed: null,
title: Text(
thirdPartyProvider
.linkedAccounts.first.username,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
leading: Image.asset(
'assets/images/ext_logo/${thirdPartyProvider.linkedAccounts.first.type == AccountType.google ? "google" : "apple"}.png',
width: 24.0,
height: 24.0,
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
PanelButton(
onPressed: () async {
await thirdPartyProvider.signOutAll();
setState(() {});
},
title: Text(
'change_account'.i18n,
style: TextStyle(
color: AppColors.of(context)
.text
.withOpacity(.95),
),
),
trailing: Icon(
FeatherIcons.chevronRight,
size: 22.0,
color: AppColors.of(context)
.text
.withOpacity(0.95),
),
borderRadius: const BorderRadius.vertical(
top: Radius.circular(12),
bottom: Radius.circular(12),
),
),
],
),
],
),
],
),
),