Flutter 在测试中未找到任何材质小部件

Flutter 在测试中未找到任何材质小部件,flutter,testing,Flutter,Testing,当我运行下面的测试时,我得到了No material widget found错误,即使我将它包装在MaterialApp中。有什么能说明原因的吗 void main() { final mockExam = examMocks[0]; Widget createGridItem() => Provider<ExamInformation>.value( value: ExamInformation( examSpecificat

当我运行下面的测试时,我得到了
No material widget found
错误,即使我将它包装在MaterialApp中。有什么能说明原因的吗

void main() {
  final mockExam = examMocks[0];
  Widget createGridItem() => Provider<ExamInformation>.value(
        value: ExamInformation(
            examSpecifications: mockExam.examSpecifications,
            examImage: mockExam.examImage,
            questionList: mockExam.questionList),
        child: ExamGridItem(),
      );

  testWidgets('Exam grid item displays Footer', (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(home: createGridItem()));

    final gridItemFooterFinder = find.byType(Footer);
    expect(gridItemFooterFinder, findsOneWidget);
  });
}
void main(){
期末考试=例[0];
Widget createGridItem()=>Provider.value(
价值:形成(
examSpecifications:mockExam.examSpecifications,
模拟考试,模拟考试,
问题列表:模拟考试。问题列表),
子项:ExamGridItem(),
);
testWidgets('Exam grid item displays Footer',(WidgetTester tester)异步{
等待tester.pumpWidget(MaterialApp(home:createGridItem());
final gridItemFooterFinder=find.byType(页脚);
expect(gridItemFooterFinder、findsOneWidget);
});
}
详细错误日志:

The following assertion was thrown building _InkResponseStateWidget(gestures: [tap], mouseCursor:
null, BoxShape.circle, dirty, state: _InkResponseState#3ef96):
No Material widget found.
_InkResponseStateWidget widgets require a Material widget ancestor.
In material design, most widgets are conceptually "printed" on a sheet of material. In Flutter's
material library, that material is represented by the Material widget. It is the Material widget
that renders ink splashes, for instance. Because of this, many material library widgets require that
there be a Material widget in the tree above them.
To introduce a Material widget, you can either directly include one, or use a widget that contains
Material itself, such as a Card, Dialog, Drawer, or Scaffold.

The specific widget that could not find a Material ancestor was:
  _InkResponseStateWidget
The ancestors of this widget were:
  ...
  InkResponse
  Positioned
  Stack
  GridTile
  Consumer<ExamInformation>
  ...
在构建InkResponseStateWidget(手势:[tap],鼠标器]时抛出以下断言:
null,BoxShape.circle,脏,状态:_InkResponseEstate#3ef96):
找不到任何重要的小部件。
_InkResponseStateWidget小部件需要材质小部件祖先。
在材质设计中,大多数小部件在概念上“打印”在一张材质上。在弗利特的
材质库,该材质由“材质”小部件表示。它是材料部件
例如,渲染墨水飞溅的。因此,许多材质库小部件都需要
它们上方的树中有一个材质小部件。
要引入Material小部件,可以直接包含一个,也可以使用包含
材质本身,如卡片、对话框、抽屉或脚手架。
找不到材质祖先的特定小部件是:
_InkResponseStateWidget
此小部件的祖先是:
...
墨水反应
定位
堆栈
网格
消费者
...

您必须将小部件放在材质小部件中

例如:

材质(子项:InkWell())
导致此错误的小部件显示在错误描述中:

  InkResponse
  Positioned
  Stack
  GridTile
  Consumer<ExamInformation>
InkResponse
定位
堆栈
网格
消费者

您必须将小部件放在材质小部件中

例如:

材质(子项:InkWell())
导致此错误的小部件显示在错误描述中:

  InkResponse
  Positioned
  Stack
  GridTile
  Consumer<ExamInformation>
InkResponse
定位
堆栈
网格
消费者

在堆栈溢出上发布时,尽量避免放置代码截图,而是创建代码块。在堆栈溢出上发布时,尽量避免放置代码截图,而是创建代码块。这是小部件树,使用者位于根目录下。使用者由ExamGridItem的生成方法返回。这反过来又由createGridItem方法返回,该方法在测试中被包装在MaterialApp中。你知道MaterialApp本身为什么不起作用吗?@mirage,因为有些小部件需要
Material
widget。这与
MaterialApp
不同。MaterialApp实现导航主题化和其他全局配置。但Material用于在其上绘制内容(例如InkWell在Material上绘制内容)“这是消费者的小部件树”我认为问题与“Stack>Positioned>InkResponse”小部件有关。这是消费者位于根的小部件树。使用者由ExamGridItem的生成方法返回。这反过来又由createGridItem方法返回,该方法在测试中被包装在MaterialApp中。你知道MaterialApp本身为什么不起作用吗?@mirage,因为有些小部件需要
Material
widget。这与
MaterialApp
不同。MaterialApp实现导航主题化和其他全局配置。但是材质用于在其上绘制内容(例如,InkWell在材质上绘制内容)“这是具有消费者的小部件树”我认为问题与“堆栈>定位>InkResponse”小部件有关。