首页 > 解决方案 > Flutter_Translate:方法调用不是常量表达式

问题描述

如何解决这个问题。非常感谢。

import 'package:flutter_translate/flutter_translate.dart';

class TabViewerPopupMenuActions {
  static const String NEW_TAB = translate(
      'options.new_tab'); //ERROR: Const variables must be initialized with a constant value.

  static const List<String> choices = <String>[
    NEW_TAB
  ];
}

我尝试删除 const

class TabViewerPopupMenuActions {
  static String NEW_TAB = translate(
      'options.new_tab'); 
  static List<String> choices = <String>[
    NEW_TAB
  ];
}

但开关盒错误

 switch (choice) {
   case TabViewerPopupMenuActions.NEW_TAB

错误:案例表达式必须是常量

标签: flutter

解决方案


推荐阅读