Implementation

The following is an example MetaMapPage class with the MetaMap method implementation:

import 'package:flutter/material.dart';
import 'package:metamap_plugin_flutter/metamap_plugin_flutter.dart';
import 'package:metamap_plugin_flutter/Result.dart'; // Adjust path based on your setup

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MetaMap Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MetaMapPage(),
    );
  }
}

class MetaMapPage extends StatefulWidget {
  const MetaMapPage({Key? key}) : super(key: key);

  @override
  State<MetaMapPage> createState() => _MetaMapPageState();
}

class _MetaMapPageState extends State<MetaMapPage> {
  @override
  void initState() {
    super.initState();

    /// Callback for when verification is created (before it's completed or cancelled)
    MetaMapFlutter.onCreated = (ResultCreated result) {
      debugPrint("🟡 Verification created:");
      debugPrint("   • verificationId: ${result.verificationId}");
      debugPrint("   • identityId: ${result.identityId}");
    };
  }

  Future<void> showMetaMapFlow() async {
    try {
      debugPrint("🚀 Starting MetaMap verification...");

      final result = await MetaMapFlutter.showMetaMapFlow(
        clientId: "YOUR_CLIENT_ID", // Replace with your actual clientId
        flowId: "YOUR_FLOW_ID",    // Replace with your actual flowId
        metadata: {
          "key": "value",
          // Example metadata — optional
        },
      );

      if (result is ResultSuccess) {
        debugPrint("✅ Verification successful!");
        debugPrint("   • verificationId: ${result.verificationId}");
        debugPrint("   • identityId: ${result.identityId}");
      } else if (result is ResultCancelled) {
        debugPrint("❌ Verification cancelled by user.");
        debugPrint("   • verificationId: ${result.verificationId}");
        debugPrint("   • identityId: ${result.identityId}");
      }
    } catch (e) {
      debugPrint("🔥 Error during MetaMap flow: $e");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("MetaMap Flutter Plugin Demo"),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: showMetaMapFlow,
          child: const Text('Start MetaMap Verification'),
        ),
      ),
    );
  }
}

In order to make this work you need to set your own CLIENT_ID and FLOW_ID. You can find them in the Metamap Dashboard, for more details please check this section.