flutter_1flow_sdk 2024.3.1 copy "flutter_1flow_sdk: ^2024.3.1" to clipboard
flutter_1flow_sdk: ^2024.3.1 copied to clipboard

1Flow flutter SDK.

example/lib/main.dart

import 'dart:developer';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_1flow_sdk/flutter_1flow_sdk.dart';

void main() {
  runApp(MyApp());
  String projectKey = "oneflow_prod_yxwI14oGAEhYgOEJjo43IsoKuWbSPoXBcKD+Bj5UkiZtPXb1vuuBkRUm5YxfBCs6thcsxPWbxDeJHJZlSGzxkw==";
 OneFlow.configure(projectKey);
  OneFlow.logUser('fluttersdk_2023.3.1', {'tested_by': 'Amit Sanvedi'});
  //OneFlow.getSDKVersion().then((version) {
    //print("version:" + version);
 // });

//  OneFlow.logUser('fluttersdk_2023.6.20',{ 'tested_by': 'Amit Sanvedi' });
  // OneFlow.useFont(fontFamily: "Courier New"); //For iOS Only
  //OneFlow.useFont(path: "fonts/pacifico.ttf"); // For Android Only
  //OneFlow.useFont(fontFamily: "Courier New", path: "fonts/pacifico.ttf"); // For iOS & Android Both
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();

    OneFlow.methodchannel
        .setMethodCallHandler(oneFlowSurveyFinishNotificationHandler);

    initPlatformState();
  }

  Future<void> oneFlowSurveyFinishNotificationHandler(MethodCall call) async {
    final String method = call.method;
    dynamic argument = call.arguments;
    print("oneFlowSurveyFinishNotificationHandler");
    switch (method) {
      case "oneFlowSurveyFinishNotification":
        {
          print("oneFlowSurveyFinishNotification: $argument");
        }
        break;
      default:
        {
          print("Invalid choice");
        }
        break;
    }
  }

  void recordEventWithParameter() {
    try {
      OneFlow.recordEventName('session_start', {'event_triggered_by': 'Amit Sanvedi'});
      print('recordEventName: Done');
    } on PlatformException {
      print('recordEventName: error occured');
    }
  }

  void recordEventWithoutParameter() {
    try {
      OneFlow.recordEventName("session_start");
      print('recordEventName: Done');
    } on PlatformException {
      print('recordEventName: error occured');
    }
  }

  void startFlow() {
    try {
      OneFlow.startFlow('298222a3ffc2e177690c1e30');
      print('startFlow: Done');
    } on PlatformException {
      print('startFlow: error occured');
    }
  }

  void showInbox() {
    try {
      OneFlow.showInbox();
      print('startFlow: Done');
    } on PlatformException {
      print('startFlow: error occured');
    }
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    if (!mounted) return;

    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Tittle',
        home: Scaffold(
          body: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                new TextButton(
                    onPressed: () {
                      recordEventWithParameter();
                    },
                    child: Text("Record Event With Parameter")),
                SizedBox(width: 100),
                new TextButton(
                    onPressed: () {
                      recordEventWithoutParameter();
                    },
                    child: Text("Record Event Without Parameter")),
                SizedBox(width: 100),
                new TextButton(
                    onPressed: () {
                      startFlow();
                    },
                    child: Text("Start Flow")),
                SizedBox(width: 100),
                new TextButton(
                    onPressed: () {
                      showInbox();
                    },
                    child: Text("Show Inbox"))
              ]),
        ));
  }
}