A voting application made with Flutter uses the VoteOnce widget, which allows the user to trigger the onTapCallback function only once no matter how many times it's tapped.

The code for VoteOnce widget is given below:

class VoteOnce extends StatefulWidget {
  final Function onTapCallback;
  final String tapText;

  const VoteOnce({Key? key, required this.onTapCallback, required this.tapText}): super(key: key);

  _VoteOnceState createState() => _VoteOnceState();

class _VoteOnceState extends State<VoteOnce> {
  bool _wasTapped = false;
  String _displayText = "";

  void initState() {
    _displayText = widget.tapText;

  Widget build(BuildContext context) {
    return Container(
      child: GestureDetector(
        onTap: () {
          if (!_wasTapped) {
          setState(() {
            _wasTapped = true;
            _displayText = "Voted";
        child: Text("Vote for $_displayText"),

What can be concluded about the lifecycle of the VoteOnce widget?

(Select all acceptable answers.)

build is called every time the Text widget is tapped.
Calling setState will trigger build only when there is a change in the value of _wasTapped or _displayText.
initState is not called when there is a change in the value passed to widget.tapText by the parent widget.
The Text widget will display "Vote for " until it is tapped, since widget.tapText is not assigned to _displayText through setState.
The Text widget can be declared as const, to prevent Flutter from rebuilding the widget when _displayText changes.

Flutter Life Cycle Widgets New Public


Would you like to see our other questions?

We have 1000+ premium hand-crafted questions for 160+ job skills and 20+ coding languages. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library
Private Concierge

Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.

Contact Private Concierge

Would you like to see our tests? The following tests contain Flutter related questions:
On the TestDome Blog

Screening Applicants: The Good, the Bad and the Ugly

Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...

Dashboard Start Trial Sign In Home Tour Tests Questions Pricing