title: Invalid argument(s): Illegal argument in isolate message in flutter
body: <p>I am trying to use flutter isolate,But it gives me error as,I am calling APIs from back end and passing it to my isolate function using compute:
  [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '': static.)
  Can anyone help me to solve the issue?</p>
  <pre><code>class PhoneContactList extends StatefulWidget {
    @override
    _PhoneContactListState createState() =&gt; _PhoneContactListState();
  }
  
  class _PhoneContactListState extends State&lt;PhoneContactList&gt; {
    //ContractSyncRX contractSyncRX = ContractSyncRX();
  
    void initState() {
      getContacts();
      super.initState();
    }
  
  
    @override
    void dispose() {
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Column(
          children: &lt;Widget&gt;[
            CustomAppBar(
              color: CustomColor.themeColor,
              leftBackButton: true,
              leftBackButtonColor: Colors.white,
              titleText: &quot;Contacts&quot;,
              titleTextColor: Colors.white,
              leftBackButtonFunction: () {
                pop(context: context);
              },
            ),
            Expanded(
              child: FutureBuilder&lt;Iterable&lt;Contact&gt;&gt;(
                future: getContacts(),
                builder: (context, snapshot) {
                  return snapshot.hasData
                      ? contractListView(snapshot.data)
                      : loadingIndicatorCircle(
                          context: context,
                          color: CustomColor.themeColor,
                          size: bCon.hbSize(10),
                        );
                },
              ),
            )
          ],
        ),
      );
    }
  
    ListView contractListView(Iterable&lt;Contact&gt; contacts) {
      return ListView(
        children: &lt;Widget&gt;[
          ...contacts.map(
            (c) {
              return c.phones.length &gt; 0
                  ? Container(
                      padding: EdgeInsets.symmetric(horizontal: bCon.hbSize(5)),
                      child: Column(
                        children: &lt;Widget&gt;[
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: &lt;Widget&gt;[
                              Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: &lt;Widget&gt;[
                                  Container(
                                    margin: EdgeInsets.only(
                                      right: bCon.hbSize(2),
                                    ),
                                    width: bCon.hbSize(22),
                                    height: bCon.hbSize(22),
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.all(
                                        Radius.circular(CustomRadius.fullRadius),
                                      ),
                                      image: Platform.isIOS
                                          ? DecorationImage(
                                              image: c.avatar != null
                                                  ? MemoryImage(c.avatar)
                                                  : AssetImage(
                                                      CustomImages.noImage),
                                              fit: BoxFit.cover,
                                            )
                                          : DecorationImage(
                                              image: c.avatar.isNotEmpty
                                                  ? MemoryImage(c.avatar)
                                                  : AssetImage(
                                                      CustomImages.noImage),
                                              fit: BoxFit.cover,
                                            ),
                                    ),
                                  ),
                                  //
                                  SizedBox(
                                    width: bCon.hbSize(3),
                                  ),
                                  Column(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: &lt;Widget&gt;[
                                      CustomText(
                                        text: c.displayName,
                                        fontSize: sCon.scaledSize(14),
                                      ),
                                      SizedBox(
                                        height: bCon.hbSize(2),
                                      ),
                                      CustomText(
                                        text: c.phones.length &gt; 0
                                            ? c.phones.first.value
                                            : &quot;No number&quot;,
                                        fontSize: sCon.scaledSize(14),
                                      ),
                                      UdGapY(
                                        value: UdDesign.pixels(8),
                                      ),
                                      UdBasicButton(
                                        height: UdDesign.pixels(30),
                                        width: UdDesign.pixels(119),
                                        borderRadius: UdDesign.pixels(15),
                                        titleFontSize: UdDesign.fontSize(14),
                                        titleFontWeight: FontWeight.w400,
                                        title: &quot;Refer Now&quot;,
                                        backgroundColor: CustomColor.themeColor,
                                      )
                                    ],
                                  )
                                ],
                              ),
  
                              //
                            ],
                          ),
                          SizedBox(
                            height: bCon.hbSize(8),
                          ),
                        ],
                      ),
                    )
                  : SizedBox.shrink();
            },
          )
        ],
      );
    }
  }
  
  Future&lt;Iterable&lt;Contact&gt;&gt; getContacts() async {
    Iterable&lt;Contact&gt; contacts = await ContactsService.getContacts();
    compute(syncContracts, contacts);
    return contacts;
  }
  
  syncContracts(Iterable&lt;Contact&gt; retrivedContacts) async {
    ContractSyncRX contractSyncRX = ContractSyncRX();
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var contractID = prefs.getString(PreferenceKey.contactId);
    retrivedContacts.forEach((element) {
      Map&lt;String, dynamic&gt; contractPayload;
      contractPayload = {
        &quot;contactId&quot;: contractID,
        &quot;contacts&quot;: [
          {
            &quot;firstName&quot;: element.displayName,
            &quot;lastName&quot;: null,
            &quot;mobile&quot;: element.phones.isNotEmpty
                ? element.phones.elementAt(0).value
                : null,
            &quot;email&quot;: element.emails.isNotEmpty
                ? element.emails.elementAt(0).value
                : null,
          }
        ],
      };
      contractSyncRX.syncContractData(contractPayload);
    });
    contractSyncRX.clean();
    contractSyncRX.dispose();
  }
  </code></pre>