错误:参数类型“void Function()?”不能分配给参数类型“void Function(String?)?”

时间:2021-06-18 10:29:25

标签: flutter dart

错误很简单我不知道如何解决问题请帮忙

import 'package:flutter/material.dart';

class CheetahInput extends StatelessWidget {
  final String? labelText;
  final VoidCallback? onSaved;

  CheetahInput({@required this.labelText, @required this.onSaved});

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      decoration: InputDecoration(
        fillColor: Colors.white,
        filled: true,
        labelText: labelText,
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(16),
        ),
        floatingLabelBehavior: FloatingLabelBehavior.never,
      ),
      initialValue: '',
      validator: (String? value) {
        return value!.isEmpty ? '$labelText is required' : null;
      },
      onSaved: onSaved,
    );
  }
}

我试图用尖括号指定类型,但没有用 感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

替换

final VoidCallback? onSaved;

final Function(String)? onSaved;

答案 1 :(得分:0)

替换

final VoidCallback? onSaved;

final FormFieldSetter<String>? onSaved;