Flutter - The argument type 'Null' can't be assigned to the parameter type 'Function'

Maahdi.Codes

I was trying to connect my existing screens with the image picker plugin. But for some reason, I am getting the error showing "The argument type 'Null' can't be assigned to the parameter type 'Function'." The code of the button where I used the onSelectVideo and null -

ElevatedButton(
                child: Text(
                  'Next',
                  style: TextStyle(fontSize: 17, color: Colors.white),
                ),
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => video_record02(
                              onSelectVideo: null,
                            ),
                    ),
                  );
                },
              ),

Now the thing is I know I don't need to use the null here. But I can't figure out what to use instead of null. The starting code of the next screen is like this -

class video_record02 extends StatefulWidget {
  final Function onSelectVideo;

  const video_record02({Key? key, required this.onSelectVideo})
      : super(key: key);

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

class _video_record02State extends State<video_record02> {
  File? storedImage;

  Future<void> takeVideo() async {
    final picker = ImagePicker();
    final videoFile = await picker.pickVideo(
      source: ImageSource.camera,
      preferredCameraDevice: CameraDevice.rear,
      maxDuration: Duration(
        seconds: 25,
      ),
    );
    if (videoFile == null) {
      return;
    }
    final rlyvideoFile = File(videoFile.path);
    setState(() {
      storedImage = rlyvideoFile;
    });
    final appDir = await syspaths.getApplicationDocumentsDirectory();
    final fileName = path.basename(rlyvideoFile.path);
    final savedImage = await rlyvideoFile.copy('${appDir.path}/$fileName');
    widget.onSelectVideo(savedImage);
  }

When I remove the null it shows I need an identifier but I can't make it work. As I am a novice learner in the flutter, I'll appreciate it if you help me solve this issue.

Miftakhul Arzak

Change null on onSelectedVideo like this onSelectedVideo:(savedImage){}

ElevatedButton(
                child: Text(
                  'Next',
                  style: TextStyle(fontSize: 17, color: Colors.white),
                ),
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => video_record02(
                              onSelectVideo: (savedImage){
                              //fill some code you want to execute if the video was selected
                              },
                            ),
                    ),
                  );
                },
              ),

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

argument type 'Null' can't be assigned to the parameter type FLUTTER GETX

Flutter / Dart Error: The argument type 'Null Function(Key)' can't be assigned to the parameter type 'void Function(Object)'

flutter The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?' in flutter

the argument type 'Zone?' can't be assigned to the parameter type 'Zone' in flutter

The Argument type 'Context' can't be assigned to the parameter type 'BuildContext' - Flutter

Flutter listener error The argument Type can't be assigned to the parameter type

The argument type 'String' can't be assigned to the parameter type 'Uri'. Flutter

Flutter : The argument type 'Image' can't be assigned to the parameter type 'IconData'

The argument type 'Object?' can't be assigned to the parameter type 'num' in flutter

The argument type 'Icon' can't be assigned to the parameter type 'IconData in Flutter

The argument type 'Text' can't be assigned to the parameter type 'Text?' Flutter

Flutter - Argument of type function can't be assigned to the parameter of type `void function()`

Flutter error: The argument type 'Future<Object?> Function()' can't be assigned to the parameter type 'FutureOr<dynamic> Function(dynamic)'

The argument type 'Widget Function()' can't be assigned to the parameter type 'String? Function(String?)?' In flutter

The argument type 'void Function(String?)?' can't be assigned to the parameter type 'String? Function(String?)? in Flutter

The argument type 'void Function(Hospital)' can't be assigned to the parameter type 'void Function(Object?)?'. Flutter Dropdown

The argument type 'Function?' can't be assigned to the parameter type 'void Function()?'

The argument type 'Function' can't be assigned to the parameter type 'void Function()?

The argument type 'Function' can't be assigned to the parameter type 'void Function()?'

Flutter null safety - The argument type 'Color?' can't be assigned to the parameter type 'Color'

flutter null safety The argument type 'String?' can't be assigned to the parameter type 'String'

The argument type 'Null' can't be assigned to the parameter type 'String'. Flutter Issue

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

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 'PatientPrescription'

The argument type 'Null' can't be assigned to the parameter type 'QuerySnapshot<Object?>'

The argument type 'Future<Null> Function(String)' can't be assigned to the parameter type 'void Function(NotificationResponse)'

Flutter: The argument type 'HomePage Function(BuildContext, Map<String, dynamic>)' can't be assigned to the parameter type

Flutter/Dart The argument type 'Future<bool?> Function()' can't be assigned to the parameter type 'Future<bool>