Santos-Enoque/flutter-web-dashboard-template

MenuController Error

Opened this issue · 4 comments

Expected a value of type MenuController' (in package:flutter_web_dashboard/controllers/menu_controller.dart), but got one of type 'MenuController' (in package:flutter/src/material/menu_anchor.dart)

See also: https://flutter.dev/docs/testing/errors

Screenshot 2023-02-21 at 3 33 06 PM

can anyone help me with this issue?

i also had the same issue. I was able to solve it by doing this.
There is a default Class MenuController that get's imported different from the one he created in this tutorial, so what i did was to rename the MenuController Class he created to CustomMenuController:



class CustomMenuController extends GetxController {
  static CustomMenuController instance = Get.find();
  var activeItem = overviewPageDisplayName.obs;

  var hoverItem = "".obs;

  changeActiveItemTo(String itemName) {
    activeItem.value = itemName;
  }

  onHover(String itemName) {
    if (!isActive(itemName)) hoverItem.value = itemName;
  }

  isHovering(String itemName) => hoverItem.value == itemName;

  isActive(String itemName) => activeItem.value == itemName;

  Widget returnIconFor(String itemName) {
    switch (itemName) {
      case overviewPageDisplayName:
        return _customIcon(Icons.trending_up, itemName);
      case driversPageDisplayName:
        return _customIcon(Icons.drive_eta, itemName);
      case clientsPageDisplayName:
        return _customIcon(Icons.people_alt_outlined, itemName);
      case authenticationPageDisplayName:
        return _customIcon(Icons.exit_to_app, itemName);
      default:
        return _customIcon(Icons.exit_to_app, itemName);
    }
  }

  Widget _customIcon(IconData icon, String itemName) {
    if (isActive(itemName)) return Icon(icon, size: 22, color: dark);

    return Icon(
      icon,
      color: isHovering(itemName) ? dark : lightGrey,
    );
  }
}


now in your main.dart, update to this:

void main() {
  Get.put(CustomMenuController());
  runApp(const MyApp());
}

Then ensure where you created an instance of MenuController is changed to CustomMenuController, this should help.

@GreatGodson Thanks for your help. In my case, it solves the compiling errors but the debug mode runs and displays a white screen. At least that is a plus. I am getting close to getting this running.

Also, you forgot to mention looking in the controller.dart file.

import 'package:flutter_web_dashboard/controllers/menu_controller.dart';
import 'package:flutter_web_dashboard/controllers/navigation_controller.dart';

CustomMenuController menuController = CustomMenuController.instance;
NavigationController navigationController = NavigationController.instance;

Update: I was able to get it running. I ended up looking into a resolved issue and found the answer. I got it running.

@jiraheta I'm glad you were able to get it running.

i am having the same issue and after following your steps, it worked like magic. Why did we have to change it to "CustomMenuController"?