Actually I am building a card reader application in which data is coming from the ML model and get stored in the mycontrollers function. But on using ContactsService.addContact(contact); I am getting error. Although contact is saved in the app but not in the phone's contact list.
code:
void saveContactInPhone() {
try {
print("saving Conatct");
Contact contact = Contact();
print("fi");
contact.displayName = myController1.text ;
contact.phones = [Item(label: "mobile", value: myController4.text)];
// contact.emails = [Item(label: "email", value: myController3.text)];
contact.company = myController2.text;
print("fi2");
ContactsService.addContact(contact);
print("object");
} catch (e) {
print(e);
}
}
Error:
I/flutter ( 1615): form init
I/flutter ( 1615): /data/user/0/com.example.camera_app/app_flutter/2020-05-29 23:35:12.398628.png I/flutter ( 1615): Going Image I/flutter ( 1615): 404 I/flutter ( 1615): Image Send I/flutter ( 1615): form come listenForSinglecontact I/flutter ( 1615): saving I/flutter ( 1615): fi I/flutter ( 1615): fi2 I/flutter ( 1615): object E/flutter ( 1615): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FormatException: Invalid envelope E/flutter ( 1615): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:571:7) E/flutter ( 1615): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18) E/flutter ( 1615): E/flutter ( 1615): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12) E/flutter ( 1615): #3 ContactsService.addContact (package:contacts_service/contacts_service.dart:83:16) E/flutter ( 1615): #4 _FormState.saveData (package:camera_app/screens/form.dart:249:23) E/flutter ( 1615): #5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:779:19) E/flutter ( 1615): #6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:862:36) E/flutter ( 1615): #7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter ( 1615): #8 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:504:11) E/flutter ( 1615): #9 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:282:5) E/flutter ( 1615): #10 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:217:7) E/flutter ( 1615): #11 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:475:9) E/flutter ( 1615): #12 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12) E/flutter ( 1615): #13 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:122:9) E/flutter ( 1615): #14 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8) E/flutter ( 1615): #15 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18) E/flutter ( 1615): #16 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7) E/flutter ( 1615): #17 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) E/flutter ( 1615): #18 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter ( 1615): #19 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter ( 1615): #20 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter ( 1615): #21 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)