contouraisdk 1.10.4
contouraisdk: ^1.10.4 copied to clipboard
The Contour AI SDK™ has been designed to be the industry’s most intuitive, and protected, experience for mobile image capture - capturing documents of various kinds via an iOS™ or Android™ mobile devi [...]
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:contouraisdk/contouraisdk.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String frontImageUri = '';
String rearImageUri = '';
@override
void initState() {
super.initState();
Contouraisdk.registerCallbacks(onDataReceived, onEventCaptured, onContourClosed);
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> callContour(String face) async {
try {
await Contouraisdk.startContourSDK("", face, "both", false);
} on PlatformException catch (e) {
print(e.message);
}
}
void onDataReceived(Map<String, String> data) {
String? croppedFront = data['croppedFrontUri'];
String? croppedRear = data['croppedRearUri'];
print('Received data from URI for front cropped: $croppedFront');
print('Received data from URI for rear cropped: ${data['croppedRearUri']}');
print('Received data from URI for front full: ${data['frontUri']}');
print('Received data from URI for rear full: ${data['rearUri']}');
if (croppedFront != null) {
setState(() {
frontImageUri = data['croppedFrontUri']!;
});
}
if (croppedRear != null) {
setState(() {
rearImageUri = data['croppedRearUri']!;
});
}
}
void onEventCaptured(String data) {
print('Received data in onEventCaptured: $data');
}
void onContourClosed() {
print('Received data in onContourClosed');
}
Widget _buildImageWidget(
String uri, double width, double height, String face) {
if (uri.isNotEmpty) {
return GestureDetector(
onTap: () {
callContour(face);
}, // Define the click handler function
child: Image.file(
File(uri),
width: width,
height: height,
),
);
} else {
return GestureDetector(
onTap: () {
callContour(face);
},
child: Image.asset(
'assets/placeholder.png',
width: width,
height: height,
),
);
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Contour example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 24),
const Text("Front",
style: TextStyle(fontSize: 16, color: Colors.black87)),
const SizedBox(height: 16),
_buildImageWidget(frontImageUri, 400, 200, 'front'),
const SizedBox(height: 30),
const Text("Back",
style: TextStyle(fontSize: 16, color: Colors.black87)),
const SizedBox(height: 16),
_buildImageWidget(rearImageUri, 400, 200, 'back'),
],
))),
);
}
}