Question

In my Dart app I need to have a const string variable defined like so:

library myapp;
part "Lookups.dart";

const String MY_SERVER_URL_PATTERN = "http://%s/" + Lookups.APP_NAME;

// ...more code

Where Lookups.dart is:

part of myapp;

abstract class Lookups {
    static const String APP_NAME = "myapp";
}

But I'm getting a compiler error on the MY_SERVER_URL_PATTERN declaration:

An expression of type 'num' was expected.

Why am I getting this, and what can I do to fix it?

Was it helpful?

Solution

This seems to be a bug with the + operator.
If you rewrite it like

const String MY_SERVER_URL_PATTERN = "http://%s/${Lookups.APP_NAME}";

it works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top