title: How to define variable inside of a text widget located in a separate dart file in Flutter
body: <p>I have a <code>messages.dart</code> file that holds all the initial texts for different messages as Widgets.</p>
  <pre><code>Widget rest = Text('You should rest $restTime or $restTimeOr');
  </code></pre>
  <p>In the <code>main.dart</code> file, I'm defining the <code>$restTime</code> string value and in the column children, I want to call the <code>rest</code> widget from the <code>messages.dart</code> file.</p>
  <pre><code>class _HomePageState extends State&lt;HomePage&gt; {
    String restTime = 'now';
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Column(
          children: [
            rest,
          ],
        ),
      );
    }
  }
  </code></pre>
  <p>But it gives me the error in the <code>messages.dart</code> file that <code>restTime</code> is undefined. What am I missing here?
  The complete <code>main.dart</code> file is:</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'example/messages.dart';
  
  void main() {
    runApp(MyApp());
  }
  
  class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: HomePage(),
      );
    }
  }
  
  class HomePage extends StatefulWidget {
    @override
    _HomePageState createState() =&gt; _HomePageState();
  }
  
  class _HomePageState extends State&lt;HomePage&gt; {
    String restTime = 'now';
    String restTimeOr = '2 hours later';
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Column(
          children: [
            rest,
          ],
        ),
      );
    }
  }
  </code></pre>
  <p>And the <code>messages.dart</code> file is:</p>
  <pre><code>import 'package:flutter/material.dart';
  
  Widget rest = Text('You should rest $restTime or $restTimeOr');
  </code></pre>