When I read the question, I quickly thought that a memory cell could be involved somewhere in the solution. But actually, a memory cell (with one input inverted) is already all you need!

Imagine that the comparator comes from your minecart and the button is just your button. The redstone lamp is the output for emptying the minecart.
When the minecart arrives with items, it turns on the comparator, which turns off the redstone lamp on the left and the redstone dust. Nothing else happens, because the memory cell still holds its state, that's the point of a memory cell.
When you now press the button, the bottom redstone torch and the left repeater turn off, which allows the top right redstone torch to turn on (since it's also not deactivated by the redstone line anymore), which turns on the output and the repeater on the right.
When the button input ends, the bottom redstone torch still does not turn on, because the right repeater is still on. Again, what a memory cell is supposed to do.
Only when the comparator turns off and the left redstone torch and the dust turn on again, then the top right redstone torch turns off again, deactivating the right repeater, activating the bottom redstone torch and the left repeater.
Special cases:
- If the minecart empties before the button turns off, the input turns off rightaway (with 3 ticks delay).
- If you press the button while the minecart is empty or not there, nothing happens.
- Spamming both inputs in certain ways very quickly and very often might cause the torches to burn out, but that should be extremely unlikely in your usecase and probably very easy to fix (it might even fix itself).
ON
state with nothing in the chest, it would immediately start dispensing stuff from the chest on the next use, without a button press. This would be dangerous.TFlipFlipInput = (chest && button) || (!chest && TFlipFlipOutput)
that would only allow an empty chest to turn the output to the off position. I'm still curious if there's a simpler way.unloading = button || (chest && unloading)
should work just fine