---
title: Flutter
description: Platform Channels का उपयोग करके अपने Flutter ऐप में Human Token Journey को एकीकृत करें — Android पर Custom Tabs और iOS पर ASWebAuthenticationSession।
canonical: https://developer.unico.io/hi/human-token/integrations/app/flutter
locale: hi
generated_by: markdown-export
---

- [/hi/](/hi/)
- [इंटीग्रेशन](/hi/human-token/integrations)
- ऐप
- Flutter

**इस पेज परFlutterPlatform Channels का उपयोग करके अपने Flutter ऐप में Human Token Journey को एकीकृत करें।

एकीकरण iOS पर `ASWebAuthenticationSession` और Android पर Custom Tabs को डेलीगेट करने के लिए `MethodChannel` का उपयोग करता है। किसी बाहरी पैकेज की आवश्यकता नहीं है।
### पूर्वापेक्षाएँ​

Flutter 3.x या बाद का
iOS के लिए Xcode 14+
Android के लिए Android Studio
आपके ऐप के लिए एक अद्वितीय URL स्कीम (जैसे `myapp`)

### चरण 1: अपना URL स्कीम परिभाषित करें​

एक अद्वितीय स्कीम चुनें (जैसे `myapp`)। प्रोसेस बनाते समय इसे `callbackUri` के रूप में उपयोग किया जाता है:
```
callbackUri: myapp://callback
```

### चरण 2: Dart सर्विस बनाएँ​

```
// lib/services/unico_service.dartimport 'package:flutter/services.dart';class UnicoService {  static const _channel = MethodChannel('unico_plugin');  Future<String?> openSession(String url) async {    try {      final result = await _channel.invokeMethod<String>('openSession', {'url': url});      if (result != null) {        final uri = Uri.parse(result);        return uri.queryParameters['id'];      }      return null;    } on PlatformException {      return null;    }  }}
```

### चरण 3: iOS प्लगइन लागू करें​

```
// ios/Runner/UnicoPlugin.swiftimport Flutterimport AuthenticationServicesclass UnicoPlugin: NSObject, FlutterPlugin, ASWebAuthenticationPresentationContextProviding {    private var session: ASWebAuthenticationSession?    static func register(with registrar: FlutterPluginRegistrar) {        let channel = FlutterMethodChannel(name: "unico_plugin", binaryMessenger: registrar.messenger())        let instance = UnicoPlugin()        registrar.addMethodCallDelegate(instance, channel: channel)    }    func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {        guard call.method == "openSession",              let args = call.arguments as? [String: Any],              let urlString = args["url"] as? String,              let url = URL(string: urlString) else {            result(FlutterMethodNotImplemented)            return        }        let newSession = ASWebAuthenticationSession(            url: url,            callbackURLScheme: "myapp"        ) { callbackURL, error in            self.session = nil            if let callbackURL = callbackURL {                result(callbackURL.absoluteString)            } else {                result(FlutterError(code: "SESSION_ERROR",                                    message: error?.localizedDescription ?? "Session cancelled",                                    details: nil))            }        }        newSession.presentationContextProvider = self        newSession.prefersEphemeralWebBrowserSession = true        newSession.start()        session = newSession    }    func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor {        guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,              let window = windowScene.windows.first else {            return ASPresentationAnchor()        }        return window    }}
```

`AppDelegate.swift` में रजिस्टर करें:
```
UnicoPlugin.register(with: self.registrar(forPlugin: "UnicoPlugin")!)
```

### चरण 4: Android प्लगइन लागू करें​

`android/app/build.gradle` में डिपेंडेंसी जोड़ें:
```
implementation("androidx.browser:browser:1.5.0")
```

```
// android/app/src/main/kotlin/<your.package>/UnicoPlugin.ktpackage com.yourappimport android.content.Intentimport android.net.Uriimport androidx.browser.customtabs.CustomTabsIntentimport io.flutter.embedding.engine.plugins.FlutterPluginimport io.flutter.embedding.engine.plugins.activity.ActivityAwareimport io.flutter.embedding.engine.plugins.activity.ActivityPluginBindingimport io.flutter.plugin.common.MethodCallimport io.flutter.plugin.common.MethodChannelclass UnicoPlugin : FlutterPlugin, MethodChannel.MethodCallHandler, ActivityAware {    private var channel: MethodChannel? = null    private var binding: ActivityPluginBinding? = null    private var pendingResult: MethodChannel.Result? = null    override fun onAttachedToEngine(flutterBinding: FlutterPlugin.FlutterPluginBinding) {        channel = MethodChannel(flutterBinding.binaryMessenger, "unico_plugin")        channel?.setMethodCallHandler(this)    }    override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {        if (call.method == "openSession") {            val url = call.argument<String>("url") ?: return result.error("MISSING_URL", "URL is required", null)            pendingResult = result            val activity = binding?.activity ?: return result.error("NO_ACTIVITY", "No activity", null)            CustomTabsIntent.Builder().build().launchUrl(activity, Uri.parse(url))        } else {            result.notImplemented()        }    }    fun handleRedirect(uri: Uri) {        if (uri.scheme == "myapp") {            pendingResult?.success(uri.toString())            pendingResult = null        }    }    override fun onAttachedToActivity(binding: ActivityPluginBinding) { this.binding = binding }    override fun onDetachedFromActivity() { binding = null }    override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) { this.binding = binding }    override fun onDetachedFromActivityForConfigChanges() { binding = null }    override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { channel = null }}
```

`MainActivity.kt` में रजिस्टर करें और रीडायरेक्ट हैंडल करें:
```
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {    super.configureFlutterEngine(flutterEngine)    flutterEngine.plugins.add(UnicoPlugin())}override fun onNewIntent(intent: Intent) {    super.onNewIntent(intent)    intent.data?.let { uri ->        if (uri.scheme == "myapp") {            val plugin = flutterEngine?.plugins?.get(UnicoPlugin::class.java) as? UnicoPlugin            plugin?.handleRedirect(uri)        }    }}
```

### चरण 5: URL स्कीम कॉन्फ़िगर करें​

iOSAndroid`Info.plist` में जोड़ें:```
<key>CFBundleURLTypes</key><array>    <dict>        <key>CFBundleURLSchemes</key>        <array>            <string>myapp</string>        </array>    </dict></array>
```

अपनी मुख्य `<activity>` के अंदर `AndroidManifest.xml` में जोड़ें:```
<intent-filter>    <action android:name="android.intent.action.VIEW" />    <category android:name="android.intent.category.DEFAULT" />    <category android:name="android.intent.category.BROWSABLE" />    <data android:scheme="myapp" android:host="callback" /></intent-filter>
```

### चरण 6: यात्रा शुरू करें​

```
final unicoService = UnicoService();final processId = await unicoService.openSession(processLink);if (processId != null) {  // Journey completed — send processId to your backend via Get Process} else {  // User canceled}
```

### फ़ाइल सारांश​

फ़ाइलउद्देश्य`lib/services/unico_service.dart`Dart MethodChannel सर्विस`ios/Runner/UnicoPlugin.swift`iOS — ASWebAuthenticationSession`ios/Runner/AppDelegate.swift`प्लगइन रजिस्ट्रेशन`android/.../UnicoPlugin.kt`Android — Custom Tabs`android/.../MainActivity.kt`प्लगइन रजिस्ट्रेशन + रीडायरेक्ट हैंडलिंग`Info.plist`iOS URL स्कीम`AndroidManifest.xml`Android Intent फ़िल्टरअंतिम अपडेट 21 अक्टू॰ 2026** को