IconButton throws an exception

Viewed 6387

I'm trying to make a simple AppBar widget with some icons in Flutter, but I keep getting this assertion:

    The following assertion was thrown building IconButton(Icon(IconData(U+0E5D2)); disabled; tooltip:

I pretty much just mimiced the documentation, but here is my code:

import 'package:flutter/material.dart';

void main() {
  runApp(new MaterialApp(
  title: "Stateless Widget Example",
  home: new AppBar(title: new Text("App Bar"))
 ));
}

class AppBar extends StatelessWidget {
  AppBar({this.title});

  final Widget title;

  @override
  Widget build(BuildContext context) {
    return new Container(
      height: 56.0,
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      decoration: new BoxDecoration(
        color: Colors.cyan,
        border: new Border(
          bottom: new BorderSide(
            width: 1.0,
            color: Colors.black
          )
        )
      ),
      child: new Row (
        children: <Widget> [
          new IconButton(
            icon: new Icon(Icons.menu),
            tooltip: 'Navigation menu',
            onPressed: null, // null disables the button
          ),
          new Expanded(child: title)
        ]
      )
    );
  }
}

I feel like I'm missing an import or something. But I'm not completely sure. Perhaps my computer was just acting up, because Flutter run has been buggy for me. I'm new to Dart and Flutter, so perhaps I'm just not seeing an obvious error.

4 Answers
addButton() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 10.0),
          child: SizedBox(
            height: 45,
            width: 200,
            child: ElevatedButton.icon(
              onPressed: () async {},
              style: ButtonStyle(
                shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                    RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(30.0),
                      )),
                elevation: MaterialStateProperty.all(1),
                backgroundColor: MaterialStateProperty.all(Colors.blue),
              ),
              icon: Icon(Icons.add, size: 18),
              label: Text("Add question"),
            ),
          ),
        ),
      ],
    );
  }

you lost meterial widget IconButton needs Material

return new Material(
      child: new Container(
      height: 56.0,
      padding: const EdgeInsets.symmetric(horizontal: 8.0),
      decoration: new BoxDecoration(
        color: Colors.cyan,
        border: new Border(
          bottom: new BorderSide(
            width: 1.0,
            color: Colors.black
          )
        )
      ),
      child: new Row (
        children: <Widget> [
          new IconButton(
            icon: new Icon(Icons.menu),
            tooltip: 'Navigation menu',
            onPressed: null, // null disables the button
          ),
          new Expanded(child: title)
        ]
      )
    );
Related