2017-05-17 36 views
1

我試圖與在顫振一些圖標簡單AppBar窗口小部件,但我不斷收到這種說法:撲:IconButton不工作

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

我幾乎只是mimiced的文件,但這裏是我的代碼:

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) 
     ] 
    ) 
    ); 
    } 
} 

我覺得我錯過了導入或其他東西。但我不完全確定。也許我的電腦剛剛起作用,因爲Flutter運行對我來說已經是越野車了。我是Dart和Flutter的新手,所以也許我只是沒有看到明顯的錯誤。

回答

4

IconButton是材料的Widget,所以你需要使用它材質父裏面,比如像這樣:

Widget build(BuildContext context) { 
    return new Scaffold(
     appBar: new AppBar(title: new Text(widget.title), actions: <Widget>[ 
     new IconButton(
      icon: new Icon(Icons.favorite), 
      tooltip: 'Favorite', 
      onPressed:() {}, 
     ), 
     new IconButton(
      icon: new Icon(Icons.more_vert), 
      tooltip: 'Navigation menu', 
      onPressed:() {}, 
     ), 
     ]), 
     body: new Center(
     child: new Text('This is the body of the page.'), 
    ), 
    ); 
    } 
0

檢查,以確保您的pubspec.yaml包含以下內容:

flutter: 
    uses-material-design: true 

這將確保該材料圖標字體是包含在你的應用程序,讓您可以在圖標類中使用的圖標。

+0

這已經添加,任何其他的想法? –