knotapi_flutter 0.1.4
knotapi_flutter: ^0.1.4 copied to clipboard
Change Card on File Information, Cancel Subscriptions, Change Passwords, 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<KnotFinished>? _streamFinished;
StreamSubscription<KnotExit>? _streamExit;
void _onSuccess (KnotSuccess event) {
String eventName = event.eventName;
String type = event.type;
String merchant = event.merchant;
print("eventName: $eventName, type: $type, merchant: $merchant");
}
void _onError (KnotError event) {
String eventName = event.eventName;
String type = event.type;
String message = event.message;
print("eventName: $eventName, type: $type, message: $message");
}
void _onEvent (KnotEvent event) {
String eventName = event.eventName;
String type = event.type;
String name = event.event;
print("eventName: $eventName, type: $type, event: $name");
}
void _onFinished (KnotFinished event) {
String eventName = event.eventName;
String type = event.type;
print("eventName: $eventName, type: $type");
}
void _onExit (KnotExit event) {
String eventName = event.eventName;
String type = event.type;
print("eventName: $eventName, type: $type");
}
@override
void initState() {
super.initState();
_streamError = KnotapiFlutter.onError.listen(_onError);
_streamEvent = KnotapiFlutter.onEvent.listen(_onEvent);
_streamExit = KnotapiFlutter.onExit.listen(_onExit);
_streamFinished = KnotapiFlutter.onFinished.listen(_onFinished);
_streamSuccess = KnotapiFlutter.onSuccess.listen(_onSuccess);
}
@override
void dispose(){
super.dispose();
_streamSuccess?.cancel();
_streamFinished?.cancel();
_streamExit?.cancel();
_streamEvent?.cancel();
_streamError?.cancel();
}
void onOpenCardOnFileSwitcher() {
_knotapiFlutterPlugin.openCardOnFileSwitcher(KnotConfiguration(
sessionId: "5484d1d3-6740-494f-af07-33d520afb0f1",
clientId: "3f4acb6b-a8c9-47bc-820c-b0eaf24ee771",
environment: "sandbox",
buttonCorners: 40,
buttonFontSize: 20,
buttonPaddings: 20,
useSelection: false,
useCategories: false,
primaryColor: "#21C577",
));
}
void onOpenSubscriptionCanceler() {
_knotapiFlutterPlugin.openSubscriptionCanceler(KnotConfiguration(
sessionId: "6518bb09-d8c5-4981-baf2-d02bd5800256",
clientId: "ab86955e-22f4-49c3-97d7-369973f4cb9e",
environment: "development",
buttonCorners: 80,
buttonFontSize: 20,
buttonPaddings: 20,
useSelection: false,
useCategories: false,
primaryColor: "#21C577",
));
}
@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: onOpenSubscriptionCanceler,
child: const Text('Open Subscription Canceler')),
],
),
),
),
);
}
}