You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否在Flutter应用中使用Bitmoji?可行的话该如何实现?

Absolutely! You can totally integrate Bitmoji into your Flutter app—while there’s no official Flutter plugin for Bitmoji right now, there are two solid approaches to make this work. Let me break them down for you:

方法1:通过MethodChannel集成Snap Kit(Bitmoji官方支持)

This is the most robust method since it leverages Snap’s official Bitmoji Kit, giving you full access to user Bitmojis, stickers, and customization options. Here’s how to set it up:

步骤1:准备Snap开发者账号

First, head over to the Snap Developer Portal to register your app, get your API keys, and configure the native iOS/Android projects according to Snap’s official documentation (you’ll need to add the Snap Kit dependencies to both native projects).

步骤2:Flutter端创建MethodChannel

Use Flutter’s MethodChannel to communicate between your Dart code and the native Bitmoji Kit implementation:

import 'package:flutter/services.dart';

class BitmojiService {
  static const _channel = MethodChannel('com.yourapp/bitmoji');

  // Fetch the user's Bitmoji avatar URL
  static Future<String?> getBitmojiAvatar() async {
    try {
      final String? avatarUrl = await _channel.invokeMethod('fetchBitmojiAvatar');
      return avatarUrl;
    } on PlatformException catch (e) {
      print('Error fetching Bitmoji: ${e.message}');
      return null;
    }
  }
}

步骤3:原生端实现Bitmoji逻辑

Android (Kotlin)

In your MainActivity.kt, set up the MethodChannel handler and call the Bitmoji Kit APIs:

class MainActivity : FlutterActivity() {
    private val CHANNEL = "com.yourapp/bitmoji"

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
            when (call.method) {
                "fetchBitmojiAvatar" -> {
                    // Implement Snap Kit's Bitmoji login and avatar fetch logic here
                    val avatarUrl = getCurrentUserBitmojiUrl()
                    avatarUrl?.let { result.success(it) } ?: result.error("FAILED", "No Bitmoji found", null)
                }
                else -> result.notImplemented()
            }
        }
    }

    private fun getCurrentUserBitmojiUrl(): String? {
        // Replace with actual Snap Kit Bitmoji retrieval code
        return BitmojiClient.getCurrentUser()?.avatar?.url
    }
}

iOS (Swift)

In your AppDelegate.swift, add the MethodChannel handler:

import UIKit
import Flutter
import SnapKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        let controller = window?.rootViewController as! FlutterViewController
        let bitmojiChannel = FlutterMethodChannel(name: "com.yourapp/bitmoji", binaryMessenger: controller.binaryMessenger)
        
        bitmojiChannel.setMethodCallHandler { [weak self] call, result in
            guard call.method == "fetchBitmojiAvatar" else {
                result(FlutterMethodNotImplemented)
                return
            }
            self?.fetchBitmojiAvatar(result: result)
        }
        
        GeneratedPluginRegistrant.register(with: self)
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }

    private func fetchBitmojiAvatar(result: FlutterResult) {
        // Implement Snap Kit's Bitmoji login and avatar fetch logic here
        if let avatarUrl = BitmojiManager.shared.currentUser?.avatarUrl {
            result(avatarUrl)
        } else {
            result(FlutterError(code: "FAILED", message: "No Bitmoji found", details: nil))
        }
    }
}
方法2:使用WebView嵌入Bitmoji Web Widget

If you need a quick, low-effort integration (great for prototypes), you can embed Bitmoji’s web widget using Flutter’s webview_flutter package.

步骤1:添加依赖

Add webview_flutter to your pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  webview_flutter: ^4.4.0 # Use the latest version

步骤2:创建WebView页面

Load the Bitmoji web widget in a WebView (you’ll need a widget ID from the Snap Developer Portal):

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

class BitmojiWidgetScreen extends StatefulWidget {
  const BitmojiWidgetScreen({super.key});

  @override
  State<BitmojiWidgetScreen> createState() => _BitmojiWidgetScreenState();
}

class _BitmojiWidgetScreenState extends State<BitmojiWidgetScreen> {
  late WebViewController _controller;

  @override
  void initState() {
    super.initState();
    _controller = WebViewController()
      ..loadHtmlString('''
        <html>
          <body style="margin:0;">
            <script src="https://sdk.bitmoji.com/embed.js"></script>
            <div class="bitmoji-widget" data-widget-id="YOUR_WIDGET_ID" data-size="large"></div>
          </body>
        </html>
      ''');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('My Bitmoji')),
      body: WebViewWidget(controller: _controller),
    );
  }
}
关键注意事项
  • Snap Developer Portal Setup: Both methods require you to register your app and get valid credentials from Snap’s developer platform—don’t skip this step!
  • MethodChannel vs WebView: The MethodChannel approach offers full functionality (login, custom Bitmojis, stickers) but requires native code work. The WebView method is quick but limited to the web widget’s features.
  • User Authentication: For the Snap Kit method, you’ll need to implement Snap login to let users connect their Bitmoji accounts to your app.

内容的提问来源于stack exchange,提问作者SOS video

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 15:02:34