Add myket in app purchase
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

88 lignes
2.4 KiB

  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:flutter/services.dart';
  4. import 'package:myketpayment/myketpayment.dart';
  5. void main() {
  6. runApp(MyApp());
  7. }
  8. class MyApp extends StatefulWidget {
  9. @override
  10. _MyAppState createState() => _MyAppState();
  11. }
  12. class _MyAppState extends State<MyApp> {
  13. String _platformVersion = 'Unknown';
  14. @override
  15. void initState() {
  16. super.initState();
  17. }
  18. final String rsa = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCPBy3LGWCeF5AwPIVdS6DvkTHkS9qa45vNhpZiJTjELjG1VLa9a8nAsm4E6qqKoQ6wh5Cuq3T9NqdtkTwWtLgVYvTl6JQlkN/2XfabkWcn58f14mvrkVv8qHUFr0m/kqz9sp/fk1KvS16BjVy/M3ScuvLr0ONJ+HS5PQvHUTdDLQIDAQAB";
  19. bool setup = false;
  20. @override
  21. Widget build(BuildContext context) {
  22. return MaterialApp(
  23. home: Scaffold(
  24. appBar: AppBar(
  25. title: const Text('Plugin example app'),
  26. ),
  27. body: Center(
  28. child: Column(
  29. children: [
  30. Text('myket for appeto'),
  31. SizedBox(height: 20,),
  32. FlatButton(
  33. child: Text("buy and consume"),
  34. onPressed: () async {
  35. if(!setup) {
  36. setup = await Myketpayment.setup(rsa);
  37. }
  38. print("setup: $setup");
  39. if(setup) {
  40. final result = await Myketpayment.buy(sku: 'myflutter', consume: true);
  41. afterPurchase(result);
  42. }
  43. else {
  44. print("can not connect to myket");
  45. }
  46. },
  47. ),
  48. SizedBox(height: 20,),
  49. FlatButton(
  50. child: Text("buy unlimit"),
  51. onPressed: () async {
  52. if(!setup) {
  53. setup = await Myketpayment.setup(rsa);
  54. }
  55. print("setup: $setup");
  56. if(setup) {
  57. final result = await Myketpayment.buy(sku: 'flunlimit');
  58. afterPurchase(result);
  59. }
  60. else {
  61. print("can not connect to myket");
  62. }
  63. },
  64. ),
  65. ],
  66. ),
  67. ),
  68. ),
  69. );
  70. }
  71. void afterPurchase(Map result) {
  72. if(result.containsKey('purchased') && result['purchased'] == true) {
  73. print("purchase info: $result");
  74. }
  75. else {
  76. print("no purchase: $result");
  77. }
  78. }
  79. }