My application is in UIKit.

I am developing a medium-sized widget for my application. The widget has been created using SwiftUI. The widget contains three buttons, each intended to navigate the user to a specific screen within the app.

Currently, the design of my widget looks good, and it appears correctly on the home screen. However, when I tap on any of the three buttons, the button click event does not seem to be working.

When I tap on a button, the entire widget is clicked. However, I want to distinguish and manage the click events for each of the three buttons individually.

I have already referred to this but that’s not working

Here is my code:

struct appWidgetEntryView: View {
    
    @Environment(.widgetFamily) var widgetFamily

    var body: some View {
        Group {
          if widgetFamily == .systemMedium {
                RectangleWidgetView() 
            }
        }
    }
}
struct RectangleWidgetView: View {
            
    var body: some View {
    
        VStack(spacing: 8){
            Button(action: {
                // Action
                print("****View Contacts Clicked*****")
                
            }) {
                HStack(spacing: 4) {
                    Spacer()
                    Text("View Contacts")
                        .font(.system(size: buttonFontSize))
                        .fontWeight(.medium)
                        .foregroundStyle(.black)
                        .frame(height: buttonHeight)
                        .lineLimit(2)
                    
                    Image("contacts")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 20, height: 20)
                        .foregroundStyle(.black)
                    Spacer()
                }
            }
            .buttonStyle(.plain)
            .frame(maxWidth: .infinity, alignment: .center)
            
            Button(action: {
                UserDefaults(suiteName: WidgetKitManager.Name.appGroup.rawValue)?.setValue("showHub", forKey: "widgetAction")
                
                print("****Add contact Clicked*****")
            }) {
                HStack(spacing: 4) {
                    Spacer()
                    Text("Add Contact")
                        .font(.system(size: buttonFontSize))
                        .fontWeight(.medium)
                        .foregroundStyle(.black)
                        .frame(height: buttonHeight)
                        .lineLimit(2)
                    
                    Image("float_add")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 15, height: 15)
                        .foregroundStyle(.black)
                    Spacer()
                }
            }
            .buttonStyle(.plain)
            .frame(maxWidth: .infinity, alignment: .center)
            
            Button(action: {
                UserDefaults(suiteName: WidgetKitManager.Name.appGroup.rawValue)?.setValue("showHub", forKey: "widgetAction")
                
                print("****Delete Clicked*****")
            }) {
                HStack(spacing: 4) {
                    Spacer()
                    Text("Delete Contact")
                        .font(.system(size: buttonFontSize))
                        .fontWeight(.medium)
                        .foregroundStyle(.black)
                        .frame(height: buttonHeight)
                        .lineLimit(2)
                    
                    Image("float_add")
                        .resizable()
                        .scaledToFit()
                        .frame(width: 15, height: 15)
                        .foregroundStyle(.black)
                    Spacer()
                }
            }
            .buttonStyle(.plain)
            .frame(maxWidth: .infinity, alignment: .center)
            
            
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(widgetBGColor)
        .cornerRadius(12)
        .adoptableWidgetBackground(widgetBGColor) // Add this line
    }
}