Skip to content

Commit a5a2103

Browse files
Add more passport and anyid document type support
1 parent 93e4a74 commit a5a2103

7 files changed

Lines changed: 136 additions & 16 deletions

example/lib/main.dart

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@ class _MyAppState extends State<MyApp> {
1818
late Uint8List resultRandomImage;
1919
late Uint8List resultCheckBackImage;
2020
late Uint8List resultIdCardBackImage;
21+
late Uint8List resultPassportImage;
22+
late Uint8List resultAnyIdImage;
2123

2224
@override
2325
void initState() {
2426
super.initState();
2527
resultRandomImage = Uint8List.fromList([]);
2628
resultCheckBackImage = Uint8List.fromList([]);
2729
resultIdCardBackImage = Uint8List.fromList([]);
30+
resultPassportImage = Uint8List.fromList([]);
31+
resultAnyIdImage = Uint8List.fromList([]);
2832
}
2933

3034
@override
@@ -36,9 +40,11 @@ class _MyAppState extends State<MyApp> {
3640
),
3741
body: Column(
3842
children: [
39-
_randomImageView(150.0, 150.0),
40-
_miSnapCheckBack(150.0, 150.0),
41-
_miSnapIdCardBack(150.0, 150.0),
43+
_randomImageView(150.0, 100.0),
44+
_miSnapCheckBack(150.0, 100.0),
45+
_miSnapIdCardBack(150.0, 100.0),
46+
_miSnapPassport(150.0, 100.0),
47+
_miSnapAnyId(150.0, 100.0),
4248
],
4349
),
4450
),
@@ -155,4 +161,78 @@ class _MyAppState extends State<MyApp> {
155161
),
156162
);
157163
}
164+
165+
Widget _miSnapPassport(double width, double height) {
166+
return SizedBox(
167+
height: height,
168+
width: width,
169+
child: Align(
170+
alignment: Alignment.center,
171+
child: InkWell(
172+
child: Container(
173+
decoration: BoxDecoration(
174+
color: const Color.fromARGB(100, 245, 245, 245),
175+
border: Border.all(
176+
width: 1,
177+
color: const Color.fromARGB(100, 204, 204, 204),
178+
),
179+
),
180+
child: resultPassportImage.isNotEmpty
181+
? Image.memory(
182+
resultPassportImage,
183+
fit: BoxFit.cover,
184+
)
185+
: const SizedBox(
186+
width: double.infinity,
187+
height: double.infinity,
188+
)),
189+
onTap: () {
190+
MisnapFlutter().misnapPassport().then((value) => {
191+
if (value != null && value.isNotEmpty)
192+
setState(() {
193+
resultPassportImage = value;
194+
})
195+
});
196+
},
197+
),
198+
),
199+
);
200+
}
201+
202+
Widget _miSnapAnyId(double width, double height) {
203+
return SizedBox(
204+
height: height,
205+
width: width,
206+
child: Align(
207+
alignment: Alignment.center,
208+
child: InkWell(
209+
child: Container(
210+
decoration: BoxDecoration(
211+
color: const Color.fromARGB(100, 245, 245, 245),
212+
border: Border.all(
213+
width: 1,
214+
color: const Color.fromARGB(100, 204, 204, 204),
215+
),
216+
),
217+
child: resultAnyIdImage.isNotEmpty
218+
? Image.memory(
219+
resultAnyIdImage,
220+
fit: BoxFit.cover,
221+
)
222+
: const SizedBox(
223+
width: double.infinity,
224+
height: double.infinity,
225+
)),
226+
onTap: () {
227+
MisnapFlutter().misnapAnyId().then((value) => {
228+
if (value != null && value.isNotEmpty)
229+
setState(() {
230+
resultAnyIdImage = value;
231+
})
232+
});
233+
},
234+
),
235+
),
236+
);
237+
}
158238
}

