'How to play list(array) of videos from firebase :In my case I tried with lot of changes but I get this error

Here there are my two Dart file from that I retrieve my Video from firestore but in that, I made video array and try to retrieve it but it gives me an error , if I am doing it with string instead of array It looks fine but in my project, I am requiring array so please help me to finger out.

My cloud firestore looks like is: collection(Course)=>autoid=>doucuments(video array)=>([0]url [1]url2)

Here is my 2 Dart file please correct my code what is wrong in this case when I am running this I got error Like :

Error: list is not a subtype of type 'string'.

code:main.dart and chewie_list_item.dart

     main.dart:It is for retrieve data

   import 'chewie_list_item.dart';
        import 'package:flutter/foundation.dart';
        import 'package:flutter/material.dart';
        import 'package:cloud_firestore/cloud_firestore.dart';`enter code here`
        import 'package:video_player/video_player.dart';
        
        void main() {
          FlutterError.onError = (FlutterErrorDetails details) {
            FlutterError.dumpErrorToConsole(details);
            if (kReleaseMode) exit(1);
          };
        
          runApp(MaterialApp(
            home: CourseApp(),
          ));
        }
        
        class CourseApp extends StatelessWidget {
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context) {
            return Scaffold(
                appBar: AppBar(
                  title: Text("Flutter Demo"),
                ),
                body: StreamBuilder(
                  stream: Firestore.instance.collection("courses").snapshots(),
                  builder: (context, snapshot) {
                    return ListView.builder(
                      itemCount: snapshot.data.documents.length,
                      itemBuilder: (context, index) {
                        DocumentSnapshot courses = snapshot.data.documents[index];
                        return (ChewieListItem(
                          videoPlayerController: VideoPlayerController.network(
                              courses['video'] ?? 'default'),
                        ));
                      },
                    );
                  },
                ));
          }
        }
        
        [code 2: chewie_list_item.dart]: It for chewie video player. 
        
        import 'package:chewie/chewie.dart';
        import 'package:flutter/material.dart';
        import 'package:video_player/video_player.dart';
        
        class ChewieListItem extends StatefulWidget {
          // This will contain the URL/asset path which we want to play
          final VideoPlayerController videoPlayerController;
          final bool looping;
        
          ChewieListItem({
            @required this.videoPlayerController,
            this.looping,
            Key key,
          }) : super(key: key);
        
          @override
          _ChewieListItemState createState() => _ChewieListItemState();
        }
        
        class _ChewieListItemState extends State<ChewieListItem> {
          ChewieController _chewieController;
        
          @override
          void initState() {
            super.initState();
            // Wrapper on top of the videoPlayerController
            _chewieController = ChewieController(
              videoPlayerController: widget.videoPlayerController,
              aspectRatio: 16 / 9,
              // Prepare the video to be played and display the first frame
              autoInitialize: true,
              looping: widget.looping,
              // Errors can occur for example when trying to play a video
              // from a non-existent URL
              errorBuilder: (context, errorMessage) {
                return Center(
                  child: Text(
                    errorMessage,
                    style: TextStyle(color: Colors.white),
                  ),
                );
              },
            );
          }
        
          @override
          Widget build(BuildContext context) {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: Chewie(
                controller: _chewieController,
              ),
            );
          }
        
          @override
          void dispose() {
            super.dispose();
            // IMPORTANT to dispose of all the used resources
            widget.videoPlayerController.dispose();
            _chewieController.dispose();
          }
        }
    
    

So mainly I have not any idea hoe to retrieve this video array from my firebase please give the correct code.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source