Skip to content

Instantly share code, notes, and snippets.

@pavanjoshi914
Created December 6, 2021 06:40
Show Gist options
  • Save pavanjoshi914/917994b8d30ef847704a327ac9787fcd to your computer and use it in GitHub Desktop.
Save pavanjoshi914/917994b8d30ef847704a327ac9787fcd to your computer and use it in GitHub Desktop.
Scaffold(
floatingActionButton: buildSaveDeletebutton()
);
buildSaveDeletebutton() {


    if(fileExist)
      return buildButton(icon: Icon(Icons.delete), function: deleteButton);
    else
      return buildButton(icon: Icon(Icons.save), function: SaveButton);

}
FloatingActionButton buildButton({required Icon icon, required Function function}) {

    return  FloatingActionButton(
        backgroundColor: Colors.teal,
      
        child: icon ,

        onPressed: () =>
                function

          );

}


   deleteButton() async {
    // video file is passed in widget 
    final originalVideoFile = File(widget.videoFile);

    String fileName = p.basename(originalVideoFile.path);

    final newFileName =
        '/storage/emulated/0/directory/$fileName';
        
        
      // dialog function
     _onLoading(true, '');

    if(fileExist){
      await  File(newFileName).delete();

      _onLoading(
        false,
        'File delete successfully present at',
      );
  }

}

  SaveButton() async {


    final originalVideoFile = File(widget.videoFile);
    
    String fileName = p.basename(originalVideoFile.path);

    final newFileName =
        '/storage/emulated/0/directory/$fileName';
    _onLoading(true, '');
    if(!fileExist){
      await originalVideoFile.copy(newFileName);

      // show dialog when button is pressed
      _onLoading(
        false,
        'If Video not available in gallary\n\nYou can find all videos at',
      );
    }

  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment