Найдите радио виджет в тесте флаттера - PullRequest
0 голосов
/ 28 января 2020

У кого-нибудь есть предложения о том, как найти следующий переключатель в моем дереве виджетов в модульном тесте?

Из debugDumpApp() виджет, который я пытаюсь найти, находится внизу этого фрагмент:

│      ├InkWell(gestures: [tap], clipped to BoxShape.rectangle, state: _InkResponseState<InkResponse>#e573c)
                              │      │└Actions(dispatcher: null, actions: {[<SelectAction>]: Closure: () => Action from Function '_createAction@613059085':., [<ActivateAction>]: Closure: () => Action from Function '_createAction@613059085':.})
                              │      │ └Focus(dependencies: [_FocusMarker], state: _FocusState#e7131)
                              │      │  └_FocusMarker
                              │      │   └Semantics(container: false, properties: SemanticsProperties, label: null, value: null, hint: null, hintOverrides: null, renderObject: RenderSemanticsAnnotations#e56d2 relayoutBoundary=up3)
                              │      │    └MouseRegion(listeners: [enter, exit], renderObject: RenderMouseRegion#61069 relayoutBoundary=up4)
                              │      │     └GestureDetector(startBehavior: start)
                              │      │      └RawGestureDetector(state: RawGestureDetectorState#51044(gestures: [tap], behavior: opaque))
                              │      │       └_GestureSemantics(renderObject: RenderSemanticsGestureHandler#8ee96 relayoutBoundary=up5)
                              │      │        └Listener
                              │      │         └_PointerListener(listeners: [down], behavior: opaque, renderObject: RenderPointerListener#125af relayoutBoundary=up6)
                              │      │          └Row(direction: horizontal, mainAxisAlignment: start, crossAxisAlignment: center, dependencies: [Directionality], renderObject: RenderFlex#2d677 relayoutBoundary=up7)
                              │      │           ├Radio<String>(dependencies: [_LocalizationsScope-[GlobalKey#eab41], _InheritedTheme], state: _RadioState<String>#e39e8(tickers: tracking 4 tickers))

Модульный тест, который не может его найти:

    final widget = MaterialApp(
      home: Scaffold(
        body: RadioListWidget(
          radioList: radiolist,
          onChange: (value) {
            selected = value;
          },
        ),
      ),
    );

      testWidgets('it behaves the same as tapping the text', (tester) async {
        await tester.pumpWidget(widget);
        debugDumpApp();
        await tester.tap(find.byType(Radio).first);
        expect(selected, 'radio 1');
      });

1 Ответ

0 голосов
/ 05 марта 2020

Замените ваш искатель следующим:

find.byType(Radio<String>().runtimeType)
...