0

Getting an exception saying _TypeError (type 'List<dynamic>' is not a subtype of type 'List<Widget>') in .toList() below.

import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:student_community/app/constants/colors.dart';
import 'package:student_community/app/constants/dimensions.dart';
import 'package:student_community/core/viewmodels/video_view_model.dart';
import 'package:student_community/meta/widgets/loading_widget.dart';

class VideoView extends StatelessWidget {
  final ScrollController scrollController = ScrollController();
  @override
  Widget build(BuildContext context) {
    return Consumer<VideoViewModel>(
        builder: (context, model, child) => Scaffold(
              resizeToAvoidBottomInset: true,
              backgroundColor: bgColor,
              body: StreamBuilder<QuerySnapshot>(
                stream: model.streamOfVideos(),
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.waiting) {
                    return loadingWidget();
                  } else {
                    return listOfVideos(snapshot, context);
                  }
                },
              ),
            ));
  }

  Widget listOfVideos(dynamic querySnapshot, BuildContext context) {
    return Scrollbar(
      controller: scrollController,
      isAlwaysShown: false,
      child: ListView(
        children: querySnapshot.data.docs
            .map((DocumentSnapshot documentSnapshot) =>
                blockOfVideo(context, documentSnapshot))
            .toList(),

      ),
    );
  }

  Widget blockOfVideo(BuildContext context, DocumentSnapshot documentSnapshot) {
    return GestureDetector(
      onTap: () {}, //Proxy provider of detailed screen,
      child: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Stack(
              children: [
                Container(
                  height: MediaQuery.of(context).size.height * 0.3,
                  width: MediaQuery.of(context).size.width,
                  decoration: BoxDecoration(
                      image: DecorationImage(
                          image: NetworkImage(
                              documentSnapshot.data()['thumbnail']))),
                ),
                Positioned(
                    top: 195,
                    left: 355,
                    child: Container(
                      child: Center(
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Text(
                            documentSnapshot.data()['length'],
                            style: TextStyle(
                                color: whiteColor, fontWeight: FontWeight.bold),
                          ),
                        ),
                      ),
                      decoration: BoxDecoration(
                          color: darkColor,
                          borderRadius: BorderRadius.circular(4.0)),
                    ))
              ],
            ),
            Row(
              children: [
                CircleAvatar(
                  backgroundImage:
                      NetworkImage(documentSnapshot.data()['userimage']),
                ),
                hSizedBox2,
                Container(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        documentSnapshot.data()['title'],
                        style: TextStyle(
                            fontSize: 20.0,
                            color: whiteColor,
                            fontWeight: FontWeight.bold),
                      ),
                      Text(
                        documentSnapshot.data()['username'],
                        style: TextStyle(
                            fontSize: 16.0,
                            color: yellowColor,
                            fontWeight: FontWeight.bold),
                      )
                    ],
                  ),
                ),
                Spacer(),
                IconButton(
                    icon: Icon(
                      EvaIcons.moreVertical,
                      color: whiteColor,
                    ),
                    onPressed: () {})
              ],
            ),
            Divider()
          ],
        ),
      ),
    );
  }
}
3
  • 2
    Does this answer your question? type 'List<dynamic>' is not a subtype of type 'List<Widget>' Commented Jul 4, 2021 at 14:38
  • Thank you very much raina77ow it fixed my problem. Commented Jul 4, 2021 at 14:56
  • One thing I love very much about Stack overflow is we get response within 24 hours. And I am new to Stack overflow. This is my 4th question here and I got a very good response from you all. Thank you very much Stack overflow and it's community. Commented Jul 4, 2021 at 15:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.