DevCrew-io / camerakit-flutter

An open-source SDK package for Flutter that provides developers with seamless integration and access to Snapchat's CameraKit features within their Flutter applications.
https://pub.dev/packages/camerakit_flutter
MIT License
17 stars 4 forks source link

App Crashed when I press OpenCameraKit #25

Closed dokind closed 11 months ago

dokind commented 11 months ago

Describe the bug App Crashed when I press OpenCameraKit

Expected behavior Launch CameraKit

Smartphone (please complete the following information):

Additional context Add any other context about the problem here.

`import 'package:camerakit_flutter/camerakit_flutter.dart'; import 'package:camerakit_flutter/configuration_camerakit.dart'; import 'package:camerakit_flutter/lens_model.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hyborg/src/camera_screen/snap_const.dart';

import 'lens_list_view.dart'; import 'media_result_widget.dart';

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

@override State createState() => _CameraDemeScreenState(); }

class _CameraDemeScreenState extends State implements CameraKitFlutterEvents { /// There will be interface that we will implement on [_CameraDemeScreenState] class in the future, /// right now we have no method to show override any function late String _filePath = ''; late String _fileType = ''; late List lensList = []; late final _cameraKitFlutterImpl = CameraKitFlutterImpl(cameraKitFlutterEvents: this); bool isLensListPressed = false;

@override void initState() { super.initState(); final config = Configuration( SnapConstants.cameraKitApiToken, SnapConstants.groupIdList, SnapConstants.cameraKitLensId, ); _cameraKitFlutterImpl.setCredentials(config); }

// Platform messages are asynchronous, so we initialize in an async method. Future initCameraKit() async { // Platform messages may fail, so we use a try/catch PlatformException. // We also handle the message potentially returning null. try { await _cameraKitFlutterImpl.openCameraKit(); // await _cameraKitFlutterImpl.getGroupLenses(SnapConstants.groupIdList); } on PlatformException { if (kDebugMode) { print("Failed to open camera kit"); } } }

// Platform messages are asynchronous, so we initialize in an async method. getGroupLenses() async { // Platform messages may fail, so we use a try/catch PlatformException. // We also handle the message potentially returning null. try { _cameraKitFlutterImpl.getGroupLenses(SnapConstants.groupIdList); } on PlatformException { if (kDebugMode) { print("Failed to open camera kit"); } } }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Camera Kit'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ ElevatedButton( onPressed: () { isLensListPressed = true; setState(() {}); getGroupLenses(); }, child: const Text("Show Lens List")), ElevatedButton( onPressed: () { initCameraKit(); }, child: const Text("Open CameraKit")), isLensListPressed ? const CircularProgressIndicator() : Container() ], ), ), ); }

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

  Navigator.of(context).push(
    MaterialPageRoute(
      builder: (context) => MediaResultWidget(
        filePath: _filePath,
        fileType: _fileType,
      ),
    ),
  );
});

}

@override void receivedLenses(List lensList) async { isLensListPressed = false; setState(() {}); await Navigator.of(context).push(MaterialPageRoute( builder: (context) => LensListView(lensList: lensList))); } } `

WaseemAbbas-DevCrew commented 11 months ago

@dokind can you please share the error details? Any console logs? Are you using the cameraKit staging or production environment? In case of production, the snap app must be approved and live in production. Also, make sure you have also set up the platform identifiers for both iOS and Android.

dokind commented 11 months ago

It's working in staging but not working in prod So My app didn't deployed yet. So I have to use prod token after I deploy my app in appstore ?

WaseemAbbas-DevCrew commented 11 months ago

It does not require the app to be deployed on the app store but it should be approved in the Snapchat developer portal. Please read here how to set up production and staging environments. You must have a version approved in production as well.

najamsaqib-devcreew commented 11 months ago

Duplicate App crash after I clicking on initLensList or openCamera #24