I have no idea what this error message means:
lib/main.dart:29:19: Error: The argument type ‘Object’ can’t be
assigned to the parameter type ‘Widget?’.
‘Object’ is from ‘dart:core’.
‘Widget’ is from ‘package:flutter/src/widgets/framework.dart’ >(‘../../flutter/packages/flutter/lib/src/widgets/framework.dart’).
? Image.network(‘https://picsum.photos/200/300’)
^
Failed to compile application.
body: GridView.count(
// Create a grid with 2 columns. If you change the scrollDirection to
// horizontal, this produces 2 rows.
crossAxisCount: 2,
// Generate 100 widgets that display their index in the List.
children: List.generate(100, (index) {
return Center(
child: index % 2 == 0
? Image.network('https://picsum.photos/200/300')
: VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
),
);
}),
),
2
Answers
I wrapped VideoPlayerController object with VideoPlayer widget. So that solved above error message. I can only see the images and no videos though.
It seems like you are using the video_player package, so keep in mind that VideoPlayerController.network returns a controller, not a Widget and that’s why you are getting that error.
Documentation here: https://pub.dev/packages/video_player
Long story short, you need to use a VideoPlayer instead of the VideoPlayerController, something like this:
Initialize the controller:
using the controller to return a widget:
I would recommend you to read the documentation