【问题标题】:network handling and internet connection handling using mvvm with provider in flutter在 flutter 中使用 mvvm 和 provider 进行网络处理和互联网连接处理
【发布时间】:2022-12-19 18:40:07
【问题描述】:

我在 onTap 中遇到错误。 错误:无法将参数类型“Function”分配给参数类型“void Function()?”。

  • “函数”来自“dart:core”。 onTap:onTap
import 'package:flutter/material.dart';

import '../users_list/models/users_list_model.dart';
import 'app_title.dart';

class UserListRow extends StatelessWidget {
  final UserModel userModel;
  final Function onTap;
  UserListRow({required this.userModel, required this.onTap});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            AppTitle(text: userModel.name),
            Text(
              userModel.email,
              style: TextStyle(color: Colors.black),
            ),
          ],
        ),
      ),
    );
  }
}

【问题讨论】:

  • 找出导致错误的代码行,并进行故障排除。想一想“不能将参数类型‘Function’分配给参数类型‘void Function()’”是什么意思。

标签: flutter dart


【解决方案1】:

最终功能 onTap;

在函数后面加上括号, 将上述代码更改为:

最终功能()?点击;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-07
    • 2018-11-07
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    相关资源
    最近更新 更多