deuna_checkout_widget
The README is available in spanish here
Once an order token is received with your DEUNA API Keys, install the plugin:
Add the dependency into pubspec.yaml
:
dependencies:
deuna_checkout_widget: ^last_version
Watch the last version in pub.dev.
Android
Configure the minSdkVersion
with the right value in android/app/build.gradle
:
android {
defaultConfig {
minSdkVersion 20
}
}
iOS
Nothing to do. It is ready to be used.
Usage
Import the deuna_checkout_widget
plugin:
import 'package:deuna_checkout_widget/deuna_checkout_widget.dart';
In the root of the application, add the configuration for the plugin:
DeUnaCheckoutConfiguration(
data: const DeUnaCheckoutData(
env: DeUnaCheckoutEnv.stg, // default value: DeUnaCheckoutEnv.prod
apiKey: 'YOUR_API_KEY',
analyticsConfig: AnalyticsConfig( // analyticsConfig is optional
amplitudeKeyId: 'AMPLITUDE_KEY_ID', // Obligatorio
googleTagManagerKeyId: 'GOOGLE_TAG_MANAGER_KEY_ID', // optional
sessionId: 'SESSION_ID', // optional
),
),
child: MaterialApp(
child: ...
),
);
After getting the order token (orderToken
), build the DeUnaCheckout
widget:
DeUnaCheckout(
orderToken: orderToken,
),
Example
The following example suppose that the orderToken
is already generated:
import 'package:deuna_checkout_widget/deuna_checkout_widget.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return DeUnaCheckoutConfiguration(
// Set `data` with your configuration data.
data: const DeUnaCheckoutData(
env: DeUnaCheckoutEnv.stg, // default value is prod
apiKey: 'YOUR_API_KEY',
),
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'DEUNA Checkout Demo'),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void openCheckout() {
Navigator.push<void>(
context,
MaterialPageRoute(
builder: (context) => const CheckoutExample(
orderToken: 'YOUR_ORDER_TOKEN',
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[
Text(
'Press the action button to open the checkout',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: openCheckout,
tooltip: 'Open Checkout',
child: const Icon(Icons.add),
),
);
}
}
class CheckoutExample extends StatelessWidget {
const CheckoutExample({
Key? key,
required this.orderToken,
}) : super(key: key);
final String orderToken;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('DEUNA Checkout Widget'),
),
body: Center(
child: DeUnaCheckout(
orderToken: orderToken,
),
),
);
}
}