We do that all the time on a pump, so if you don’t mind having an extra injection then there’s no reason why you can’t do it too, the insulin is the same.
What do you do if your blood sugar is a bit high though, do you add a correction amount onto the food dose when you inject for your dinner? Don’t do that again if you inject separately for the pudding or you will end up overdosing. E.g. say you test just before dinner and your BG is 11. You calculate carbs, work out the dose and add a bit on to bring the 11 back down into range. Then you decide to have pudding. Your BG in the meantime has risen to 13 because of the food you have eaten, the insulin hasn’t had time to get working properly yet. If you correct again you will have done it twice because the first injection covered the high BG and the food, that insulin hasn’t finished working, and the only reason it’s gone up is because of the food so it will go down again when the insulin gets working.
In fact, I wouldn’t bother testing again, just do an injection for the pudding carbs only!