# Ch 6.6: Need help understanding syntax of return statement

**URL:** <https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245>\
**Category:** Flutter Apprentice\
**Created:** [December 3, 2021, 12:06am UTC](https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245 "2021-12-03T00:06:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmjpmj](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pmjpmj/32/101435_2.png) [@pmjpmj](https://forums.kodeco.com/u/pmjpmj)\
**Post date:** [December 3, 2021, 12:06am UTC](https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245/1 "2021-12-03T00:06:46Z")

</div>

Chapter 6, section 6 includes the following code snippet:

```nohighlight
// 1
return Consumer<TabManager>(builder: (context, tabManager, child) {
  return Scaffold(
      appBar: AppBar(
          title: Text(
            'Fooderlich',
            style: Theme.of(context).textTheme.headline6,
          ),
      ),
      // 2
      // TODO: Replace body
      body: pages[tabManager.selectedTab],
      bottomNavigationBar: BottomNavigationBar(
          selectedItemColor: Theme.of(context)
            .textSelectionTheme.selectionColor,
          // 3
          currentIndex: tabManager.selectedTab,
          onTap: (index) {
            // 4
            tabManager.goToTab(index);
          },
          items: <BottomNavigationBarItem>[
            const BottomNavigationBarItem(
                icon: Icon(Icons.explore),
                label: 'Explore',
            ),
            const BottomNavigationBarItem(
                icon: Icon(Icons.book),
                label: 'Recipes',
            ),
            const BottomNavigationBarItem(
                icon: Icon(Icons.list),
                label: 'To Buy',
            ),
          ],
      ),
    );
  },
);

```

I am having difficulty parsing the first line of this code. Abstracting out the details that I understand, I get this:

```auto
return Consumer<TabManager>(builder: (context, tabManager, child) { return Scaffold(...) });

```

Basically, it appears that the code returns a Consumer widget that is constructed with two arguments:

1. “builder”, which is `(context, tabManager, child)`
2. Syntax I don’t understand: `{ return Scaffold()}`

Could someone explain this syntax use to me?

Thanks!

---

<div class="post-metadata">

**Author:** ![jomoka](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jomoka/32/109828_2.png) [@jomoka](https://forums.kodeco.com/u/jomoka)\
**Post date:** [December 3, 2021, 2:34am UTC](https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245/2 "2021-12-03T02:34:37Z")

</div>

@pmjpmj

In summary when ever you need to listen to some state change, you can wrap your widget in a `Consumer` widget. When state changes, the `builder` method is triggered to rebuild the child widgets with the new state.

The `Consumer` widget is part of the `provider` package state management solution, you can find more info here:

> **[Simple app state management](https://docs.flutter.dev/development/data-and-backend/state-mgmt/simple)**
>
> A simple form of state management.

> **[Consumer class - provider library - Dart API](https://pub.dev/documentation/provider/latest/provider/Consumer-class.html)**
>
> API docs for the Consumer class from the provider library, for the Dart programming language.

This is just a small introduction to state management, i believe in the later chapters you will be introduced to the provider package. So feel free to jump to chapter 14 to understand more.

---

<div class="post-metadata">

**Author:** ![pmjpmj](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/pmjpmj/32/101435_2.png) [@pmjpmj](https://forums.kodeco.com/u/pmjpmj)\
**Post date:** [December 3, 2021, 3:31am UTC](https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245/3 "2021-12-03T03:31:43Z")

</div>

Thanks for the quick response!

I’m sorry, I wasn’t clear. I think my question is actually about Dart language syntax. What does it mean when you have a function with a parameter that is in curly braces like this:

```auto
return Foo( bar, { return Baz() });

```

Notice the curly braces and return statement _inside_ the parameters to Foo.

I understand about Consumers and so forth, but this syntax is a mystery to me.

Thanks!

---

<div class="post-metadata">

**Author:** ![jomoka](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jomoka/32/109828_2.png) [@jomoka](https://forums.kodeco.com/u/jomoka)\
**Post date:** [December 3, 2021, 12:29pm UTC](https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245/4 "2021-12-03T12:29:10Z")

</div>

It’s called a closure. Think of it like a function. But the difference between a function and a closure is it has no name.

---

<div class="post-metadata">

**Author:** ![kvutien](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kvutien/32/100870_2.png) [@kvutien](https://forums.kodeco.com/u/kvutien)\
**Post date:** [January 12, 2022, 3:07pm UTC](https://forums.kodeco.com/t/ch-6-6-need-help-understanding-syntax-of-return-statement/159245/5 "2022-01-12T15:07:59Z")

</div>

Let me try and help, sharing what a newbie like me understood of Dart, but @jomoka might correct me if I’m wrong.

The statement `return Consumer( builder: (someArg) {some code},);` is returning a constructor of an object called `Consumer`. This constructor takes an argument named `builder`. This `builder` is actually a function that has `someArg` as argument and a body that is between brackets.

Is it correct, @jomoka ?
