4

I created a method below to loop through my list because I don't want to write again and again of these few lines but the parameter I pass to the Text widget and also value argument are error and it said Invalid constant value. How can I achieve this? I'm new to flutter. Please help me.

  PopupMenuItem _createMenuItems(final String a) {
    return const PopupMenuItem(
      value: a,
      child: Text(a),
    );
  }
Pro
  • 2,843
  • 1
  • 18
  • 29
Sokheang Khun
  • 137
  • 1
  • 2
  • 11

1 Answers1

14

Have your tried simply returning PopupMenuItem without const modifier like below?

PopupMenuItem _createMenuItems(final String a) {
   return PopupMenuItem(
     value: a,
     child: Text(a),
   );
}
Pro
  • 2,843
  • 1
  • 18
  • 29