title: How to pass a string argument in Flutter?
body: <p>I'm trying to create a widget that is a container and takes two arguments, the path to the image and the title of the Image. The widget code so far is:</p>
  <pre><code>
  class CharacterBox extends StatelessWidget {
    final String imagePath;
    final String characterName;
    CharacterBox(this.imagePath, this.characterName);
    @override
    Widget build(BuildContext context) {
      final CharacterBox args = ModalRoute.of(context).settings.arguments;
      return Container(
        margin: EdgeInsets.all(20.0),
        height: 200,
        width: 100,
        child: Column(
          children: [
            Expanded(
              child: Image(
                image: AssetImage(args.imagePath),
                alignment: Alignment.center,
                fit: BoxFit.contain,
              ),
            ),
            Container(
              margin: EdgeInsets.all(5.0),
              child: Text(
                args.characterName,
                style: TextStyle(color: Colors.white),
              ),
            )
          ],
        ),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(5.0),
            color: Color.fromARGB(255, 252, 70, 82)),
      );
    }
  }
  </code></pre>
  <p>And I'm using the following to pass the arguments:</p>
  <pre><code>body: SafeArea(
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: &lt;Widget&gt;[
                CharacterBox(&quot;assets/artwork.png&quot;, &quot;Character&quot;),
              ],
            ),
          ),
  </code></pre>
  <p>However I get the error saying:</p>
  <pre><code>The getter 'imagePath' was called on null.
  Receiver: null
  Tried calling: imagePath
  </code></pre>
  <p>I guess it is related to the ModalRoute declaration since I was doing it with <a href="https://flutter.dev/docs/cookbook/navigation/navigate-with-arguments" rel="nofollow noreferrer">this</a> Documentation. However, I still didn't quiet get it.</p>