He had a full day to do it. His fam left, it's still light outside. When Jesse comes over accusing him of poisoning Brock, it's dark outside. There was a solid 8-10 hour window for it to take place.
Also keep in mind Saul and his goon Huell were helping Walt. In this scene you can see the goon put something in his pocket....
That's when he swapped the pack out, just like Jesse said. What's funny is Jesse was 100% right and he let Walt manipulate him.
And in the finale scene, when Walt goes looking for Saul, you can see his secretary shredding school schedules:
It's kinda blurry but you can make out ART, HIST, MATH, ENG, etc.
Huell or Saul could've poisoned the kid while Walt was at home.