Isolate

ReceivePort

// create one 
ReceivePort receivePort = ReceivePort();
// receive messages via
await for(var message in receivePort) {
    print(message);
}

Spawn an Isolate

// the isolate main function must be static
// the second arg is the arg for that main function
// you can send a object list including the send port
Isolate.spawn(isolateMain, receivePort.sendPort);

Send Port

// send a message
// note the send port was created when yo made the receive port
sendPort.send(receivePort.sendPort);

Example

import 'dart:isolate';

void main() async {
  
  ReceivePort receivePort = ReceivePort();
  Isolate.spawn(isolateMain, receivePort.sendPort);
  SendPort isolateSendPort = await receivePort.first;

  isolateSendPort.send("hey!");
  isolateSendPort.send("how is it going");
  
}

void isolateMain(SendPort sendPort) async {
  ReceivePort receivePort = ReceivePort();
  sendPort.send(receivePort.sendPort);

  await for(var message in receivePort) {
    print(message);
  }
  
}