2017-10-20 68 views
0

我怎樣才能在dart中傳遞這個常量?端口在飛鏢的js地圖

const CHANNEL_STATES = { 
    closed: "closed", 
    errored: "errored", 
    joined: "joined", 
    joining: "joining", 
    leaving: "leaving", 
} 

我需要它來調用前。 CHANNEL_STATES.closed 感謝

回答

2

你可以做到這一點與類和常量靜態成員:

class CHANNEL_STATES { 
    static const String closed = "closed"; 
    static const String errored = "errored"; 
    static const String joined = "joined"; 
    static const String joining = "joining"; 
    static const String leaving = "leaving"; 
} 
+0

但使用此模式,我不能在選擇的情況下使用它們 –

+0

爲什麼不應該這樣工作? – rinukkusu

0

我不知道你問的什麼,但在DART類似的地圖常數是:

const channelStates = const { 
    "closed": "closed", 
    "errored": "errored", 
    "joined": "joined", 
    "joining": "joining", 
    "leaving": "leaving", 
}; 

鏢地圖文字可以使用任何對象作爲重點,所以使用字符串作爲密鑰,您需要引用它。你不能像JavaScript中那樣使用一個沒有引號的標識符。