Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initial popup illustration customization iOS #42

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

murilofank
Copy link

Fix on iOS side.
There was a issue when trying to customize the document illustration displayed on the initial popup, on the document capture flow.

Fix evidences

SDK default configuration:

default-illustration.MP4

With Customization:

custom-illustration.MP4

How to test

  1. First of all, install the pubspec in the main project and in the example app.
// in the root folder
flutter pub get

//after that
cd example
flutter pub get
  1. Next, install the pods.
// in the root folder
cd example/ios
pod install
  1. Open the Runner.xcworkspace, located inside Flutter/example/ios.
  2. Add the image file to the app Assets.
  3. Implement the customization on test app /example/lib/main.dart, you can replace the code with this:
import 'package:document_detector/caf_stage.dart';
import 'package:document_detector/ios/step_customization.dart';
import 'package:document_detector/document_detector_step.dart';
import 'package:document_detector/document_type.dart';
import 'package:document_detector/result/document_detector_failure.dart';
import 'package:document_detector/result/document_detector_result.dart';
import 'package:document_detector/result/document_detector_success.dart';
import 'package:flutter/material.dart';

import 'package:document_detector/document_detector.dart';
import 'package:flutter/services.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _result = "";
  String _description = "";

// You will need to give a valid mobileToken here for .Beta environment
  String mobileToken = "INSERT YOUR MOBILETOKEN HERE";

  @override
  void initState() {
    super.initState();
    requestPermissions();
  }

  void requestPermissions() async {
    await [
      Permission.camera,
    ].request();
  }

// Here is the configuration to customize the illustration displayed in the initial popup
// replace the parameter with your image file name.
// this object is passed on as a parameter on line 101
  DocumentDetectorStepCustomizationIos stepCustomizationIos =
      DocumentDetectorStepCustomizationIos(
          illustration: 'YOUR IMAGE FILE NAME');

  void startDocumentDetector(List<DocumentDetectorStep> documentSteps) async {
    String result = "";
    String description = "";

    DocumentDetector documentDetector =
        new DocumentDetector(mobileToken: mobileToken);

    documentDetector.setStage(CafStage.BETA);
    documentDetector.setDocumentFlow(documentSteps);

    try {
      DocumentDetectorResult documentDetectorResult =
          await documentDetector.start();

      if (documentDetectorResult is DocumentDetectorSuccess) {
        result = "Success!";
      } else if (documentDetectorResult is DocumentDetectorFailure) {
        result = "Failure!";
      } else {
        result = "Closed!";
      }
    } on PlatformException catch (err) {
      result = "Excpection!";
      description = err.message!;
    }

    if (!mounted) return;

    setState(() {
      _result = result;
      _description = description;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: const Text('DocumentDetector plugin example'),
            ),
            body: Container(
                margin: const EdgeInsets.all(20.0),
                child: Column(
                  children: [
                    Row(
                      children: [
                        ElevatedButton(
                          child: Text('Start DocumentDetector for CNH'),
                          onPressed: () async {
                            startDocumentDetector([
                              new DocumentDetectorStep(
                                  ios: stepCustomizationIos,
                                  document: DocumentType.CNH_FRONT)
                            ]);
                          },
                        )
                      ],
                    ),
                    Row(
                      children: [
                        Container(
                            margin: EdgeInsets.only(top: 10.0),
                            child: Text("Result: $_result"))
                      ],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Expanded(
                          child: Text("Description:\n$_description",
                              overflow: TextOverflow.clip),
                        )
                      ],
                    ),
                  ],
                ))));
  }
}
  1. Run the test app.

@murilofank murilofank added bug Something isn't working team: sdk SDK Team labels Apr 5, 2024
@murilofank murilofank self-assigned this Apr 5, 2024
Copy link

@marcuscaf marcuscaf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@murilofank murilofank merged commit 6dd3441 into document-detector Apr 8, 2024
@murilofank murilofank deleted the fix/popup-customization-ios branch April 8, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working team: sdk SDK Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants