Question

This StoreProduct represents an SK1 product

  • 21 August 2023
  • 1 reply
  • 200 views

Badge

i have a flutter app that about daily horoscope and tarot cards and i’m trying to implement it but i’m kinda lost in the documents and tutorials i have purchase function page like this in code

 

import 'package:flutter/services.dart';
import 'package:purchases_flutter/models/offering_wrapper.dart';
import 'package:purchases_flutter/purchases_flutter.dart';

class PurchaseFlutterAPI {
// initialize function to be called to initialize our purchase_Flutter plugin
static Future init() async {
await Purchases.setLogLevel(LogLevel.debug);
}

// gets a list of offerings from RevenueCat and stores it in a list for use in our app
static Future<List<Offering>> fetchOffers() async {
try {
final offerings = await Purchases.getOfferings();
final activeOffering = offerings.current;

return (activeOffering == null) ? [] : [activeOffering];
} on PlatformException catch (e) {
return [];
}
}
}

and a subscripiton page in this

import 'package:flutter/material.dart';
import 'package:horoscope101/subs.dart';

class SubsPage extends StatefulWidget {
const SubsPage({super.key});

@override
State<SubsPage> createState() => _SubsPageState();
}

class _SubsPageState extends State<SubsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildAppBar(),
body: Column(
children: [
ElevatedButton(
onPressed: () {
PurchaseFlutterAPI.fetchOffers();
},
child: Center(
child: Text("Get Offers"),
))
],
),
);
}
}

AppBar _buildAppBar() {
return AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: BackButton(
color: Color(0xFF9932CC),
),
title: Text(
"Your Future Is At Your Hands",
style: TextStyle(fontSize: 18, color: Color(0xFF9932CC)),
),
centerTitle: true,
);
}

and in main.dart i have api

final _configruation =
PurchasesConfiguration("ios_api_key")
..observerMode = false;

Future main() async {
WidgetsFlutterBinding.ensureInitialized();

await Purchases.configure(_configruation);
runApp(const MyApp());
}

what am i doing wrong ? thanks for all your help


1 reply

Userlevel 4
Badge +8

Hi, when you attempt to make a purchase are you getting an error? You can enable our SDK’s debug logs here: https://www.revenuecat.com/docs/debugging#section-debugging

Reply