0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Dart (Flutter)でvalue of type 'TableRow' can't be returned from the method 'build' because it has a return type of 'Widget'.と怒られた。TableRow Classはウィジェットではないらしい。

Last updated at Posted at 2023-03-10

Tableウィジェット配下のTableRowをコンポーネント化しようとしたら、value of type 'TableRow' can't be returned from the method 'build' because it has a return type of 'Widget'.と怒られました。

class MyWidget extends StatelessWidget {
  const MyWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return TableRow();
  }
}

そして、このページを見ろと言われました。

return_of_invalid_typeという「診断メッセージ」で、宣言されたreturnの型と合わないということで怒られているみたいです。
特にreturnの型を宣言しているつもりはないのですが...。

こちらのページにヒントがありました。同じエラーではないですが。

Flutterでは全ての要素がウィジェットだと思っていたのですが、どうやらTable Rowクラスはウィジェットではないらしいです。その証拠に(?)、明確にWidgetであるTableTextでは公式ドキュメントで、Widgetであるという文面がありますが、TableRowはA horizontal group of cells in a Table.という説明になっています。

また、ウィジェットのドキュメントにあるものがTable Rowにはありません。それはInheritance(継承?)の情報です。

TableRow class
https://api.flutter.dev/flutter/widgets/TableRow-class.html

Table class
https://api.flutter.dev/flutter/widgets/Table-class.html

Inheritance
Object > DiagnosticableTree > Widget > RenderObjectWidget > Table

Text class
https://api.flutter.dev/flutter/widgets/Text-class.html

Inheritance
Object > DiagnosticableTree > Widget > StatelessWidget > Text

ちなみにTableRowはWidgetではないけど、TableCellはWidgetらしい :thinking:
ドキュメントにそう書いてあるし、手元で試してみたら確かにコンポーネント化できました。

TableCell class
https://api.flutter.dev/flutter/widgets/TableCell-class.html

Inheritance
Object > DiagnosticableTree > Widget > ProxyWidget > ParentDataWidget<TableCellParentData> > TableCell

対応としては、 TableRow周りをコンポーネントに切り出したいと思ったら、TableRowの中身のContainerとかTableCellをコンポーネント化するか、Tableごとコンポーネント化するとかなのかなと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?