Flutterでいくつかのアイコンを使用して単純なAppBarウィジェットを作成しようとしていますが、次のアサーションを取得し続けます。
The following assertion was thrown building IconButton(Icon(IconData(U+0E5D2)); disabled; tooltip:
私はほとんどドキュメントを模倣しましたが、ここに私のコードがあります:
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を初めて使用するので、明らかなエラーが表示されないだけかもしれません。
IconButtonはマテリアルウィジェットであるため、次のように、マテリアルの親内で使用する必要があります。
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.'),
),
);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加