idwise_flutter_sdk 0.0.17 copy "idwise_flutter_sdk: ^0.0.17" to clipboard
idwise_flutter_sdk: ^0.0.17 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_flutter_sdk/idwise_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> {
  String clientKey =
      "QmFzaWMgWkRJME1qVm1ZelV0WlRZeU1TMDBZV0kxTFdGak5EVXRObVZqT1RGaU9XSXpZakl6T21oUFlubE9VRXRpVVRkMWVubHBjbGhUYld4aU1GcDNOMWcyTkVwWWNrTXlOa1Z4U21oWlNsaz0=";

  String journeyDefinitionId =
      "d2425fc5-e621-4ab5-ac45-6ec91b9b3b23"; //provided by IDWise
  String referenceNo = "";
  String locale = "en";

  final journeyCallbacks = IDWiseSDKJourneyCallbacks(
      onJourneyStarted: (String journeyId) =>
          print("onJourneyStarted: $journeyId"),
      onJourneyCompleted: () => print("onJourneyCompleted"),
      onJourneyResumed: (String journeyId) => print("onJourneyResumed"),
      onJourneyCancelled: () => print("onJourneyCancelled"),
      onError: (dynamic error) => print("onError $error"));

  @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,
            )
          ],
        )),
      ),
    );
  }
}