Pending an answer from a real electrician, I suspec that that three components you're connecting together are not sufficiently compatible.
I'm referring to the lights, the fan, and the dimmer control.
For example, I believe the load that fan motor presents to the dimmer is vastly different to that of the lights, so connecting the fan to the dimmer is likely to be the cause of your flickering problem. If you disconnect the fan then you can confirm this.
I'm really guessing here, but it might be that you simply need a two gang dimmer control switch.
As I said, I don't know the correct solution to what you're trying to achieve, but based on personal experience I wouldn't have expected what you're doing to work. Easy to say in retrospect, I know, but I hope you know what I mean.