idwise 0.0.6
idwise: ^0.0.6 copied to clipboard
Flutter Plugin for IDWise SDK
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:idwise/idwise_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class JourneyCallbacks extends IDWiseSDKJourneyCallbacks {
@override
void onJourneyStarted(journeyId) {
//this callback triggers when Journey is started
print("onJourneyStarted $journeyId");
}
@override
void onJourneyCompleted() {
//This callback triggers when Journey is completed
print("onJourneyCompleted");
}
@override
void onJourneyResumed(journeyId) {
//This callback triggers when Journey is resumed in Dynamic Journey Mode
print("onJourneyResumed $journeyId");
}
@override
void onJourneyCancelled() {
//This callback triggers when journey is cancelled by the user
print("onJourneyCancelled");
}
@override
void onError(error) {
//this callback triggers when an error is occured during the Journey
print("onError $error");
}
}
class _MyAppState extends State<MyApp> {
String clientKey =
"QmFzaWMgWkRJME1qVm1ZelV0WlRZeU1TMDBZV0kxTFdGak5EVXRObVZqT1RGaU9XSXpZakl6T21oUFlubE9VRXRpVVRkMWVubHBjbGhUYld4aU1GcDNOMWcyTkVwWWNrTXlOa1Z4U21oWlNsaz0=";
String journeyDefinitionId = "d2425fc5-e621-4ab5-ac45-6ec91b9b3b23";
String referenceNo = "";
String locale = "en";
@override
void initState() {
super.initState();
IDWise.initialize(clientKey, IDWiseSDKTheme.DARK, onError: (error) {
print("onError in _idwiseFlutterPlugin: $error");
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> _initializeAndStartJourney() async {
try {
IDWise.startJourney(
journeyDefinitionId, referenceNo, locale, JourneyCallbacks());
} on PlatformException {
//platformVersion = 'Failed to get platform version.';
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('IDWise Plugin Sample'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: const Text('Start Journey'),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xff4B5EB9),
textStyle: const TextStyle(color: Colors.white)),
onPressed: _initializeAndStartJourney,
)
],
)),
),
);
}
}