Reputation:
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'.
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,
),
Upvotes: 2
Views: 5779
Reputation: 119
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
Upvotes: 0
Reputation: 510
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);
Upvotes: 5
Reputation: 1178
Pass a UniqueKey
to CreateProfile
like this.
CreateProfile(key: UniqueKey())
Upvotes: 2