Skip to content

Commit

Permalink
Modify styles
Browse files Browse the repository at this point in the history
  • Loading branch information
weta-vn committed Oct 10, 2021
1 parent 32b505d commit e2d5a52
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.1.5]

* **New features:**
* Object detection & OCR extraction interface for image

## [0.1.4]

* **New `ImagePickerConfigs` features:**
Expand Down
7 changes: 5 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ class MyApp extends StatelessWidget {
fullscreenDialog: true,
builder: (context) => ImageSticker(
file: file, title: title, maxWidth: maxWidth, maxHeight: maxHeight, configs: configs))));
configs.labelDetectFunc = (String path, {double? threshold = 0.7, int? maxResultCount = 5}) async {

// Example about label detection & OCR extraction feature.
// You can use Google ML Kit or TensorflowLite for this purpose
configs.labelDetectFunc = (String path) async {
return <DetectObject>[
DetectObject(label: 'dummy1', confidence: 0.75),
DetectObject(label: 'dummy2', confidence: 0.75),
DetectObject(label: 'dummy3', confidence: 0.75)
];
};
configs.ocrDetectFunc = (String path, {bool? isCloudService = false}) async {
configs.ocrExtractFunc = (String path, {bool? isCloudService = false}) async {
if (isCloudService!) {
return 'Cloud dummy ocr text';
} else {
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.4"
version: "0.1.5"
archive:
dependency: transitive
description:
Expand Down
11 changes: 8 additions & 3 deletions lib/configs/image_picker_configs.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:core';

import 'package:advance_image_picker/models/image_object.dart';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

import '../models/image_object.dart';
import '../widgets/editors/editor_params.dart';

export 'package:camera/camera.dart' show FlashMode;
Expand Down Expand Up @@ -177,7 +177,7 @@ class ImagePickerConfigs {
bool albumPickerModeEnabled = true;

/// Detect labels from image function
Future<List<DetectObject>> Function(String path, {double? threshold, int? maxResultCount})? labelDetectFunc;
Future<List<DetectObject>> Function(String path)? labelDetectFunc;

/// Max count for label detection
int labelDetectMaxCount = 5;
Expand All @@ -186,7 +186,7 @@ class ImagePickerConfigs {
double labelDetectThreshold = 0.7;

/// Detect OCR from image function
Future<String> Function(String path, {bool? isCloudService})? ocrDetectFunc;
Future<String> Function(String path, {bool? isCloudService})? ocrExtractFunc;

/// Camera direction setting.
///
Expand Down Expand Up @@ -459,6 +459,11 @@ class ImagePickerConfigs {
/// Defaults to "saturation".
String get textSaturation => getTranslatedString("image_picker_image_edit_saturation", "saturation");

/// Get localized text for label "image_picker_ocr".
///
/// Defaults to "OCR".
String get textOCR => getTranslatedString("image_picker_ocr", "OCR");

/// Translate string by translateFunc.
String getTranslatedString(String name, String defaultValue) {
return translateFunc.call(name, defaultValue);
Expand Down
3 changes: 1 addition & 2 deletions lib/widgets/picker/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,7 @@ class _ImagePickerState extends State<ImagePicker>

// Run label detector
if (_configs.labelDetectFunc != null && f.recognitions == null) {
f.recognitions = await _configs.labelDetectFunc!(f.modifiedPath,
maxResultCount: _configs.labelDetectMaxCount, threshold: _configs.labelDetectThreshold);
f.recognitions = await _configs.labelDetectFunc!(f.modifiedPath);
if (f.recognitions?.isNotEmpty ?? false) {
f.label = f.recognitions!.first.label;
} else {
Expand Down
53 changes: 27 additions & 26 deletions lib/widgets/viewer/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
),
),
Positioned(top: 0, left: 0, right: 0, child: _buildCurrentImageInfoView(context)),
if (_configs.ocrDetectFunc != null)
if (_configs.ocrExtractFunc != null)
Positioned(bottom: 0, left: 0, right: 0, child: _buildOCRTextView(context)),
],
),
Expand Down Expand Up @@ -407,8 +407,8 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
}

// Get OCR from image
if (_configs.ocrDetectFunc != null) {
final text = await _configs.ocrDetectFunc!.call(retImg.modifiedPath);
if (_configs.ocrExtractFunc != null) {
final text = await _configs.ocrExtractFunc!.call(retImg.modifiedPath);
if (text.isNotEmpty) retImg.ocrText = text;
}
return retImg;
Expand All @@ -432,7 +432,7 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
// Display detected labels
if (image.recognitions != null && image.recognitions!.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
padding: const EdgeInsets.symmetric(vertical: 4),
child: Wrap(
children: image.recognitions!.map((e) {
final isSelected = e.label == image.label;
Expand All @@ -448,10 +448,10 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
},
child: Container(
decoration: BoxDecoration(
border: Border.all(color: isSelected ? Colors.white : Colors.grey, width: 1.0),
border: Border.all(color: isSelected ? Colors.white : Colors.grey, width: 1),
borderRadius: const BorderRadius.all(Radius.circular(10))),
padding: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 4.0),
margin: const EdgeInsets.symmetric(vertical: 2.0, horizontal: 4.0),
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 4),
margin: const EdgeInsets.symmetric(vertical: 2, horizontal: 4),
child: Text("${e.label}:${e.confidence?.toStringAsFixed(2) ?? ""}",
style: TextStyle(color: isSelected ? Colors.white : Colors.grey)),
),
Expand All @@ -468,6 +468,7 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
});
}

/// Build widget for displaying OCR informations
Widget _buildOCRTextView(BuildContext context) {
final image = _images[_currentIndex ?? 0];
return Stack(
Expand All @@ -481,15 +482,15 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
context: context,
builder: (context) {
return Dialog(
insetPadding: const EdgeInsets.symmetric(horizontal: 20.0),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
insetPadding: const EdgeInsets.symmetric(horizontal: 20),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Stack(
fit: StackFit.passthrough,
children: [
Container(
height: MediaQuery.of(context).size.height * 2 / 3,
margin: const EdgeInsets.only(top: 40, bottom: 50),
padding: const EdgeInsets.all(12.0),
padding: const EdgeInsets.all(12),
child: TextField(
maxLines: null,
controller: _textFieldController,
Expand All @@ -499,7 +500,7 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
child: Row(children: [
Text(_configs.textEditText,
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
Expand All @@ -518,17 +519,17 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
left: 0,
right: 0,
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
style: TextButton.styleFrom(
primary: Colors.black87,
minimumSize: const Size(88, 36),
padding: const EdgeInsets.symmetric(horizontal: 16),
backgroundColor: Colors.grey.shade200,
padding: EdgeInsets.zero,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2)),
borderRadius: BorderRadius.all(Radius.circular(30)),
),
),
child: Text(_configs.textClear, style: const TextStyle(color: Colors.red)),
Expand All @@ -541,10 +542,10 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
TextButton(
style: TextButton.styleFrom(
primary: Colors.blue,
minimumSize: const Size(88, 36),
padding: const EdgeInsets.symmetric(horizontal: 16),
backgroundColor: Colors.blue,
padding: EdgeInsets.zero,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2)),
borderRadius: BorderRadius.all(Radius.circular(30)),
),
),
child: Text(_configs.textSave, style: const TextStyle(color: Colors.white)),
Expand All @@ -565,7 +566,7 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
},
child: Container(
color: Colors.black54,
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
constraints: const BoxConstraints(minHeight: 100),
child: Text(
image.ocrText ?? "",
Expand All @@ -582,19 +583,19 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
child: TextButton(
style: TextButton.styleFrom(
primary: Colors.blue,
minimumSize: const Size(88, 36),
padding: const EdgeInsets.symmetric(horizontal: 16),
backgroundColor: Colors.blue,
padding: EdgeInsets.zero,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(2)),
borderRadius: BorderRadius.all(Radius.circular(30)),
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8),
child: Row(children: [
const Text("OCR", style: TextStyle(color: Colors.white)),
Text(_configs.textOCR, style: const TextStyle(color: Colors.white)),
if (_isProcessing)
const Padding(
padding: EdgeInsets.symmetric(horizontal: 4.0),
padding: EdgeInsets.symmetric(horizontal: 4),
child: CupertinoActivityIndicator(),
)
]),
Expand All @@ -605,7 +606,7 @@ class _ImageViewerState extends State<ImageViewer> with PortraitStatefulModeMixi
_isProcessing = true;
});

final text = await _configs.ocrDetectFunc!.call(image.modifiedPath);
final text = await _configs.ocrExtractFunc!.call(image.modifiedPath, isCloudService: true);
setState(() {
_isProcessing = false;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: advance_image_picker
description: Flutter plugin in pure Dart code for selecting/editing multiple images from the Android/iOS image library and taking new pictures with the camera in the same view.
version: 0.1.4
version: 0.1.5
homepage: https://freemar.vn
repository: https://github.com/weta-vn/advance_image_picker

Expand Down

0 comments on commit e2d5a52

Please sign in to comment.