문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top