Ad

TabBarSelection No Such Method Error

- 1 answer

I am trying to make a simple tabbed page with

class NotePageState extends State<NotePage> {

  @override
  Widget build(BuildContext context) {
    final List<Note> _notes = <Note>[new Note(title: "Note 1", description: "Description 1"), new Note(title: "Note 3", description: "Description 2")];
    return new Scaffold(
        appBar: new AppBar(
        // Here we take the value from the MyHomePage object that
        // was created by the App.build method, and use it to set
        // our appbar title.
          title: new Text("Title"),
        ),
        body: new TabBarSelection<Note>(
          values:_notes,
          key: new GlobalKey(),
          child: new TabBarView<Note>(
              key : new GlobalKey(),
              children:  _notes.map((Note note) {
                new NoteContainer(note);
              }).toList()
          )
        )
    );
  }

But I got:

0      Object._noSuchMethod (dart:core-patch/object_patch.dart:44)
1      Object.noSuchMethod (dart:core-patch/object_patch.dart:47)
2      KeyedSubtree.KeyedSubtree.wrap (package:flutter/src/widgets/basic.dart:3092:21)
3      _TabBarViewState._updateItemsFromChildren (package:flutter/src/material/tabs.dart:1152:11)
4      _TabBarViewState._updateItemsForSelectedIndex (package:flutter/src/material/tabs.dart:1161:7)
5      _TabBarViewState._updateItemsAndScrollBehavior (package:flutter/src/material/tabs.dart:1183:5)
6      _TabBarViewState._initSelection (package:flutter/src/material/tabs.dart:1128:7)
7      _TabBarViewState.buildContent (package:flutter/src/material/tabs.dart:1263:5)
8      ScrollableState.build (package:flutter/src/widgets/scrollable.dart:776:16)
9      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2895:23)
10     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
11     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
12     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3013:22)
13     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
14     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
15     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
16     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2907:16)
17     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
18     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
19     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
20     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
21     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
22     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2907:16)
23     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
24     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
25     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3013:22)
26     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
27     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
28     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2907:16)
30     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
31     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
32     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
33     ParentDataElement.mount (package:flutter/src/widgets/framework.dart:3196:16)
34     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
35     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:3939:32)
36     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
37     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
38     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2907:16)
39     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
40     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
41     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
42     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
43     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
44     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2907:16)
45     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
46     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
47     StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3013:22)
48     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
49     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
50     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
51     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:3843:14)
52     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2248:14)
53     Element.updateChild (package:flutter/src/widgets/framework.dart:2076:12)
54     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:2907:16)
55     BuildableElement.rebuild (package:flutter/src/widgets/framework.dart:2784:5)
56     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:2875:5)
57     ComponentElement.mount (package:flutter/src/widgets/framework.dart:2870:5)
Ad

Answer

Looks like your block is missing a return statement:

          children:  _notes.map((Note note) {
            new NoteContainer(note); // missing return.
          }).toList()

I'm surprised the analyzer isn't warning you? https://dartpad.dartlang.org/79d5f3213049aa11146e0082a66b472e

Filed https://github.com/dart-lang/sdk/issues/28018 about the missing analyzer warning.

Ad
source: stackoverflow.com
Ad