Closure call with mismatched arguments: function ‘routes.<anonymous closure>‘

Posted 我叫白小飞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Closure call with mismatched arguments: function ‘routes.<anonymous closure>‘相关的知识,希望对你有一定的参考价值。

Closure call with mismatched arguments: function ‘routes.’

今天在玩flutter的时候,发现了个问题,以此记录一下:
在学习路由跳转的时候,将路由提取出来,然后在MaterialApp里边配置onGenerateRoute的时候:

 
  Widget build(BuildContext context) 
    return MaterialApp(
      debugShowCheckedModeBanner: false, // 去掉debug图标
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      // home: const Tabs(title: 'Flutter Demo Home Page'),
      initialRoute: "/", // 配置默认路由
      onGenerateRoute: onGenerateRoute,
    );
  

提取出来的route:

var onGenerateRoute = (RouteSettings settings) 
  // 统一处理路由
  final String? name = settings.name;
  final Function? pageContentBuilder = routes[name];

  if (pageContentBuilder != null) 
    if (settings.arguments != null) 
      Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
     else 
      Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    
  
  return null;
;

乍一看,没啥问题啊,可是一运行就有问题了:

======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building Builder(dirty):
Closure call with mismatched arguments: function 'routes.<anonymous closure>'
Receiver: Closure: (dynamic, dynamic argumnets) => FormPage
Tried calling: routes.<anonymous closure>(Instance of 'StatelessElement', arguments: _LinkedHashMap len:2)
Found: routes.<anonymous closure>(dynamic, dynamic argumnets) => FormPage

参数不匹配,我也是纳闷了,这和老师写的一样啊,找了半个小时,终于找到了问题:
我特么眼瞎啊
我特么眼瞎啊
我特么眼瞎啊

注意单词,是不是写错了

注意单词,是不是写错了

注意单词,是不是写错了

我就是arguments这个单词写错了…

以上是关于Closure call with mismatched arguments: function ‘routes.<anonymous closure>‘的主要内容,如果未能解决你的问题,请参考以下文章

Closure::call()

Groovy闭包 Closure ( 闭包调用 与 call 方法关联 | 接口中定义 call() 方法 | 类中定义 call() 方法 | 代码示例 )

Groovy闭包 Closure ( 闭包调用 与 call 方法关联 | 接口中定义 call() 方法 | 类中定义 call() 方法 | 代码示例 )

laravel with closure

Groovy闭包 Closure ( 闭包调用 | 闭包默认参数 it | 代码示例 )

php7新特性