Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ plugins {

android {
namespace = "com.example.scanbot_sdk_example_flutter"
compileSdk = 35
compileSdk = 36

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_17
jvmTarget = JavaVersion.VERSION_21
}

defaultConfig {
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>

<!-- required for mock camera functionality to allow full access to external storage.-->
<!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />-->
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri May 10 16:38:24 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.3.2" apply false
id "org.jetbrains.kotlin.android" version "1.9.20" apply false
id "com.android.application" version "8.10.1" apply false
id "org.jetbrains.kotlin.android" version "2.1.21" apply false
}

include ":app"
105 changes: 50 additions & 55 deletions lib/classic_components/cropping_custom_ui.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:scanbot_sdk/scanbot_sdk.dart';
import 'package:scanbot_sdk/scanbot_sdk.dart' as sdk;
import '../storage/_legacy_pages_repository.dart';
import '../utility/utils.dart';

/// This screen demonstrates how to integrate the classical cropping component
class CroppingScreenWidget extends StatefulWidget {
const CroppingScreenWidget({Key? key, required this.page}) : super(key: key);
final sdk.Page page;
const CroppingScreenWidget({Key? key, required this.documentImage})
: super(key: key);
final ImageRef documentImage;

@override
_CroppingScreenWidgetState createState() => _CroppingScreenWidgetState();
}

class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
final LegacyPageRepository _pageRepository = LegacyPageRepository();
late sdk.Page currentPage;
late ImageRef currentPage;
bool showProgressBar = false;
bool doneButtonEnabled = true;
CroppingController? croppingController;

@override
void initState() {
super.initState();
currentPage = widget.page;
currentPage = widget.documentImage;
}

@override
Expand All @@ -36,36 +37,13 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
if (showProgressBar) _buildProgressBar(),
],
),
floatingActionButton: _buildFloatingActionButton(),
bottomNavigationBar: _buildBottomAppBar(),
);
}

Widget _buildFloatingActionButton() {
return FloatingActionButton(
onPressed: _handleNextPage,
child: const Icon(Icons.navigate_next),
);
}

Future<void> _handleNextPage() async {
setState(() {
showProgressBar = true;
});

final nextPage = await _pageRepository.nextPage(currentPage);

setState(() {
showProgressBar = false;
currentPage = nextPage;
});
}

AppBar _buildAppBar() {
return AppBar(
iconTheme: const IconThemeData(
color: Colors.white,
),
iconTheme: const IconThemeData(color: Colors.white),
backgroundColor: ScanbotRedColor,
title: const Text(
'Crop document',
Expand All @@ -82,17 +60,14 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
),
actions: [
if (doneButtonEnabled)
IconButton(
icon: const Icon(Icons.done),
onPressed: cropAndPop,
),
IconButton(icon: const Icon(Icons.done), onPressed: cropAndPop),
],
);
}

Widget _buildCroppingWidget() {
return ScanbotCroppingWidget(
page: currentPage,
documentImage: currentPage,
onViewReady: (controller) {
croppingController = controller;
},
Expand All @@ -101,10 +76,13 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
showProgressBar = isProcessing;
});
},
onError: (error) {
Logger.root.severe(error.toString());
},
edgeColor: Colors.red,
edgeColorOnLine: Colors.blue,
anchorPointsColor: Colors.amberAccent,
borderInsets: sdk.Insets.all(16),
borderInsets: Insets.all(16),
);
}

Expand All @@ -125,7 +103,7 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
children: [
_buildBottomBarButton('Reset', () => croppingController?.reset()),
_buildBottomBarButton('Detect', () => croppingController?.detect()),
_buildBottomBarButton('Rotate Cw', _rotateImage),
_buildBottomBarButton('Rotate CW', _rotateImage),
],
),
);
Expand All @@ -134,10 +112,7 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
Widget _buildBottomBarButton(String label, VoidCallback onPressed) {
return TextButton(
onPressed: doneButtonEnabled ? onPressed : null,
child: Text(
label,
style: const TextStyle(color: Colors.black),
),
child: Text(label, style: const TextStyle(color: Colors.black)),
);
}

Expand All @@ -155,15 +130,6 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
});
}

Future<sdk.Page> proceedImage(
sdk.Page page, CroppingPolygon croppingResult) async {
return await ScanbotSdk.cropAndRotatePage(
page,
croppingResult.polygon,
croppingResult.rotationTimesCw,
);
}

Future<void> cropAndPop() async {
setState(() {
showProgressBar = true;
Expand All @@ -175,9 +141,38 @@ class _CroppingScreenWidgetState extends State<CroppingScreenWidget> {
showProgressBar = false;
});

if (croppingResult != null) {
var newPage = await proceedImage(currentPage, croppingResult);
Navigator.of(context).pop(newPage);
if (croppingResult == null) {
Navigator.of(context).pop();
return;
}

final documentResult = await ScanbotSdk.document
.createDocumentFromImageRefs(images: [currentPage]);

if (documentResult is! Ok<DocumentData>) {
print(documentResult.toString());
return;
}

final document = documentResult.value;

final modifiedDocumentResult = await ScanbotSdk.document.modifyPage(
document.uuid,
document.pages.first.uuid,
options: ModifyPageOptions(
rotation: ImageRotation.values[croppingResult.rotationTimesCw],
polygon: toPointList(croppingResult.polygon),
),
);

if (modifiedDocumentResult is! Ok<DocumentData>) {
print(modifiedDocumentResult.toString());
return;
}

Navigator.of(context).pop(modifiedDocumentResult.value);
}
}
}

List<Point<double>> toPointList(List<PolygonPoint> polygon) =>
polygon.map((p) => Point<double>(p.x, p.y)).toList();
64 changes: 0 additions & 64 deletions lib/classic_components/custom_ui_menu.dart

This file was deleted.

Loading