Home > other >  The argument type 'Null' can't be assigned to the parameter type 'Key'
The argument type 'Null' can't be assigned to the parameter type 'Key'

Time:02-08

I want to call CreateProfile() in my main.dart.. but it gives me an error.. the below image showing the error in main.dart and I have included my createprofile.dart code for you to refer.

The argument type 'Null' can't be assigned to the parameter type 'Key'.

error

starting code of CreateProfile.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:convert';
import 'package:http/http.dart' ;

class CreateProfile extends StatefulWidget {
  CreateProfile({required Key key}) : super(key: key);

  @override
  _CreateProfileState createState() => _CreateProfileState();
}

class _CreateProfileState extends State<CreateProfile> {

  bool circular = false;
  PickedFile? _imageFile;
  final ImagePicker _picker = ImagePicker();

  final _globalkey = GlobalKey<FormState>();

  TextEditingController _name = TextEditingController();
  TextEditingController _profession = TextEditingController();
  TextEditingController _dob = TextEditingController();
  TextEditingController _title = TextEditingController();
  TextEditingController _about = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Form(
        key: _globalkey,
        child: ListView(
          padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
          children: <Widget>[
            imageProfile(),
            SizedBox(
              height: 20,
            ),

CodePudding user response:

This error occurred because you used the required keyword in CreateProfile.dart. If you want to pass a null value as the key you can change the constructor like this :

  CreateProfile({Key? key}) : super(key: key);

CodePudding user response:

Pass a UniqueKey to CreateProfile like this.

CreateProfile(key: UniqueKey())

CodePudding user response:

You can use ValueKey: A key that uses a simple value such as a String. You can learn more here -> https://www.youtube.com/watch?v=kn0EOS-ZiIc

CodePudding user response:

CreateProfile({required Key key}) : super(key: key);

Remove this line. It's not needed.

  •  Tags:  
  • Related