createMenu static method

List<Widget> createMenu({
  1. required double menuPositionX,
  2. required double menuPositionY,
  3. required Color menuColor,
  4. required double radius,
  5. required List<Item> menuItems,
  6. required double itemSize,
  7. required Color itemColor,
  8. required TextStyle titleStyle,
  9. required Border border,
  10. required Border borderCentralMenu,
  11. required double animationOffset,
  12. OrbitMenuAnimationType orbitMenuAnimationType = OrbitMenuAnimationType.rotating,
  13. double itemOffsetPercentage = 0.0,
  14. Widget? myWidget,
})

Implementation

static List<Widget> createMenu({
  required double menuPositionX,
  required double menuPositionY,
  required Color menuColor,
  required double radius,
  required List<Item> menuItems,
  required double itemSize,
  required Color itemColor,
  required TextStyle titleStyle,
  required Border border,
  required Border borderCentralMenu,
  required double animationOffset,
  OrbitMenuAnimationType orbitMenuAnimationType =
      OrbitMenuAnimationType.rotating,
  double itemOffsetPercentage = 0.0,
  Widget? myWidget,
}) {
  int numberOfElements = menuItems.length;
  double adjustedRadius = radius * (1 + itemOffsetPercentage);
  List<Point> points =
      getCircularPosition(numberOfElements, adjustedRadius, animationOffset);
  List<Widget> menuWidgets = [];

  /// Add the central menu
  menuWidgets.add(
    Positioned(
        left: menuPositionX - radius,
        top: menuPositionY - radius,
        child: BigCircle(
          size: radius * 2,
          color: menuColor,
          border: borderCentralMenu,
        )),
  );

  /// Add the items
  switch (orbitMenuAnimationType) {
    case OrbitMenuAnimationType.orbit:
      for (int i = 0; i < numberOfElements; i++) {
        double waveOffset =
            sin(animationOffset + (i / numberOfElements) * 2 * pi) * 100;
        menuWidgets.add(
          Positioned(
              left: menuPositionX + points[i].x - (itemSize / 2) + waveOffset,
              top: menuPositionY + points[i].y - (itemSize / 2) + waveOffset,
              child: myWidget != null
                  ? GestureDetector(
                    onTap: menuItems[i].onPressed,
                    child: SizedBox(
                        width: itemSize,
                        height: itemSize,
                        child: myWidget,
                      ),
                  )
                  : menuItems[i].image.isNotEmpty ? GestureDetector(
                    onTap: menuItems[i].onPressed,
                    child: SizedBox(
                      width: itemSize,
                      height: itemSize,
                      child: Image(image: AssetImage(menuItems[i].image),),
                    ),
                  ):CircleItem(
                      size: itemSize,
                      color: itemColor,
                      titleStyle: titleStyle,
                      border: border,
                      borderWidth: 1,
                      title: menuItems[i].title,
                      onTap: menuItems[i].onPressed,
                    )),
        );
      }
      break;
    default:
      for (int i = 0; i < numberOfElements; i++) {
        menuWidgets.add(
          Positioned(
              left: menuPositionX + points[i].x - (itemSize / 2),
              top: menuPositionY + points[i].y - (itemSize / 2),
              child: myWidget != null
                  ? GestureDetector(
                    onTap: menuItems[i].onPressed,
                    child: SizedBox(
                        width: itemSize,
                        height: itemSize,
                        child: myWidget,
                      ),
                  )
                  : menuItems[i].image.isNotEmpty ? GestureDetector(
                    onTap: menuItems[i].onPressed,
                    child: SizedBox(
                      width: itemSize,
                      height: itemSize,
                      child: Image(image: AssetImage(menuItems[i].image),),
                    ),
                  ): CircleItem(
                      size: itemSize,
                      color: itemColor,
                      titleStyle: titleStyle,
                      border: border,
                      borderWidth: 1,
                      title: menuItems[i].title,
                      onTap: menuItems[i].onPressed,
                    )),
        );
      }
      break;
  }
  return menuWidgets;
}