패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.7

camerakit_flutter

Flutter 애플리케이션 내에서 Snapchat CameraKit 기능에 원활하게 통합하고 접근할 수 있도록 해주는 camerakit 플러그인입니다.

AndroidiOS
30일 다운로드
140
좋아요
34
Pub 점수
150

패키지 설치

flutter pub add camerakit_flutter

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

camerakit_flutter는 Android 및 iOS 모바일 애플리케이션에 Snapchat CameraKit 기능을 원활하게 통합할 수 있는 Flutter 플러그인입니다. 실시간 필터, 얼굴 감지, AR 효과와 같은 고급 카메라 기능에 간편한 Flutter 인터페이스를 통해 접근할 수 있도록 해줍니다. 네이티브 코드 지식 없이도 풍부한 시각적 경험을 구현하는 것을 단순화합니다. devcrew.io에서 개발된 이 플러그인은 CameraKit의 강력한 기능을 활용하여 Flutter 앱 내에서 고성능 카메라 기능을 제공합니다.

사용 사례

  • 소셜 미디어 앱에 AR 필터 추가하기
  • 사진 앱에서 실시간 얼굴 효과 구현하기
  • 인터랙티브 오버레이를 통한 비디오 채팅 향상
  • 증강현실 게임 만들기
  • Snapchat 스타일의 카메라 기능 통합

주요 기능

  • 무결점의 Flutter 통합
  • Android 및 iOS 지원
  • 실시간 얼굴 및 객체 추적
  • Snapchat의 AR 필터 라이브러리에 액세스
  • 카메라 제어를 위한 사용하기 쉬운 API
  • 고성능, 낮은 지연

적합한 대상

  • 카메라 기능이 풍부한 앱을 개발하는 플러터 개발자
  • 소셜 미디어 또는 메시징 플랫폼
  • AR 기능을 지원하는 엔터테인먼트 앱
  • 실시간 시각 효과가 필요한 앱

고려 사항

  • CameraKit SDK 설정 및 자격 증명이 필요합니다
  • 제공된 필터를 초과한 사용자 정의는 제한적입니다
  • 외부 SDK 업데이트에 의존
  • 통합된 자산으로 인해 앱 크기가 증가할 수 있습니다
  • 카메라 접근에 대한 적절한 권한 처리가 필요합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

camerakit-flutter

pub package license

An open-source SDK package for Flutter that provides developers with seamless integration and access to Snapchat's CameraKit features within their Flutter applications. Flutter developers now can access set configuration from Flutter for both platforms (IOS and Android), you can open CameraKit , get media results (Images and Videos) and get list of lenses against group ids.

Obtaining CameraKit Keys

Your App ID and API Token can be found in the Snap Kit Portal and is used to provide authorized access to Camera Kit remote services. For more information you can read the docs Android, IOS.

CAUTION

API Token is different for Production and Staging Environment. A watermark will be applied to the camera view when using the Staging API token.

Configuration

Once you have access to the account, locate your groupIds and cameraKitApiToken.

Now that you have obtained all your credentials, you can use it to initialize the Configuration class in your Flutter application as mentioned in the below section.

class Constants {
    /// List of group IDs for Camera Kit
    static const List<String> groupIdList = ['your-group-ids']; // TODO: Fill group IDs here
}
Android Setup

The easiest way to include this, is to define a tag in AndroidManifest.xml with a Camera Kit application ID value under tag:

<application ...>
    <meta-data android:name="com.snap.camerakit.app.id" android:value="" />
    <meta-data android:name="com.snap.camerakit.api.token" android:value="" />
</application>
iOS Setup

Add SCCameraKitClientID (string), and set it to your application's Snap Kit App ID in your application's Info.plist file.

Add SCCameraKitAPIToken (string), and set it to your application's API Token in your application's Info.plist file.

Note: To use production api token, your camerakit app should be approved and live on snapchat developer portal. Otherwise the app may cause unauthorized exception. Read more about submitting app for review

Installation

First, add camerakit_flutter: as a dependency in your pubspec.yaml file. Then run flutter pub get to install the package.

Now in your Dart code, you can use:

import 'package:camerakit_flutter/camerakit_flutter.dart';

iOS

Add the following keys to your Info.plist file, located in /ios/Runner/Info.plist:

  • NSCameraUsageDescription - describe why your app needs permission for the camera library. It's a privacy feature to ensure that apps don't access sensitive device features without the user's knowledge and consent.
  • NSMicrophoneUsageDescription - used to explain to the user why the app needs access to the device's microphone.
<key>NSCameraUsageDescription</key>
<string>app need camera permission for showing camerakit lens</string>
<key>NSMicrophoneUsageDescription</key>
<string>app need microphone permission for recording a video</string>
  • (Optional: To fix cocoapods installation error) Inside Podfile under iOS directory of your flutter project, uncomment the following line and set the iOS version 13
    platform :ios, '13.0'
    

Android

  • CameraKit android SDK requires to use an AppCompat Theme for application, so make sure your application theme inherits an AppCompat theme.

  • For example: in your style.xml define a new theme like this:

<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
  • and then in AndroidManifest.xml
 <application
    ...
    android:theme="@style/AppTheme">
    ...
    ...
</application>
  • Make sure in build.gradle under app module, the minSdkVersion version is 21
defaultConfig {
    minSdkVersion 21
}
  • Make sure in build.gradle under android module, the minimum kotlin_version version is 1.8.10
    ext.kotlin_version = '1.8.10'
    

Demo

https://github.com/DevCrew-io/camerakit-flutter/assets/136708738/63eb485d-1998-43f1-90ae-64193fde262e

Key Features

