main.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_mercadopago/flutter_mercadopago.dart';
  5. void main() => runApp(new MyApp());
  6. class MyApp extends StatefulWidget {
  7. @override
  8. _MyAppState createState() => new _MyAppState();
  9. }
  10. class _MyAppState extends State<MyApp> {
  11. String _platformVersion = 'Unknown';
  12. FlutterMercadopago mp;
  13. static const String mpPublicKey = "TEST-c1826083-a656-4126-8b52-746e37a6e6f8";
  14. static const String mpPreferenceId = "251601260-c06cdffc-4b3a-4496-a182-d561c81380d6";
  15. // static const String mpPublicKey = "APP_USR-4a4313ac-bede-4a66-b43d-25b9ec036783";
  16. @override
  17. void initState() {
  18. super.initState();
  19. initPlatformState();
  20. mp = new FlutterMercadopago(
  21. publicKey: mpPublicKey,
  22. preferenceId: mpPreferenceId,
  23. );
  24. }
  25. // Platform messages are asynchronous, so we initialize in an async method.
  26. Future<void> initPlatformState() async {
  27. String platformVersion;
  28. // Platform messages may fail, so we use a try/catch PlatformException.
  29. try {
  30. platformVersion = await FlutterMercadopago.platformVersion;
  31. } on PlatformException {
  32. platformVersion = 'Failed to get platform version.';
  33. }
  34. // If the widget was removed from the tree while the asynchronous platform
  35. // message was in flight, we want to discard the reply rather than calling
  36. // setState to update our non-existent appearance.
  37. if (!mounted) return;
  38. setState(() {
  39. _platformVersion = platformVersion;
  40. });
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. return new MaterialApp(
  45. home: new Scaffold(
  46. appBar: new AppBar(
  47. title: const Text('Plugin example app'),
  48. ),
  49. body: new Center(
  50. child: new Text('Running on: $_platformVersion\n'),
  51. ),
  52. floatingActionButton: FloatingActionButton(
  53. child: Icon(Icons.add),
  54. onPressed: () async {
  55. var result = await mp.startForPayment();
  56. print("Result: $result");
  57. },
  58. ),
  59. ),
  60. );
  61. }
  62. }