title: Flutter: Very basic stupid beginner question
body: <p>I am trying to learn Flutter and so I am following a YouTube tutorial.
  Now I have a question I can't really describe, it is working but i don't understand why.</p>
  <p>My Program contains two .dart files, you can see them below.</p>
  <p>Is the the Question Class in questions.dart executed by pressing Button 1 or 3 (Answer 1, Answer 3)?
  If I understand that correctly the buttons will execute &quot;onPressed: _answerQuestions,&quot;. But _answerQuestions only changes the State of &quot;questionIndex&quot; and is not calling something else, right? The UI gets rebuild and the Question Text changes.
  But Questions Class does change the appearence of the text with the &quot;style&quot;, this is its only task right now?</p>
  <p>So why do we have a second dart File for that? We could simply change the style within the main.dart?</p>
  <p>main.dart:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  import './question.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() {
      // TODO: implement createState
      return MyAppState();
    }
  }
  
  class MyAppState extends State&lt;MyApp&gt; {
    var questionIndex = 0;
  
    void _answerQuestions() {
      setState(() {
        questionIndex = questionIndex + 1;
      });
      print(questionIndex);
    }
  
    @override
    Widget build(BuildContext context) {
      var questions = [
        'What\'s your favorite color?',
        'What\'s your favorite animal?',
      ];
      return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('My First App'),
          ),
          body: Column(
            children: [
              Question(questions[questionIndex]),
              RaisedButton(
                child: Text('Answer 1'),
                onPressed: _answerQuestions,
              ),
              RaisedButton(
                  child: Text('Answer 2'),
                  onPressed: () =&gt; print('Answer 2 chosen')),
              RaisedButton(
                child: Text('Answer 3'),
                onPressed: _answerQuestions,
              ),
            ],
          ),
        ),
      );
    }
  }
  </code></pre>
  <p>And question.dart:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  class Question extends StatelessWidget {
    final String questionText;
  
    Question(this.questionText);
  
    @override
    Widget build(BuildContext context) {
      return Text(
        questionText,
        style: TextStyle(fontSize: 28),
      );
    }
  }
  </code></pre>