Passing CameraKit's credentials in Flutter

Access CameraKit in Flutter

Get List of lenses for given list of group ids

Get media results

Show list of lenses

Show camerakit's captured media

Access Camerakit in Flutter

Load all lenses

You can access camerakit by just calling openCameraKit function with only the list of groupIds to load all lenses of given groups. You can hide or show close button on camerakit screen by setting isHideCloseButton to true or false respectively.

late final _cameraKitFlutterImpl = CameraKitFlutterImpl(cameraKitFlutterEvents: this);
_cameraKitFlutterImpl.openCameraKit(
    groupIds: Constants.groupIdList,
    isHideCloseButton: false,
);
Load single lens

You can access camerakit with single lens by just calling openCameraKitWithSingleLens function with the lensId and groupId of that lens. You can hide or show close button on camerakit screen by setting isHideCloseButton to true or false respectively.

_cameraKitFlutterImpl.openCameraKitWithSingleLens(
    lensId: lensId!,
    groupId: groupId!,
    isHideCloseButton: false,
);

Get group lenses

To get group lenses you need to pass concerned list of group ids to the function.

_cameraKitFlutterImpl.getGroupLenses(
    groupIds: Constants.groupIdList,
);

Implement the interface CameraKitFlutterEvents to overirde receivedLenses function. you will get the List of Lens model.

class _MyAppState extends State<MyApp> implements CameraKitFlutterEvents {
    @override
    void receivedLenses(List<Lens> lensList) async {
        await Navigator.of(context).push(MaterialPageRoute(
        builder: (context) => LensListView(lensList: lensList)));
    }
}

Get media results

Call openCameraKit or openCameraKitWithSingleLens function to open Camerakit,

 _cameraKitFlutterImpl.openCameraKit(
    groupIds: Constants.groupIdList
);
 _cameraKitFlutterImpl.openCameraKitWithSingleLens(
    lensId: lensId!,
    groupId: groupId!
);

After capturing image or recording video you will get the results in onCameraKitResult method.

@override
void onCameraKitResult(Map<dynamic, dynamic> result) {
    setState(() {
        _filePath = result["path"] as String;
         _fileType = result["type"] as String;
    });
}

Show media

Here is example to show the image taken by camerakit.

class MediaResultWidget extends StatefulWidget {
  final String filePath;
  final String fileType;

  const MediaResultWidget(
      {super.key, required this.filePath, required this.fileType});

  @override
  State<MediaResultWidget> createState() => _CameraResultWidgetState();
}

class _CameraResultWidgetState extends State<MediaResultWidget> {
  late VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();

    _controller = VideoPlayerController.file(File(widget.filePath))
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
    _controller.addListener(() {
      if (!_controller.value.isPlaying &&
          _controller.value.isInitialized &&
          (_controller.value.duration == _controller.value.position)) {
        //checking the duration and position every time
        setState(() {
          if (kDebugMode) {
            print(
                "*************** video paying  c o m p l e t e d *******************");
          }
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text('CameraKit Result'),
        ),
        floatingActionButton: widget.filePath.isNotEmpty &&
                widget.fileType == "video"
            ? FloatingActionButton(
                onPressed: () {
                  setState(() {
                    _controller.value.isPlaying
                        ? _controller.pause()
                        : _controller.play();
                  });
                },
                child: Icon(
                  _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
                ),
              )
            : Container(),
        body: widget.filePath.isNotEmpty
            ? widget.fileType == 'video'
                ? Center(
                    child: AspectRatio(
                      aspectRatio: _controller.value.aspectRatio,
                      child: VideoPlayer(_controller),
                    ),
                  )
                : widget.fileType == 'image'
                    ? Center( child: Image.file(File(widget.filePath)) )
                    : const Text("UnKnown File to show")
            : const Text("No File to show"));
  }
}
2b

Show lens list

Here is example to show list of lenses.

class LensListView extends StatefulWidget {
  final List<Lens> lensList;

  const LensListView({super.key, required this.lensList});

  @override
  State<LensListView> createState() => _LensListWidgetState();
}

class _LensListWidgetState extends State<LensListView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Lens List'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          const SizedBox(
            height: 10,
          ),
          widget.lensList.isNotEmpty
              ? Expanded(
                  child: ListView.separated(
                      itemCount: widget.lensList.length,
                      separatorBuilder: (BuildContext context, int index) =>
                          const Divider(),
                      itemBuilder: (context, index) => GestureDetector(
                        child: Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: Row(
                                children: [
                                  Image.network(
                                    widget.lensList[index].thumbnail?[0] ?? "",
                                    width: 70,
                                    height: 70,
                                  ),
                                  const SizedBox(
                                    width: 20,
                                  ),
                                  Text(
                                    widget.lensList[index].name!,
                                    style: const TextStyle(
                                        fontSize: 16,
                                        fontStyle: FontStyle.italic),
                                  )
                                ],
                              ),
                            ),
                        onTap: (){
                          final Map<String, dynamic> arguments = {
                            'lensId': widget.lensList[index].id ?? "",
                            'groupId': widget.lensList[index].groupId ?? ""
                          };
                          Navigator.of(context).pop(arguments);
                        },
                      )),
                )
              : Container()
        ],
      ),
    );
  }
}
1c

Bugs and feature requests

Have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea is not addressed yet, please open a new issue.

Author

DevCrew I/O

Connect with Us:

devcrew.io mycompany DevCrew-io

Contributing

Contributions, issues, and feature requests are welcome!

Show your Support

Give a star if this project helped you.

카테고리

의존성

의존성 목록 1 개

  • plugin_platform_interface^2.0.2

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.