# Chapter 5 Passing Functions to Functions...why doesn't this work?

**URL:** <https://forums.kodeco.com/t/chapter-5-passing-functions-to-functions-why-doesnt-this-work/169740>\
**Category:** Dart Apprentice\
**Created:** [April 25, 2022, 5:16am UTC](https://forums.kodeco.com/t/chapter-5-passing-functions-to-functions-why-doesnt-this-work/169740 "2022-04-25T05:16:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kemmetdaniel](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kemmetdaniel/32/105896_2.png) [@kemmetdaniel](https://forums.kodeco.com/u/kemmetdaniel)\
**Post date:** [April 25, 2022, 5:16am UTC](https://forums.kodeco.com/t/chapter-5-passing-functions-to-functions-why-doesnt-this-work/169740/1 "2022-04-25T05:16:50Z")

</div>

I try to code my own examples / scenarios as I work through the book to make sure I understand what I’m reading / learning and not just relying on the book’s boiler plate. I started the passing functions to functions section and wrote the following code:

```auto
  double taxRate = .0825;
  double costOfProduct = 9.99;

  Function totalCostOfProduct =
      ({required double taxRate, required double costOfProduct}) {
    return (costOfProduct * taxRate) + costOfProduct;
  };
  
  print(totalCostOfProduct(taxRate: taxRate, costOfProduct: costOfProduct));

  String tellMeThePrice({required Function totalCostOfProduct}) {
    return "THE PRICE IS ${totalCostOfProduct}";
  }

  print(tellMeThePrice(
      totalCostOfProduct: totalCostOfProduct(
          taxRate: taxRate, totalCostOfProduct: costOfProduct)));

```

However when I run this I get the following error:

```auto
Unhandled exception:
NoSuchMethodError: Closure call with mismatched arguments: function 'main.<anonymous closure>'
Receiver: Closure: ({required double costOfProduct, required double taxRate}) => double
Tried calling: main.<anonymous closure>(taxRate: 0.0825, totalCostOfProduct: 9.99)
Found: main.<anonymous closure>({required double costOfProduct, required double taxRate}) => double
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:38:5)
#1 _objectNoSuchMethod (dart:core-patch/object_patch.dart:85:9)
#2 main (file:///home/dj/Repos/Dart-Apprentice/Chapter%205/lesson.dart:24:45)
#3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

```

This doesn’t make sense to me because I am passing a defined function object (totalCostOfProduct) to the tellMeThePrice function which requires a function that calculates the price as a named parameter. So it got that, and THAT function got it’s required doubles becuase they are previously assigned in the main function. The IDE isn’t throwing a fit, why is the dart compiler? What don’t I understand?

I suspect but can’t confirm this is a closure / scope issue.

---

<div class="post-metadata">

**Author:** ![suragch](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/suragch/32/109020_2.png) [@suragch](https://forums.kodeco.com/u/suragch)\
**Post date:** [April 25, 2022, 7:14am UTC](https://forums.kodeco.com/t/chapter-5-passing-functions-to-functions-why-doesnt-this-work/169740/2 "2022-04-25T07:14:23Z")

</div>

Good question. I reposted it here:

- [Passing parameters in Dart from one anonymous function to another using the variable name - Stack Overflow](https://stackoverflow.com/questions/71995692/passing-parameters-in-dart-from-one-anonymous-function-to-another-using-the-vari)

Feel free to add comments or edit the question there.
