【问题标题】:What is the purpose of underline sign using (_) { } in Flutter? [duplicate]在 Flutter 中使用 (_) { } 下划线符号的目的是什么? [复制]
【发布时间】:2019-10-04 09:02:51
【问题描述】:

我正在通过 https://flutter.dev/docs/cookbook/testing/unit/mocking 指南学习在 Flutter 中使用 Mockito 模拟依赖项。

我不明白下面一行:

when(client.get('https://jsonplaceholder.typicode.com/posts/1'))
          .thenAnswer((_) async => http.Response('{"title": "Test"}', 200));

(_) {} 中的下划线符号到底有什么作用?据我所知,() 用于传递需要在{} 正文中使用的参数。在编写_ 时,我们究竟传递给函数的是什么?

【问题讨论】:

  • 是的,你可能是对的。试图自己找到它,但看起来我失败了。感谢您的回答。

标签: testing flutter dart mockito


【解决方案1】:

它是一个变量名,当我不想使用参数时,我正在使用_。通常_ 用于private,但在这种情况下它与private 无关。

【讨论】:

    猜你喜欢
    • 2010-09-18
    • 2015-04-18
    • 2017-11-27
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    相关资源
    最近更新 更多