Could not start Observatory HTTP server - dart

Here is my dart code
import 'package:tpdart/tpdart.dart' as tpdart;
void main(List<String> arguments) {
print('Hello world: ${tpdart.calculate()}!');
}
But when I type F5, I get this issue:
I tried to looking in Google but I didn't see any solution.

Related

Dart How to load file in runtime

I'm writing a discord bot using the nyxx library and want use dynamic file import for load command info and handler. But, after 5 hours of searching with Google, I didn't find anything to help me do that.
In Node.js, I can use require() or import() for it: Does the dart have something like that?
A small code snippet, showing what I want do:
this.commands = new Collection();
fs.readdirSync('./src/commands').filter(( f ) => f.endsWith( '.js' )).forEach((file) => {
const command = require(`../commands/${file}`);
this.commands.set( command.info.name, command );
});
Is it possible to do this or not? (I don't like to write many imports for commands and register it in lib.)
You can in theory use Isolate.spawnUri to spawn external Dart programs to run in its own Isolate instances that can then communicate back to the main program using SendPort.
It does, however, come with some limitations. E.g. it is very limited what types of objects you can send though SendPort when using spawnUri since the two programs does not share any type information (compared to Isolate.spawn which does allow you to send your own custom types). The documented types you can send can be found here:
Null
bool
int
double
String
List or Map (whose elements are any of these)
TransferableTypedData
SendPort
Capability
https://api.dart.dev/stable/2.17.6/dart-isolate/SendPort/send.html
But it does allow us to make some kind of protocol and you can create some helper class around this to handle the conversion of a known object structure into e.g. Map<String, Object>.
A small example that works with Dart VM would be:
Your command implemented as: command.dart
import 'dart:isolate';
void main(List<String> arguments, Map<String, Object> message) {
final userName = message['username'] as String;
final sendPort = message['port'] as SendPort;
sendPort.send('Hi $userName. '
'You got a message from my external command program!');
}
Your server that calls your command: server.dart
import 'dart:isolate';
void main() {
final recievePort = ReceivePort();
recievePort.listen((message) {
print('Got the following message: $message');
recievePort.close();
});
Isolate.spawnUri(Uri.file('command.dart'), [], {
'username': 'julemand101',
'port': recievePort.sendPort,
});
}
If running this with: dart server.dart you, hopefully, get:
Got the following message: Hi julemand101. You got a message from my external command program!
If you want to compile your application, you can do so by doing the following. You need to compile the command.dart, since a compiled Dart program does not understand how to read Dart code.
dart compile exe server.dart
dart compile aot-snapshot command.dart
You should here change Uri.file('command.dart') to Uri.file('command.aot') since the file-extension for aot-snapshot are .aot.
If everything works, you should be able to see:
> .\server.exe
Got the following message: Hi julemand101. You got a message from my external command program!

Flutter testing find.pageBack() on IOS doesn't work

I use flutter_driver and gherkin for test my app.
I want to use action to page back (find.pageBack()) but the Flutter Driver doesn't found the button on IOS emulator. On Android, it's ok.
I don't have any error just a timeout : TimeoutException after 0:00:10.000000: Future not completed
import 'package:flutter_driver/flutter_driver.dart';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import 'package:gherkin/gherkin.dart';
class NavValidation extends ThenWithWorld<FlutterWorld> {
#override
Future<void> executeStep() async {
await FlutterDriverUtils.getText(world.driver, find.text('sagittarius / yesterday'));
await FlutterDriverUtils.tap(world.driver, find.pageBack());
}
RegExp get pattern => RegExp(r"user should land on result screen");
}

Micronoaut ServerStartupEvent callback not called in startup?

Just started to experiment with MN M3. Created a minimal Groovy service with the following code:
package test2
import groovy.transform.CompileStatic
import io.micronaut.context.event.ApplicationEventListener
import io.micronaut.runtime.Micronaut
import io.micronaut.runtime.server.event.ServerStartupEvent
#Singleton
#CompileStatic
class Application implements ApplicationEventListener<ServerStartupEvent> {
static void main(String[] args) {
println "Start"
Micronaut.run(Application.class)
}
#Override
void onApplicationEvent(ServerStartupEvent event) {
println "Boo!"
}
}
I get the "Start" but the startup event callback is never called:
Start
10:35:54.066 [main] INFO io.micronaut.runtime.Micronaut - Startup
completed in 897ms. Server Running: http://localhost:32034
I think this is the appropriate way to deal with initialization in MN?
Turns out Groovy has its own #Singleton annotation which was used by default. You need to import:
import javax.inject.Singleton
Might be a good idea to emphasize this somewhere in the docs.

Is it possible to detect 'dead' completers in Dart?

In the Dart vm the following code will not hang - the VM will exit:
import 'dart:async';
Future<Null> main() async {
await neverCompletes();
print('Will not run');
}
Future<Null> neverCompletes() => new Completer<Null>().future;
Is there any way to detect this situation? It would be easier to investigate if the VM hangs waiting for the Future. Any flags I can pass?

New build options for web ui on Dart 1.0

I have a Project using still web-ui, and trying to run it on Dart 1.0 but I get an error in this line of code:
build(new Options().arguments, ['web/lista_orden_p.html']);
What is the new syntax for this?
The Options class has been depreciated and removed from the dart:io library. the main() function now takes a List of strings as the arguments as such:
// build.dart
void main(List<String> args) {
build(args, ['web/lista_orden_p.html']);
}

Resources