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

'List<dynamic>' is not a subtype of type 'Map<dynamic, dynamic>' #90

Open
eimantas1998 opened this issue Dec 9, 2019 · 3 comments
Open

Comments

@eimantas1998
Copy link

eimantas1998 commented Dec 9, 2019

Hello, when i try to scan the first time everything works as expected, but when i try to do it again i get this error on a loop.

I/flutter (13206): type 'List<dynamic>' is not a subtype of type 'Map<dynamic, dynamic>' in type cast, #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:56)
I/flutter (13206): <asynchronous suspension>
I/flutter (13206): #1      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:349:48)
I/flutter (13206): #2      TextRecognizer.processImage (package:firebase_ml_vision/src/text_recognizer.dart:40:38)
I/flutter (13206): #3      _detect (package:flutter_camera_ml_vision/utils.dart:43:25)
I/flutter (13206): #4      CameraMlVisionState._processImage (package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart:285:19)
I/flutter (13206): #5      CameraController.startImageStream.<anonymous closure> (package:camera/camera.dart:411:20)
I/flutter (13206): #6      _rootRunUnary (dart:async/zone.dart:1134:38)
I/flutter (13206): #7      _CustomZone.runUnary (dart:async/zone.dart:1031:19)
I/flutter (13206): #8      _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
I/flutter (13206): #9      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:338:11)
I/flutter (13206): #10     _DelayedData.perform (dart:async/stream_impl.dart:593:14)
I/flutter (13206): #11     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:709:11)
I/flutter (13206): #12     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:669:7)
I/flutter (13206): #13     _rootRun (dart:async/zone.dart:1122:38)
I/flutter (13206): #14     _CustomZone.run (dart:async/zone.dart:1023:19)
I/flutter (13206): #15     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
I/flutter (13206): #16     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
I/flutter (13206): #17     _rootRun (dart:async/zone.dart:1126:13)
I/flutter (13206): #18     _CustomZone.run (dart:async/zone.dart:1023:19)
I/flutter (13206): #19     _CustomZone.runGuarded (dart:async/zone.dart:925:7)
I/flutter (13206): #20     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
I/flutter (13206): #21     _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
I/flutter (13206): #22     _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
@eimantas1998 eimantas1998 changed the title 'List<dynamic>' is not a subtype of type 'Map<dynamic, dynamic>' i get this error if i scan once and try to scan again. 'List<dynamic>' is not a subtype of type 'Map<dynamic, dynamic>' Dec 9, 2019
@jaumard
Copy link
Collaborator

jaumard commented Dec 9, 2019

Hello,

Would be nice to have a reproducible code we can copy / paste to reproduce this issue. I use it and don't have this problem, so maybe a detector I didn't use yet or a config issue.

Thanks

@eimantas1998
Copy link
Author

icon: Icon(Icons.photo_camera),
onPressed: () async {
String result =
await Navigator.of(context).push(
MaterialPageRoute(
builder: (c) {
return ScanPage(
regPattern: pattern);
},
),
);
if ((result ?? '').isNotEmpty) {
_controller.text = result;
}

class ScanPage extends StatefulWidget {
final String regPattern;

ScanPage({@required this.regPattern});

@OverRide
_ScanPageState createState() => _ScanPageState();
}

class _ScanPageState extends State {
TextRecognizer textRecognizer;

bool resultSent = false;

@OverRide
void initState() {
super.initState();
textRecognizer = FirebaseVision.instance.textRecognizer();
}

@OverRide
void dispose() {
textRecognizer.close();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Scanner'),
),
body: SafeArea(
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: CameraMlVision(
resolution: ResolutionPreset.medium,
detector: textRecognizer.processImage,
onResult: (VisionText visionText) {
String matchedText = findMatch(visionText?.blocks ?? []);
if (matchedText.isNotEmpty && mounted && !resultSent) {
setState(() {
resultSent = true;
});
Navigator.of(context).pop(matchedText);
}
},
))),
);
}

String findMatch(List textBlocks) {
RegExp exp = new RegExp(widget.regPattern);

String wholeText = "";
for (TextBlock block in textBlocks) {
  block.lines.forEach((ln) => wholeText += "/" + ln.text);
}

if (exp.hasMatch(wholeText)) {
  return exp.stringMatch(wholeText);
} else {
  return '';
}

}
}

@eimantas1998
Copy link
Author

To reproduce the issue try to get the result, or press back button, then try to scan again. After that it just starts looping the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants