extractMaterialStatePropertySize function

Dimensions? extractMaterialStatePropertySize(
  1. Expression expr
)

Extract Size from MaterialStateProperty<Size>

Implementation

Dimensions? extractMaterialStatePropertySize(Expression expr) {
  // Check for MaterialStateProperty.all(Size(width, height))
  if (expr is MethodInvocation) {
    final methodName = expr.methodName.name;
    if (methodName == 'all' || methodName == 'resolveWith') {
      final args = expr.argumentList.arguments;
      if (args.isNotEmpty) {
        final sizeArg = args.first;
        if (sizeArg is InstanceCreationExpression) {
          final typeName = sizeArg.staticType?.element?.name;
          if (typeName == 'Size') {
            // Extract width and height from Size constructor
            final sizeArgs = sizeArg.argumentList.arguments;
            if (sizeArgs.length >= 2) {
              final width = extractNumericValue(sizeArgs[0]);
              final height = extractNumericValue(sizeArgs[1]);
              if (width != null && height != null) {
                return Dimensions(width, height);
              }
            }
          }
        }
      }
    }
  }
  return null;
}