Advertisement
Guest User

IAP

a guest
Sep 18th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.76 KB | None | 0 0
  1.   Future<void> initPlatformState() async {
  2.     var result = await FlutterInappPurchase.initConnection;
  3.     print('result: $result');
  4.  
  5.     // If the widget was removed from the tree while the asynchronous platform
  6.     // message was in flight, we want to discard the reply rather than calling
  7.     // setState to update our non-existent appearance.
  8.     if (!mounted) return;
  9.  
  10.     // refresh items for android
  11.     String msg = await FlutterInappPurchase.consumeAllItems;
  12.     print('consumeAllItems: $msg');
  13.     await _getProduct();
  14.   }
  15.  
  16.   Future<Null> _getProduct() async {
  17.     List<IAPItem> items = await FlutterInappPurchase.getProducts([Constants.removeAdsProductId]);
  18.     for (var item in items) {
  19.       print('${item.toString()}');
  20.       this._items.add(item);
  21.     }
  22.  
  23.     setState(() {
  24.       this._items = items;
  25.     });
  26.   }
  27.  
  28.   List<Widget> _renderButton() {
  29.     List<Widget> widgets = this._items.map((item) =>
  30.       Column(
  31.         children: <Widget>[
  32.           Container(
  33.             height: 250.0,
  34.             width: double.infinity,
  35.             child: Card(
  36.               child: Column(
  37.                 children: <Widget>[
  38.                   SizedBox(height: 28.0),
  39.                   Align(
  40.                     alignment: Alignment.center,
  41.                     child: Text(language.removeAdTitle, style: Theme
  42.                       .of(context)
  43.                       .textTheme
  44.                       .display1,),
  45.                   ),
  46.                   SizedBox(height: 24.0),
  47.                   Align(
  48.                     alignment: Alignment.center,
  49.                     child: Text(language.removeAdFirstText, style: TextStyle(fontSize: 16.0, color: Colors.grey[700]),),
  50.                   ),
  51.                   Align(
  52.                     alignment: Alignment.center,
  53.                     child: Text(language.removeAdSecondText, style: TextStyle(fontSize: 16.0, color: Colors.grey[700])),
  54.                   ),
  55.                   SizedBox(height: 24.0),
  56.                   SizedBox(
  57.                     width: 340.0,
  58.                     height: 50.0,
  59.                     child: RaisedButton(
  60.                       onPressed: () => _buyProduct(item),
  61.                       shape: new RoundedRectangleBorder(
  62.                         borderRadius: new BorderRadius.circular(30.0)),
  63.                       child: Text('${language.buy} ${item.price} ${item.currency}', style: Theme.of(context).primaryTextTheme.button,),
  64.                     ),
  65.                   ),
  66.                 ],
  67.               ),
  68.             ),
  69.           ),
  70.         ],
  71.       )
  72.     ).toList();
  73.     return widgets;
  74.   }
  75.  
  76.   @override
  77.   Widget build(BuildContext context) {
  78.     language = AppLocalizations.of(context);
  79.  
  80.     return Column(
  81.       children: this._renderButton(),
  82.     );
  83.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement