The "love-in-idleness" flower, otherwise known as a pansy, is first referred to by Oberon in Act 2, Scene 1. He relays to Puck that one night he saw Cupid "[f]lying between the cold moon and the earth" (II.i.159). Cupid aimed his arrow at a beautiful virgin but missed, and instead, the arrow hit a flower that changed from "milk-white" to "purple with love's wound" (170). The flower is now magical from Cupid's arrow and if you squeeze the juice onto a sleeping person's eyelids that person will fall in love with the first "living creature" he/she sees (173-175). The flower is called "love-in-idleness" because love is created while the person is in a state of idleness, or repose. Another reason it can be called "love-in-idleness" is because a person, like Hermia, can win love without having to do any real work or suffering.
The flower plays a significant role in the ending of the play because it rightly unites the two couples. In the opening scene of the play, we learn that Demetrius had actually sworn vows of love to Helena before he began pursuing Hermia (I.i.247-248). Demetrius even later confesses that he had been engaged to Helena before beginning to court Hermia, as we see in his line addressed to Theseus, "To her, my lord, / Was I betroth'd ere I saw Hermia" (IV.i.172-173). Hence, having Demetrius fall in love again with Helena is the morally correct ending for the story. It is also correct that Hermia should marry Lysander as he has just as much social standing as Demetrius and may even be wealthier than Demetrius, which are things we see Lysander tell Egeus in the opening scene in an effort to persuade Egeus to let his daughter make her own choice without the threat of death. Hence, the flower serves to rightly unite both couples, creating a satisfying and morally correct ending.