knotapi_flutter 1.0.1
knotapi_flutter: ^1.0.1 copied to clipboard
Change card on file information, retrieve transactions, and more via Knot.
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:knotapi_flutter/events.dart';
import 'package:knotapi_flutter/knotapi_configuration.dart';
import 'package:knotapi_flutter/knotapi_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _knotapiFlutterPlugin = KnotapiFlutter();
StreamSubscription<KnotEvent>? _streamEvent;
StreamSubscription<KnotSuccess>? _streamSuccess;
StreamSubscription<KnotError>? _streamError;
StreamSubscription<KnotExit>? _streamExit;
void _onSuccess (KnotSuccess event) {
Product type = event.product;
String merchant = event.merchant;
print("eventName: _onSuccess, type: $type, merchant: $merchant");
}
void _onError (KnotError event) {
String type = event.product;
String message = event.message;
print("eventName: _onError, type: $type, message: $message");
}
void _onEvent (KnotEvent event) {
Product type = event.product;
String name = event.event;
String? taskId = event.taskId;
Map<String, Object?> metaData = event.metaData;
print("eventName: _onEvent, type: $type, event: $name, taskId: $taskId, metaData: $metaData");
}
void _onExit (KnotExit event) {
String type = event.type;
print("eventName: _onExit, type: $type");
}
@override
void initState() {
super.initState();
_streamError = KnotapiFlutter.onError.listen(_onError);
_streamEvent = KnotapiFlutter.onEvent.listen(_onEvent);
_streamExit = KnotapiFlutter.onExit.listen(_onExit);
_streamSuccess = KnotapiFlutter.onSuccess.listen(_onSuccess);
}
@override
void dispose(){
super.dispose();
_streamSuccess?.cancel();
_streamExit?.cancel();
_streamEvent?.cancel();
_streamError?.cancel();
}
void onOpenCardOnFileSwitcher() {
_knotapiFlutterPlugin.open(KnotConfiguration(
sessionId: "0e737510-6421-4334-a517-875fa0365b50",
clientId: "7b751423-b438-4cc3-ba0f-f23e4d33f844",
environment: Environment.development,
product: Product.cardSwitcher,
useCategories: false));
}
void onOpenTransactionLink() {
_knotapiFlutterPlugin.open(KnotConfiguration(
sessionId: "695ce724-7f61-40f1-a410-cb0c0fcf9b7f",
clientId: "3f4acb6b-a8c9-47bc-820c-b0eaf24ee771",
environment: Environment.development,
product: Product.transactionLink,
merchantIds: [17],
useCategories: false));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.black,
appBarTheme: const AppBarTheme(color: Colors.black),
buttonTheme: const ButtonThemeData(buttonColor: Colors.black),
colorScheme: const ColorScheme(
background: Colors.white,
brightness: Brightness.light,
primary: Colors.black,
onPrimary: Colors.white,
secondary: Colors.white,
onSecondary: Colors.white,
error: Colors.redAccent,
onError: Colors.redAccent,
onBackground: Colors.black,
surface: Colors.white,
onSurface: Colors.black)),
home: Scaffold(
appBar: AppBar(
title: const Text('KnotAPI Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: onOpenCardOnFileSwitcher,
child: const Text('Open Card On File Switcher'),
),
ElevatedButton(
onPressed: onOpenTransactionLink,
child: const Text('Open Transaction Link')),
],
),
),
),
);
}
}