Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error: No named parameter with the name 'videoId #905

Open
shreifragab opened this issue Jan 7, 2024 · 1 comment
Open

[BUG] Error: No named parameter with the name 'videoId #905

shreifragab opened this issue Jan 7, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@shreifragab
Copy link

Hello,

I have been facing this problem for over a month, and I haven't been able to find a solution so far. I have searched and used artificial intelligence tools like ChatGPT, Google Bard, and Github Copilot, but none of them could provide the appropriate solution.

When building my project with "flutter run," I encountered several issues due to the use of "youtube_player_iframe."

I have solved most of the problems, but there is one issue that I haven't been able to resolve yet. The error is as follows:

lib/screens/items/youtube_videos.dart:28:13: Error: No named parameter with the name 'videoId'.
            videoId:
            ^^^^^^^
/C:/Users/Sheko/AppData/Local/Pub/Cache/hosted/pub.dev/youtube_player_iframe-4.0.4/lib/src/controller/youtube_player_controller.dart:27:3: Context: Found this candidate, but the arguments don't match.
  YoutubePlayerController({
  ^^^^^^^^^^^^^^^^^^^^^^^
Target kernel_snapshot failed: Exception

FAILURE: Build completed with 2 failures.

Version:

  • Flutter: 3.18.0-0.2.pre • channel beta
  • Dart: 3.3.0-174.3.beta
  • youtube_player_iframe: 5.0.0

Here is the "youtube_videos.dart" file where the problems appear.

import 'package:flutter/material.dart';
import 'package:youtube_player_iframe/youtube_player_iframe.dart';
import 'package:be_app_mobile/models/side_item.dart';
import 'package:be_app_mobile/models/general.dart';
import 'package:be_app_mobile/helpers/font_helper.dart';

class YouTubeVideos extends StatefulWidget {
  const YouTubeVideos({Key? key, required this.item, required this.general})
      : super(key: key);

  final SideItem item;
  final General general;

  @override
  State<YouTubeVideos> createState() => _YouTubeVideosState();
}

class _YouTubeVideosState extends State<YouTubeVideos> {
  double size = 0.0;
  late List<YoutubePlayerController> _controllers;

  @override
  void initState() {
    super.initState();
    _controllers = widget.item.youtubeVideos
        .map<YoutubePlayerController>(
          (video) => YoutubePlayerController(
            videoId:
                YoutubePlayerController.convertUrlToId(video.videoUrl) ?? '',
            params: YoutubePlayerParams(
              showControls: !video.hideControls,
              showFullscreenButton: true,
              loop: video.isLive,
            ),
          ),
        )
        .toList();
  }

  @override
  void dispose() {
    for (var controller in _controllers) {
      controller.close();
    }
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: widget.general.getApplicationColor(),
      body: Stack(
        children: [
          ListView.separated(
            itemBuilder: (context, index) {
              return Column(
                children: [
                  YoutubePlayer(
                    controller: _controllers[index],
                    aspectRatio: 16 / 9,
                  ),
                  Stack(
                    children: [
                      Container(
                        color: Colors.black,
                        height: 80,
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 10),
                        child: Text(
                          widget.item.youtubeVideos[index].videoTitle,
                          overflow: TextOverflow.ellipsis,
                          maxLines: 2,
                          style: getFontStyle(16, Colors.white,
                              FontWeight.normal, widget.general),
                        ),
                      ),
                    ],
                  )
                ],
              );
            },
            itemCount: _controllers.length,
            separatorBuilder: (context, _) {
              return SizedBox(height: size);
            },
          ),
        ],
      ),
    );
  }
}
@shreifragab shreifragab added the bug Something isn't working label Jan 7, 2024
@shreifragab shreifragab changed the title [BUG] [BUG] Error: No named parameter with the name 'videoId Jan 7, 2024
@Hsiao-Chien-Ti
Copy link

Hsiao-Chien-Ti commented Feb 21, 2024

I guess you are mixing two different packages.
Both youtube_player_flutter and youtube_player_iframe have YoutubePlayerController.
However, videoId only exists in youtube_player_flutter and params only exists in youtube_player_iframe.
You can instead use another function:

    _youtubeController = YoutubePlayerController.fromVideoId(
      videoId: widget.videoId,
      autoPlay: true,
      params: const YoutubePlayerParams(loop: true, showFullscreenButton: true)
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants