onepref 0.0.7 copy "onepref: ^0.0.7" to clipboard
onepref: ^0.0.7 copied to clipboard

A simplified version of SharedPreferences and other pre-defined functions.

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() {

  OnePref.init();   // call this, to initialize the class
  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,
       ),
     ),
  ),
20
likes
0
pub points
88%
popularity

Publisher

verified publisherdingi.icu

A simplified version of SharedPreferences and other pre-defined functions.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, in_app_purchase, in_app_purchase_android, shared_preferences

More

Packages that depend on onepref