Let's say we have your HTML code something like this:
<form > <input type="radio" name="gender" id="gender_male" value="male">Male<br> <input type="radio" name="gender" id="gender_female" value="female">Female </form> <form> <input type="checkbox" id="baconLover">I like bacon<br> </form>
Your Dart code to get your values will be something like this: I also added an event to find out when the checkbox is checked.
import 'dart:html'; void main() { // Adds a click event when the checkbox is clicked query("#baconLover").on.click.add((MouseEvent evt) { InputElement baconCheckbox = evt.target; if (baconCheckbox.checked) { print("The user likes bacon"); } else { print("The user does not like bacon"); } }); // Adds a click event for each radio button in the group with name "gender" queryAll('[name="gender"]').forEach((InputElement radioButton) { radioButton.onclick.listen((e) { InputElement clicked = e.target; print("The user is ${clicked.value}"); }); }); }
Eduardo copat
source share