2
  static getMaxId(SendPort sendPort) async {
    ApiService apiService = ApiService();
    var maxId = await apiService.getMId("1");
    sendPort.send(getFeedData(maxId));
  }

  static getFeedData(dynamic maxId) async {
    ApiService apiService = ApiService();
    List<MarketfeedsModel>? marketFeedsNew =
        await apiService.getfH("1", maxId.toString());
    return marketFeedsNew;
  }

  var receivePort = ReceivePort();
  await Isolate.spawn(getMaxId, receivePort.sendPort);

  receivePort.listen((message) {
   print("data " + message.toString());
  });

Future<dynamic> getMId(String tabletype) async {
    final api = '$baseUrl/api/Feeds/getMaxId';
    Map<String, dynamic> queryParameters = {'tableid': tabletype};
    try {
      Response response;
      Dio dio = Dio();
      await apiClientToken().then((value) => {dio = value});
      response = await dio.get(api, queryParameters: queryParameters);
      final body = response.data;
      if (response.statusCode == 200) {
        if (body != null) {
          return body['message'];
        } else {
          return null;
        }
      } else {
        print(response.data);
        return null;
      }
    } on DioError catch (e) {
      // setError(e, context);
    } catch (e) {
      print(e);
    }
    return null;
  }

I'm trying to implement a Isolate in my code. everything is working until Isolate used.after using Isolate unable to get data from api and its showing an error and getting null response from api. I don't know why im always getting bad state BackgroundIsolateBinaryMessenger error.

problem is here

static getMaxId(SendPort sendPort) async {
    ApiService apiService = ApiService();
    var maxId = await apiService.getMId("1");
    sendPort.send(getFeedData(maxId));
  }

always getting maxId null when using sendport if sendport is not using doing normal code then getting a maxId

Tintin V
  • 23
  • 4

0 Answers0