makeStyleMoreiOS function

ButtonStyle makeStyleMoreiOS(
  1. ButtonStyle style
)

Implementation

ButtonStyle makeStyleMoreiOS(ButtonStyle style) {
  final currentForegroundColor = style.foregroundColor!.resolve({})!;
  final currentForegroundResolver = style.foregroundColor!.resolve;

  final currentBackgroundColor = style.backgroundColor!.resolve({})!;
  final currentBackgroundResolver = style.backgroundColor!.resolve;

  final newStyle = style.copyWith(
    foregroundColor: WidgetStateColor.resolveWith(
      (states) {
        if (states.contains(WidgetState.pressed)) {
          final currentForegroundColorOpacity = currentForegroundColor.opacity;
          return currentForegroundColor
              .withOpacity(currentForegroundColorOpacity * 0.4);
        }
        return currentForegroundResolver(states) ?? Colors.transparent;
      },
    ),
    backgroundColor: WidgetStateColor.resolveWith(
      (states) {
        if (states.contains(WidgetState.pressed)) {
          final currentBackgroundColorOpacity = currentBackgroundColor.opacity;
          return currentBackgroundColor
              .withOpacity(currentBackgroundColorOpacity * 0.4);
        }
        if (states.contains(WidgetState.disabled)) {
          return CupertinoColors.quaternarySystemFill;
        }
        return currentBackgroundResolver(states) ?? Colors.transparent;
      },
    ),
    side: WidgetStateProperty.resolveWith(
      (states) {
        if (style.side == null) {
          return null;
        }
        if (states.contains(WidgetState.disabled)) {
          return BorderSide.none;
        }

        if (states.contains(WidgetState.pressed)) {
          final currentSide = style.side!.resolve({})!;
          final currentSideColor = currentSide.color;
          final currentSideColorOpacity = currentSideColor.opacity;

          return currentSide.copyWith(
              color:
                  currentSideColor.withOpacity(currentSideColorOpacity * 0.4));
        }
        final currentSideResolver = style.side!.resolve;
        return currentSideResolver(states) ?? BorderSide.none;
      },
    ),
    overlayColor: const WidgetStatePropertyAll(Colors.transparent),
    elevation: const WidgetStatePropertyAll(0),
    splashFactory: NoSplash.splashFactory,
    animationDuration: const Duration(milliseconds: 120),
    shape: WidgetStatePropertyAll(
      RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8),
      ),
    ),
  );
  return newStyle;
}