ios/Classes/SwiftMisnapFlutterPlugin.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ public class SwiftMisnapFlutterPlugin: NSObject, FlutterPlugin {
3737

3838
let configuration = MiSnapConfiguration(for: .idFront)
3939
self.setupMiSnapVC(configuration: configuration)
40+
41+
case "passport":
42+
43+
let configuration = MiSnapConfiguration(for: .passport)
44+
self.setupMiSnapVC(configuration: configuration)
4045

46+
case "any_id":
47+
48+
let configuration = MiSnapConfiguration(for: .anyId)
49+
self.setupMiSnapVC(configuration: configuration)
50+
4151
case "load_random_image":
4252
self.loadRandomImage()
4353

lib/misnap_config.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ class MiSnapPluginConfig {
44
static const checkFront = 'check_front';
55
static const idCardBack = 'id_card_back';
66
static const idCardFront = 'id_card_front';
7+
static const passport = 'passport';
8+
static const anyId = 'any_id';
79
static const randomImage = 'load_random_image';
810
}

lib/misnap_flutter.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ class MisnapFlutter {
2222
Future<Uint8List?> misnapIdCardFront() async {
2323
return MisnapFlutterPlatform.instance.misnapIdCardFront();
2424
}
25+
26+
Future<Uint8List?> misnapPassport() async {
27+
return MisnapFlutterPlatform.instance.misnapPassport();
28+
}
29+
30+
Future<Uint8List?> misnapAnyId() async {
31+
return MisnapFlutterPlatform.instance.misnapAnyId();
32+
}
2533
}

lib/misnap_flutter_method_channel.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,38 @@ class MethodChannelMisnapFlutter extends MisnapFlutterPlatform {
1414

1515
@override
1616
Future<Uint8List?> loadRandomImage() async {
17-
final image = await methodChannel
17+
return methodChannel
1818
.invokeMethod<Uint8List>(MiSnapPluginConfig.randomImage);
19-
return image;
2019
}
2120

2221
@override
2322
Future<Uint8List?> misnapCheckBack() async {
24-
final image = await methodChannel
25-
.invokeMethod<Uint8List>(MiSnapPluginConfig.checkBack);
26-
return image;
23+
return methodChannel.invokeMethod<Uint8List>(MiSnapPluginConfig.checkBack);
2724
}
2825

2926
@override
3027
Future<Uint8List?> misnapCheckFront() async {
31-
final image = await methodChannel
32-
.invokeMethod<Uint8List>(MiSnapPluginConfig.checkFront);
33-
return image;
28+
return methodChannel.invokeMethod<Uint8List>(MiSnapPluginConfig.checkFront);
3429
}
3530

3631
@override
3732
Future<Uint8List?> misnapIdCardBack() async {
38-
final image = await methodChannel
39-
.invokeMethod<Uint8List>(MiSnapPluginConfig.idCardBack);
40-
return image;
33+
return methodChannel.invokeMethod<Uint8List>(MiSnapPluginConfig.idCardBack);
4134
}
4235

4336
@override
4437
Future<Uint8List?> misnapIdCardFront() async {
45-
final image = await methodChannel
38+
return methodChannel
4639
.invokeMethod<Uint8List>(MiSnapPluginConfig.idCardFront);
47-
return image;
40+
}
41+
42+
@override
43+
Future<Uint8List?> misnapPassport() async {
44+
return methodChannel.invokeMethod<Uint8List>(MiSnapPluginConfig.passport);
45+
}
46+
47+
@override
48+
Future<Uint8List?> misnapAnyId() async {
49+
return methodChannel.invokeMethod<Uint8List>(MiSnapPluginConfig.anyId);
4850
}
4951
}

lib/misnap_flutter_platform_interface.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,12 @@ abstract class MisnapFlutterPlatform extends PlatformInterface {
4444
Future<Uint8List?> misnapIdCardFront() {
4545
throw UnimplementedError('misnapIdCardFront() has not been implemented.');
4646
}
47+
48+
Future<Uint8List?> misnapPassport() {
49+
throw UnimplementedError('misnapPassport() has not been implemented.');
50+
}
51+
52+
Future<Uint8List?> misnapAnyId() {
53+
throw UnimplementedError('misnapAnyId() has not been implemented.');
54+
}
4755
}

test/misnap_flutter_test.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ class MockMisnapFlutterPlatform
3232
Future<Uint8List?> misnapIdCardFront() {
3333
throw UnimplementedError();
3434
}
35+
36+
@override
37+
Future<Uint8List?> misnapAnyId() {
38+
throw UnimplementedError();
39+
}
40+
41+
@override
42+
Future<Uint8List?> misnapPassport() {
43+
throw UnimplementedError();
44+
}
3545
}
3646

3747
void main() {

0 commit comments

Comments
 (0)