Santos-Enoque / flutter-web-dashboard-template

270 stars 203 forks source link

Cannot read the properties of Null (reading isHovering) #12

Open Shayanali4075 opened 3 years ago

Shayanali4075 commented 3 years ago

``Hello Santos Enoque, hope you are doing well and thank you so much for such a nice flutter course for free actually i am following your flutter crash course and i don't no where i go wrong, right now i am getting an error

Cannot read the properties of Null (reading isHovering)

here is my code

HorizontalMenuItem:

 `import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'package:web/constants/style.dart';
 import 'package:web/controller/menu_controller.dart';

 import 'custom_text.dart';

 class HorizontalMenuItem extends StatelessWidget {
   final String itemName;
   final Function onTap;
   const HorizontalMenuItem({Key key, this.itemName, this.onTap})
       : super(key: key);

  @override
  Widget build(BuildContext context) {
    double _width = MediaQuery.of(context).size.width;

return InkWell(
    onTap: onTap,
    onHover: (value) {
      value
          ? MenuController.instance.onHover(itemName)
          : MenuController.instance.onHover("not hovering");
    },
    child: Obx(() => Container(
          color: MenuController.instance.isHovering(itemName)
              ? lightgrey.withOpacity(.1)
              : Colors.transparent,
          child: Row(
            children: [
              Visibility(
                visible: MenuController.instance.isHovering(itemName) ||
                    MenuController.instance.isActive(itemName),
                maintainSize: true,
                maintainAnimation: true,
                maintainState: true,
                child: Container(
                  width: 6,
                  height: 40,
                  color: dark,
                ),
              ),
              SizedBox(width: _width / 88),
              Padding(
                padding: const EdgeInsets.all(16),
                child: MenuController.instance.returnIconFor(itemName),
              ),
              if (!MenuController.instance.isActive(itemName))
                Flexible(
                    child: CustomText(
                  text: itemName,
                  color: MenuController.instance.isHovering(itemName)
                      ? dark
                      : lightgrey,
                ))
              else
                Flexible(
                    child: CustomText(
                  text: itemName,
                  color: dark,
                  size: 18,
                  weight: FontWeight.bold,
                ))
            ],
          ),
        ))); }}`

Menu_Controller:

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:web/constants/style.dart';
import 'package:web/routing/Routes.dart';

class MenuController extends GetxController {
  static MenuController instance = Get.find();
  var activeItem = OverViewPageRoute.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 OverViewPageRoute:
        return _customIcon(Icons.trending_up, itemName);
      case DriverPageRoute:
        return _customIcon(Icons.drive_eta, itemName);
      case ClientsPageRoute:
        return _customIcon(Icons.people_alt_outlined, itemName);
      case AuthenticationPageRoute:
        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,
    );
  }
}

flutter error

Kindly look into this code and please highlight the MISTAKES. Should be thankful to you.