Click here to Skip to main content
15,567,482 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made a listview builder following a course in which I kept an elevated button(which adds video through image picker) to be index 0 and then videos shall be showed at index 0. My elevated button is not showing.

I made same code for image picker but did not happen in that case.

The listview builder is in the scaffold. There is not any error showing up in debug console

class _addVideoState extends State<addVideo> {
  bool uploading = false;
  double val = 0;
  CollectionReference? vidRef;
  firebase_storage.Reference? ref;
  File? video;
  VideoPlayerController? videoPlayerController;
  VideoPlayerController? INvideoPlayerController;

  final picker = ImagePicker();

  

  List<File> _video = [];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Add video'),
        actions: [
          ElevatedButton(
            onPressed: () {
              setState(() {
                uploading = true;
              });

              uploadFile().whenComplete(() => Navigator.of(context).pop());
            },
            child: const Text(
              'Upload Video',
              style: TextStyle(color: Colors.red),
            ),
          )
        ],
      ),
      body: ListView.builder(
          itemCount: _video.length + 1,
          itemBuilder: (ctx, index) {
            INvideoPlayerController = VideoPlayerController.file(_video[index])
              ..setLooping(true)
              ..initialize().then((value) => INvideoPlayerController!.play());
            return index == 0
                ? Center(
                    child: ElevatedButton(
                         onPressed: () {
                           !uploading ? chooseVideo() : null;
                           print(_video);
                         },
                         child: const Text(
                           'Test',
                           style: TextStyle(color: Colors.black),
                         )),                    
                  )
                : AspectRatio(
                    aspectRatio: INvideoPlayerController!.value.aspectRatio,
                    child: VideoPlayer(INvideoPlayerController!),
                  );
            
          }),
    );
  }

  chooseVideo() async {
    ImagePicker picker = ImagePicker();

    final pickedFile = await picker.pickVideo(source: ImageSource.gallery);

    setState(() {
      _video.add(File(pickedFile!.path));
    });
    videoPlayerController = VideoPlayerController.file(File(pickedFile!.path))
      ..addListener(() => setState(() {
            
          }))
      ..setLooping(true)
      ..initialize().then((_) {
       
        setState(() {});
        videoPlayerController!.play();
      });
    print(pickedFile.path);
    print(File(pickedFile.path));
    print('Kavya-choosevideo-videoPlayerController :   $videoPlayerController');
    if (pickedFile.path == null) retrieveLostData();
  }

  Future<void> retrieveLostData() async {
    final LostDataResponse = await ImagePicker.platform.getLostData();
    if (LostDataResponse.isEmpty) {
      return;
    }
    if (LostDataResponse != null) {
      setState(() {
        _video.add(File(LostDataResponse.file!.path));
      });
    } else {
      print(LostDataResponse.file);
    }
  }

  Future uploadFile() async {
    int i = 1;

    for (var vid in _video) {
      setState(() {
        val = i / _video.length;
      });
   
      ref = firebase_storage.FirebaseStorage.instance
          .ref()
          .child('videos/${Path.basename(vid.path)}');
      await ref!.putFile(vid).whenComplete(() async {
       
        await ref!.getDownloadURL().then((value) {
          vidRef!.add({
            'url': value
          }); 
          i++;  
        });
      });
    }
  }

  @override
  void initState() {
    super.initState();
    vidRef = FirebaseFirestore.instance.collection(
        'Videourls'); 
    INvideoPlayerController = VideoPlayerController.network('')
      ..addListener(() {})
      ..setLooping(true)
      ..initialize().then((value) => INvideoPlayerController!.play());
  }
}


What I have tried:

I have tried Fitting all of it in a column with an elevated button above listview that is giving a lot of errors just because of nesting a listview inside a column and also some range errors
Posted
Updated 17-Mar-22 9:54am
v3
Comments
wseng 6-Mar-22 3:50am    
try check your index. Did you get 0?
Kavya Bhargava 6-Mar-22 6:26am    
Yes I did I am getting 0 but can not see the elevated button on the screen
wseng 6-Mar-22 12:14pm    
did you try to replace it with Text()? Does it appear?
Kavya Bhargava 10-Mar-22 14:52pm    
No, it does not
wseng 10-Mar-22 21:51pm    
post full code here

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900