Reputation: 97
I'm creating an App in Flutter/Dart and I'm currently working on the layout of the App. I'm trying to create a standart Table Layout, which works perfectly, up until I want to outsource the code into different files. At this point I created a class extending StatelessWidget which overrides the built method returning a TableRow. At this point my IDE claims that 'TableRow' is not of type 'Widget'.
I tried using different approaches like Grid Layout and some tricks with Rows/Columns, but not a single one is actually the solution I'm searching for. I'm just trying to refactor the code into multiple files.
This code is now in a seperate file. While the TableRow was a direct child in the Table() it worked perfectly fine.
import 'package:flutter/material.dart';
class Test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TableRow(
children: [
TableCell(
child: Text("test"),
),
]
)
}
}
The file I'd call the method from would somewhat look like this:
Container(
constraints: BoxConstraints(minWidth: 250, maxWidth: 300, maxHeight: 300),
child: Table(
children: [
Test(),
Test(),
Test(),
Test(),
],
),
),
I simply expected the TableRow to be recognized as a normal Widget as everything else is. TableCell for example is recognized as Widget. The error Message I get is "error: The return type 'TableRow' isn't a 'Widget', as defined by the method 'build'. (return_of_invalid_type at [projectname] lib/widgets/auth/shared/test.dart:12)". The error happens before compiling and gets marked by Android Studio.
Edit: Added code call
Upvotes: 4
Views: 4924
Reputation: 89946
The error message tells you what's wrong: TableRow
isn't a Widget
.
If you look at the TableRow
documentation, note that there is no "Inheritance" section that shows that it derives from Widget
.
If you look at the Table
documentation, note that children
is a List<TableRow>
and not a List<Widget>
.
"Everything is a widget" is a hyperbole meant to get people to think of decomposing their UIs into composable widgets. Obviously there are some things that aren't Widget
s (int
, String
, Function
, Element
, RenderObject
, ...).
Upvotes: 8