Programmatic Widget creation and Onclick binding

I was refering to the previous answer, more particularly this :
Your switch block has a static number of pin
image

I need to look to all your new answer in detail now, it looks good .

Thanks a lot for the time you took.