title: The method isn't defined for the class - Flutter
body: <p>I'm new to flutter and have been trying to make a simple quiz app. I've encountered an error and I'm not sure what is wrong.</p>
  <p><strong>Error:</strong></p>
  <pre><code>Compiler message:                                                       
  lib/main.dart:37:17: Error: The method 'Answer' isn't defined for the class '_MyAppState'.
   - '_MyAppState' is from 'package:project2/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Answer'.
                  Answer(),                                               
                  ^^^^^^                                                  
  lib/main.dart:38:17: Error: The method 'Answer' isn't defined for the class '_MyAppState'.
   - '_MyAppState' is from 'package:project2/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Answer'.
                  Answer(),                                               
                  ^^^^^^                                                  
  lib/main.dart:39:17: Error: The method 'Answer' isn't defined for the class '_MyAppState'.
   - '_MyAppState' is from 'package:project2/main.dart' ('lib/main.dart').
  Try correcting the name to the name of an existing method, or defining a method named 'Answer'.
                  Answer()                                                
                  ^^^^^^     
  </code></pre>
  <p><strong>main.dart:</strong></p>
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
  import './questions.dart';
  import './answer.dart';
  
  void main() =&gt; runApp(MyApp());
  
  class MyApp extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() {
      return _MyAppState();
    }
  }
  
  class _MyAppState extends State&lt;MyApp&gt; {
    var _questionIndex = 0;
  
    var _questions = [&quot;Question 1?&quot;, &quot;Question 2?&quot;, &quot;Question 3?&quot;];
  
    void _answerQuestion() {
      setState(() {
        _questionIndex = _questionIndex + 1;
      });
  
      print(&quot;You answered the question!&quot;);
    }
  
    Widget build(BuildContext context) {
      return MaterialApp(
          home: Scaffold(
              appBar: AppBar(
                title: Text(&quot;Quiz&quot;),
              ),
              body: Column(
                children: &lt;Widget&gt;[
                  Question(_questions[_questionIndex]),
                  Answer(),
                  Answer(),
                  Answer()
                ],
              )));
    }
  }
  
  </code></pre>
  <p><strong>answer.dart:</strong></p>
  <pre class="lang-dart prettyprint-override"><code>import 'package:flutter/material.dart';
  
  class Answer extends StatelessWidget {
  
    @override
    Widget build(BuildContext context) {
      return Container(
          width: double.infinity,
          color: Colors.blue,
          child: RaisedButton(child: Text(&quot;Answer 1&quot;), onPressed: null));
    }
  }
  </code></pre>
  <p>I have used the same class name and imported the right file into main.dart. I'm not sure what's wrong. Can someone please point it out to me. Thanks in advance!</p>