Giter Site home page Giter Site logo

alirezat66 / onepref Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wdtheprovider/onepref

0.0 0.0 0.0 325 KB

a package for payment

License: BSD 3-Clause "New" or "Revised" License

Ruby 3.55% C++ 27.63% C 1.88% Objective-C 0.05% Kotlin 0.18% Dart 37.73% Swift 1.87% HTML 2.40% CMake 24.70%

onepref's Introduction

This package is endorsed, which means you can simply use shared_preferences and in_app_purchase normally. This package will be automatically included in your app when you do, so you do not need to add it to your pubspec.yaml.

Features

OnePref offers the same functionality shared_preferences package offers but in a friendly way and it has other in app purchase functions to fast track your development when you add in app purchase in your application.

Getting started

flutter pub add onepref
import 'package:onepref/onepref.dart' 
//In your main.dart
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await OnePref.init();
  runApp(const MyApp());
}

Usage

To Write

OnePref.setString("key","value here");
Get the Value

const value = OnePref.getString("key");

To get Products

//declare these 

late final List<String> _notFoundIds = <String>[];
late final List<ProductDetails> _products = <ProductDetails>[];
late final List<PurchaseDetails> _purchases = <PurchaseDetails>[];
late bool _isAvailable = false;
late bool _purchasePending = false;

IApEngine iApEngine = IApEngine();

ATTENTATION !!!!!  ATTENTATION !!!!!   ATTENTATION !!!!!
//(Please make sure you have configured in App purchase for your app)

@override
void initState() {
  super.initState();
  
  iApEngine.inAppPurchase.purchaseStream.listen(
          (List<PurchaseDetails> purchaseDetailsList) {
        //listen to the purchases
        listenToPurchaseUpdated(purchaseDetailsList);
      }, onDone: () {}, onError: (Object error) {});
  
  getProducts();// calling get products
}

void getProducts() async {
    // Querying the products from Google Play
    await iApEngine.getIsAvailable().then((isAvailable) async {
      if (isAvailable) {
        await iApEngine
            .queryProducts(Constants.storeProductIds)
            .then((value) => {
                  setState(() {
                    _isAvailable = isAvailable;
                    _products.addAll(value
                        .productDetails); // Setting the returned products here.
                    _notFoundIds.addAll(value
                        .notFoundIDs); // Setting the returned notProductIds here.
                    _purchasePending = false;
                  })
                });
      }
    });
  }
  

HandlePurchase

 TextButton(onPressed: () {
     iApEngine.handlePurchase(_products[selectedProduct ?? 0],Constants.storeProductIds);},
   child: Text("Buy $reward",
                textAlign: TextAlign.center,
            style: const TextStyle(
           color: Colors.white, fontSize: 14,
          fontWeight: FontWeight.normal,
       ),
     ),
  ),

onepref's People

Contributors

wdtheprovider avatar alirezat66 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.