Please help, after flutter update, (The name 'MenuItem' is defined in the libraries) in visual studio

Viewed 697

When I updated Flutter, I had this problem in more than one project.

the error message:

The name 'MenuItem' is defined in the libraries 'package:flutter/src/widgets/platform_menu_bar.dart' and 'package:fuodz/widgets/menu_item.dart'.

Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.

enter image description here

2 Answers

Try use as prefix

import "package:fuodz/widgets/menu_item.dart" as item;

//code widget

VStack[
  item.MenuItem();
]

or, change class name MenuItem in widgets/menu_item.dart to different name

import 'package:flutter/material.dart'; import 'package:Yourprojectname/model/menu_item.dart' as item;

class MenuItems{
static List<item.MenuItem> itemFirst = [ itemShare, ]; static List<item.MenuItem> itemSecond = [ itemSignOut, ]; static const itemShare = item.MenuItem( text: 'Alarm', icon: Icons.alarm, ); static const itemSignOut = item.MenuItem( text: 'Sign Out', icon: Icons.logout, ); }

Related