title: Custom widget testing needs Material widget to test
body: <p>I am trying to perform basic widget testing in Flutter. Basically I would like to have a list with list of data, and display each of the items in a custom widget (<em><strong>BasicListItem</strong></em>) which also has a ListTile widget in it.</p>
  <p>Root widget:</p>
  <pre><code>class MyApp extends StatelessWidget {
    final List taskList = ['List-1', 'List-2', 'List-3'];
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        home: Scaffold(
          body: ListView.builder(
              itemCount: taskList.length, itemBuilder: _itemBuilder),
        ),
      );
    }
  
    Widget _itemBuilder(BuildContext context, int index) {
      final String item = taskList[index];
      return BasicListItem(key: Key(item), title: item);
    }
  }
  </code></pre>
  <p>The list item widget (<strong>BasicListItem</strong>) takes a title, and use it inside the ListTile widget.</p>
  <pre><code>class BasicListItem extends StatelessWidget {
    final String title;
  
    const BasicListItem({required Key key, required this.title})
        : super(key: key);
  
    @override
    Widget build(BuildContext context) {
      return ListTile(
        leading: Icon(Icons.map),
        title: Text(title),
      );
    }
  }
  </code></pre>
  <p>This is the test for it:</p>
  <pre><code>testWidgets('has title and Icons', (WidgetTester tester) async {
  
    const testKey = Key('my-key-1');
    const testTitle = 'Demo title';
  
    await tester.pumpWidget(BasicListItem(key: testKey, title: testTitle));
  
    expect(find.text(testTitle), findsOneWidget);
  });
  </code></pre>
  <p>But the test throws an error:</p>
  <blockquote>
  <p>No Material widget found. ListTile widgets require a Material widget
  ancestor.</p>
  </blockquote>
  <p>...
  ...</p>
  <blockquote>
  <p>The following TestFailure object was thrown running a test:<br />
  Expected: exactly one matching node in the widget tree   Actual:
  _TextFinder:&lt;zero widgets with text &quot;Demo title&quot; (ignoring offstage widgets)&gt;</p>
  </blockquote>
  <p>However, the test does <em><strong>pass</strong></em> if I wrap ListTile around a MaterialApp, inside the BasicListItem build method. Like so:</p>
  <pre><code>@override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      home: Scaffold(
        body: ListTile(
          leading: Icon(Icons.map),
          title: Text(title),
        ),
      )
    );
  }
  </code></pre>
  <p>But doing this I cannot use it inside the ListView widget. And also I would like to have modular/separate custom widgets so that I can use it on different places as well. I am new and maybe I am missing something. How can I build custom widget and test it out? Could you help me out please.</p>