Skip to content

Commit e6b15fa

Browse files
Merge pull request #33 from DevCrew-io/bug-fixes
Bug Fixes & Improvements
2 parents b442741 + d5df862 commit e6b15fa

30 files changed

+825
-334
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## 0.0.7
2+
### Fixed
3+
* `Low Quality` output image (iOS).
4+
* Release `Camera` and `Microphone` access when closing the camera screen (iOS).
5+
6+
### Added
7+
* `Close Button` on camera screen, Default it is visible but can hide it with `isHideCloseButton` to true.
8+
* Open the camera screen with a single lens when the user taps on a lens list.
9+
10+
### Updated
11+
* Package implementation guide.
12+
* Example Project
13+
* README.md
14+
115
## 0.0.6
216
* Make cameraKitLensId optional
317
* Snap CameraKit Upgraded to 1.27.0

README.md

Lines changed: 127 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ For more information you can read the docs [Android](https://docs.snap.com/camer
1515
#### CAUTION
1616
**API Token** is different for **Production** and **Staging** Environment. A watermark will be applied to the camera view when using the Staging API token.
1717

18-
Once you have access to the account, locate your **groupIds**, **cameraKitLensId** (optional) and **cameraKitApiToken**.
18+
Once you have access to the account, locate your **groupIds** and **cameraKitApiToken**.
1919

2020
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.
2121

2222
```dart
23-
class Constants {
24-
/// List of group IDs for Camera Kit (TODO: Fill group ID here).
25-
static const List<String> groupIdList = ['your-group-ids'];
26-
/// optional: if you want to get single lense you can set it otherwise set empty sting
27-
/// The lens ID for Camera Kit (TODO: Fill lens ID here).
28-
static const cameraKitLensId = 'camera-kit-lens-id';
29-
/// The API token for Camera Kit in the staging environment (TODO: Fill API token here).
30-
static const cameraKitApiToken = 'your-api-token'; //TODO fill api token staging & production here
31-
}
23+
class Constants {
24+
/// List of group IDs for Camera Kit
25+
static const List<String> groupIdList = ['your-group-ids']; // TODO: Fill group IDs here
26+
27+
/// The API token for Camera Kit in the staging environment
28+
static const cameraKitApiToken = 'your-api-token'; // TODO fill api token staging or production here
29+
}
3230
```
3331
**Note:** To use production api token, your camerakit app should be approved and live on snapchat developer portal.
3432
Otherwise the app may cause `unauthorized` exception. [Read more](https://docs.snap.com/camera-kit/app-review/release-app) about submitting app for review
@@ -39,48 +37,48 @@ Then run ```flutter pub get``` to install the package.
3937

4038
Now in your Dart code, you can use:
4139
```dart
42-
import 'package:camerakit_flutter/camerakit_flutter.dart';
40+
import 'package:camerakit_flutter/camerakit_flutter.dart';
4341
```
4442
## iOS
4543
Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:
4644

4745
* 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.
4846
* NSMicrophoneUsageDescription - used to explain to the user why the app needs access to the device's microphone.
4947
```dart
50-
<key>NSCameraUsageDescription</key>
51-
<string>app need camera permission for showing camerakit lens</string>
52-
<key>NSMicrophoneUsageDescription</key>
53-
<string>app need microphone permission for recording a video</string>
48+
<key>NSCameraUsageDescription</key>
49+
<string>app need camera permission for showing camerakit lens</string>
50+
<key>NSMicrophoneUsageDescription</key>
51+
<string>app need microphone permission for recording a video</string>
5452
```
5553
* (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
5654
```
57-
platform :ios, '13.0'
55+
platform :ios, '13.0'
5856
```
5957
## Android
6058
* CameraKit android SDK requires to use an AppCompat Theme for application, so make sure your application theme inherits an AppCompat theme.
6159

6260
* For example: in your `style.xml` define a new theme like this:
6361
```xml
64-
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
62+
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
6563
```
6664
* and then in `AndroidManifest.xml`
6765
```xml
68-
<application
69-
...
70-
android:theme="@style/AppTheme">
71-
...
72-
...
73-
</application>
66+
<application
67+
...
68+
android:theme="@style/AppTheme">
69+
...
70+
...
71+
</application>
7472
```
7573
* Make sure in `build.gradle` under app module, the `minSdkVersion` version is `21`
7674
```groovy
77-
defaultConfig {
78-
minSdkVersion 21
79-
}
75+
defaultConfig {
76+
minSdkVersion 21
77+
}
8078
```
8179
* Make sure in `build.gradle` under android module, the minimum `kotlin_version` version is `1.8.10`
8280
```
83-
ext.kotlin_version = '1.8.10'
81+
ext.kotlin_version = '1.8.10'
8482
```
8583
## Demo
8684

@@ -105,67 +103,82 @@ https://github.com/DevCrew-io/camerakit-flutter/assets/136708738/63eb485d-1998-4
105103

106104
## Set Configuration
107105

108-
Configuration class is used to pass all credentials required for Camerakit, you can pass list of Group ids to show all group lenses. You don't need to set separate credentials for iOS and Android.
106+
You can set camerakit credentials by just calling setCredentials function. Before calling you need instance of CameraKitFlutterImpl, you only need to pass apiToken to configure camerakit flutter package. You don't need to set separate credentials for iOS and Android.
109107

110108
```dart
111-
final config = Configuration(
112-
Constants.cameraKitApiToken,
113-
Constants.groupIdList);
114-
115-
_cameraKitFlutterImpl.setCredentials(config);
109+
late final _cameraKitFlutterImpl = CameraKitFlutterImpl(cameraKitFlutterEvents: this);
110+
_cameraKitFlutterImpl.setCredentials(apiToken: Constants.cameraKitApiToken);
116111
```
117112
## Access Camerakit in Flutter
118-
You can access camerakit by just calling openCameraKit function. Before calling you need instance of CameraKitFlutterImpl to get required function
113+
### Load all lenses
114+
You can access camerakit by just calling openCameraKit function with only the list of groupIds to load all lenses of given groups.
115+
You can hide or show close button on camerakit screen by setting isHideCloseButton to true or false respectively.
119116
```dart
120-
late final _cameraKitFlutterImpl =
121-
CameraKitFlutterImpl(cameraKitFlutterEvents: this);
122-
await _cameraKitFlutterImpl.openCameraKit();
117+
_cameraKitFlutterImpl.openCameraKit(
118+
groupIds: Constants.groupIdList,
119+
isHideCloseButton: false,
120+
);
121+
```
122+
### Load single lens
123+
You can access camerakit with single lens by just calling openCameraKitWithSingleLens function with the lensId and groupId of that lens.
124+
You can hide or show close button on camerakit screen by setting isHideCloseButton to true or false respectively.
125+
```dart
126+
_cameraKitFlutterImpl.openCameraKitWithSingleLens(
127+
lensId: lensId!,
128+
groupId: groupId!,
129+
isHideCloseButton: false,
130+
);
123131
```
124132
## Get group lenses
125133

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

128136
```dart
129-
130-
_cameraKitFlutterImpl.getGroupLenses(Constants.groupIdList);
131-
137+
_cameraKitFlutterImpl.getGroupLenses(
138+
groupIds: Constants.groupIdList,
139+
);
132140
```
133141

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

137145
```dart
138-
139146
class _MyAppState extends State<MyApp> implements CameraKitFlutterEvents {
140-
@override
141-
void receivedLenses(List<Lens> lensList) async {
142-
143-
await Navigator.of(context).push(MaterialPageRoute(
147+
@override
148+
void receivedLenses(List<Lens> lensList) async {
149+
await Navigator.of(context).push(MaterialPageRoute(
144150
builder: (context) => LensListView(lensList: lensList)));
145-
}
151+
}
146152
}
147153
```
148154

149155
## Get media results
150-
Call openCamerakit function to open Camerakit,
156+
Call openCameraKit or openCameraKitWithSingleLens function to open Camerakit,
151157
```dart
152-
await _cameraKitFlutterImpl.openCameraKit();
158+
_cameraKitFlutterImpl.openCameraKit(
159+
groupIds: Constants.groupIdList
160+
);
161+
```
162+
```dart
163+
_cameraKitFlutterImpl.openCameraKitWithSingleLens(
164+
lensId: lensId!,
165+
groupId: groupId!
166+
);
153167
```
154168
After capturing image or recording video you will get the results in onCameraKitResult method.
155169

156170
```dart
157-
@override
158-
void onCameraKitResult(Map<dynamic, dynamic> result) {
171+
@override
172+
void onCameraKitResult(Map<dynamic, dynamic> result) {
159173
setState(() {
160-
_filePath = result["path"] as String;
161-
_fileType = result["type"] as String;
174+
_filePath = result["path"] as String;
175+
_fileType = result["type"] as String;
162176
});
163-
}
177+
}
164178
```
165179
## Show media
166180
Here is example to show the image taken by camerakit.
167181
```dart
168-
169182
class MediaResultWidget extends StatefulWidget {
170183
final String filePath;
171184
final String fileType;
@@ -195,8 +208,10 @@ class _CameraResultWidgetState extends State<MediaResultWidget> {
195208
(_controller.value.duration == _controller.value.position)) {
196209
//checking the duration and position every time
197210
setState(() {
198-
print(
199-
"*************** video paying c o m p l e t e d *******************");
211+
if (kDebugMode) {
212+
print(
213+
"*************** video paying c o m p l e t e d *******************");
214+
}
200215
});
201216
}
202217
});
@@ -209,36 +224,34 @@ class _CameraResultWidgetState extends State<MediaResultWidget> {
209224
title: const Text('CameraKit Result'),
210225
),
211226
floatingActionButton: widget.filePath.isNotEmpty &&
212-
widget.fileType == "video"
227+
widget.fileType == "video"
213228
? FloatingActionButton(
214-
onPressed: () {
215-
setState(() {
216-
_controller.value.isPlaying
217-
? _controller.pause()
218-
: _controller.play();
219-
});
220-
},
221-
child: Icon(
222-
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
223-
),
224-
)
229+
onPressed: () {
230+
setState(() {
231+
_controller.value.isPlaying
232+
? _controller.pause()
233+
: _controller.play();
234+
});
235+
},
236+
child: Icon(
237+
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
238+
),
239+
)
225240
: Container(),
226241
body: widget.filePath.isNotEmpty
227242
? widget.fileType == 'video'
228-
? Center(
229-
child: AspectRatio(
230-
aspectRatio: _controller.value.aspectRatio,
231-
child: VideoPlayer(_controller),
232-
),
233-
)
234-
: widget.fileType == 'image'
235-
? Image.file(File(widget.filePath))
236-
: const Text("UnKnown File to show")
243+
? Center(
244+
child: AspectRatio(
245+
aspectRatio: _controller.value.aspectRatio,
246+
child: VideoPlayer(_controller),
247+
),
248+
)
249+
: widget.fileType == 'image'
250+
? Center( child: Image.file(File(widget.filePath)) )
251+
: const Text("UnKnown File to show")
237252
: const Text("No File to show"));
238253
}
239254
}
240-
241-
242255
```
243256
<img width="180" height="350" alt="2b" src="https://github.com/DevCrew-io/camerakit-flutter/assets/72248282/c2eea95f-aaa8-43f9-9982-8d51777fe870">
244257

@@ -271,39 +284,47 @@ class _LensListWidgetState extends State<LensListView> {
271284
),
272285
widget.lensList.isNotEmpty
273286
? Expanded(
274-
child: ListView.separated(
275-
itemCount: widget.lensList.length,
276-
separatorBuilder: (BuildContext context, int index) =>
277-
const Divider(),
278-
itemBuilder: (context, index) => Padding(
279-
padding: const EdgeInsets.all(2.0),
280-
child: Row(
281-
children: [
282-
Image.network(
283-
widget.lensList[index].thumbnail?[0] ?? "",
284-
width: 70,
285-
height: 70,
286-
),
287-
const SizedBox(
288-
width: 20,
289-
),
290-
Text(
291-
widget.lensList[index].name!,
292-
style: const TextStyle(
293-
fontSize: 16,
294-
fontStyle: FontStyle.italic),
295-
)
296-
],
297-
),
298-
)),
299-
)
287+
child: ListView.separated(
288+
itemCount: widget.lensList.length,
289+
separatorBuilder: (BuildContext context, int index) =>
290+
const Divider(),
291+
itemBuilder: (context, index) => GestureDetector(
292+
child: Padding(
293+
padding: const EdgeInsets.all(8.0),
294+
child: Row(
295+
children: [
296+
Image.network(
297+
widget.lensList[index].thumbnail?[0] ?? "",
298+
width: 70,
299+
height: 70,
300+
),
301+
const SizedBox(
302+
width: 20,
303+
),
304+
Text(
305+
widget.lensList[index].name!,
306+
style: const TextStyle(
307+
fontSize: 16,
308+
fontStyle: FontStyle.italic),
309+
)
310+
],
311+
),
312+
),
313+
onTap: (){
314+
final Map<String, dynamic> arguments = {
315+
'lensId': widget.lensList[index].id ?? "",
316+
'groupId': widget.lensList[index].groupId ?? ""
317+
};
318+
Navigator.of(context).pop(arguments);
319+
},
320+
)),
321+
)
300322
: Container()
301323
],
302324
),
303325
);
304326
}
305327
}
306-
307328
```
308329
<img width="180" height="350" alt="1c" src="https://github.com/DevCrew-io/camerakit-flutter/assets/72248282/5eecc1e8-8d8a-4e3b-84f1-956038ebf0bc">
309330

@@ -331,8 +352,3 @@ Contributions, issues, and feature requests are welcome!
331352
## Show your Support
332353

333354
Give a star if this project helped you.
334-
335-
## Copyright & License
336-
337-
Code copyright 2023 DevCrew I/O. Code released under
338-
the [MIT license](https://github.com/DevCrew-io/expandable-richtext/blob/main/LICENSE).

android/src/main/AndroidManifest.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.camerakit.camerakit_flutter">
2+
package="com.camerakit.camerakit_flutter">
33

4-
<uses-permission android:name="android.permission.INTERNET"/>
4+
<uses-permission android:name="android.permission.INTERNET" />
55
<uses-permission android:name="android.permission.CAMERA" />
66
<uses-permission android:name="android.permission.RECORD_AUDIO" />
77
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
8+
9+
<application>
10+
<activity android:name="com.camerakit.camerakit_flutter.ARCameraActivity" />
11+
</application>
12+
813
</manifest>

0 commit comments

Comments
 (0)