Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振测试小部件find.byType(TextField)工作,find.byWidget(TextField())不工作';不行。为什么?_Flutter_Widget_Widget Test Flutter - Fatal编程技术网

Flutter 颤振测试小部件find.byType(TextField)工作,find.byWidget(TextField())不工作';不行。为什么?

Flutter 颤振测试小部件find.byType(TextField)工作,find.byWidget(TextField())不工作';不行。为什么?,flutter,widget,widget-test-flutter,Flutter,Widget,Widget Test Flutter,我刚刚开始进行颤振小部件测试,并遇到了这个问题。我想知道这是否是预期的行为。 当尝试使用find.byType查找我的文本字段时,它会成功,但使用find.byWidget则不会成功。这是正常的还是我做错了什么?目标是稍后在文本字段中输入文本,然后点击按钮 我的文本字段和按钮: Column( children: [ TextField( style: TextStyle( color: Colors.black, ),

我刚刚开始进行颤振小部件测试,并遇到了这个问题。我想知道这是否是预期的行为。 当尝试使用find.byType查找我的文本字段时,它会成功,但使用find.byWidget则不会成功。这是正常的还是我做错了什么?目标是稍后在文本字段中输入文本,然后点击按钮

我的文本字段和按钮:

Column(
    children: [
      TextField(
        style: TextStyle(
          color: Colors.black,
        ),
        autofocus: true,
        autocorrect: false,
        enableSuggestions: false,
        controller: _controller,
        cursorColor: Colors.black,
        decoration: InputDecoration(
            hintText: 'Fill in.....',
          hintStyle: TextStyle(fontSize: 18),
        ),
      ),
      Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          ElevatedButton(
              onPressed: () {
                onSubmit(_controller.text);
              },
              child: Text('Press me!',
                  style: TextStyle(
                    fontSize: 18,
                    color: Theme.of(context).primaryColorBrightness ==
                        Brightness.dark
                        ? Colors.white
                        : Colors.black,
                  ))),
      ],),
    ],
  ),
这是我的测试:

tester.ensureVisible(find.byType(TextInputWidget));
  expect(find.byType(TextInputWidget), findsOneWidget);

  final a = TextField(
    style: TextStyle(
      color: Colors.black,
    ),
    autofocus: true,
    autocorrect: false,
    enableSuggestions: false,
    controller: TextEditingController(),
    cursorColor: Colors.black,
    decoration: InputDecoration(
      hintText: 'Fill in.....',
      hintStyle: TextStyle(fontSize: 18),
    ),
  );

  //expect(find.byWidget(a), findsOneWidget); // Fails
  expect(find.byType(TextField), findsOneWidget); //Succeeds