Open elompo23 opened 3 years ago
I think it may be the way I have been uploading the audio and images, anything would help.
I think you should upgrade the versions of libraries mentioned in pubspec file, or try to upload the small song file. Hope it works for you.
On Mon, Feb 22, 2021, 9:15 AM elompo23 notifications@github.com wrote:
I think it may be the way I have been uploading the audio and images, anything would help.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gaurangkeluskar22/Basic-Music-Player-App/issues/3#issuecomment-783055803, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKNI75NFEOKRAWPWVFZODJDTAHHM3ANCNFSM4X7XA5OA .
Here is my code (I added some code for my app):
import 'dart:io'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:file_picker/file_picker.dart'; import 'package:firebase_storage/firebase_storage.dart'; import 'package:flutter/material.dart'; import 'package:CampFire/pages/home.dart'; import 'widget.dart'; import 'package:path/path.dart';
class Upload extends StatefulWidget { @override _UploadState createState() => _UploadState(); }
class _UploadState extends State {
TextEditingController songname = TextEditingController();
TextEditingController artistname = TextEditingController();
File image, song; String imagepath, songpath; Reference ref; var image_down_url; var song_down_url; final firestoreinstance = FirebaseFirestore.instance;
void selectimage() async { FilePickerResult result = await FilePicker.platform.pickFiles();
}
Future uploadimagefile(List image, String imagepath) async {
ref = FirebaseStorage.instance.ref().child(imagepath);
UploadTask uploadTask = ref.putData(image);
return image_down_url = await (await uploadTask).ref.getDownloadURL(); }
void selectsong() async { FilePickerResult result = await FilePicker.platform.pickFiles();
}
Future uploadsongfile(List song, String songpath) async {
ref = FirebaseStorage.instance.ref().child(songpath);
UploadTask uploadTask = ref.putData(song);
return song_down_url = await (await uploadTask).ref.getDownloadURL(); }
finalupload(context) { if (songname.text != '' && song_down_url != null && image_down_url != null) { print(songname.text); print(artistname.text); print(song_down_url.toString()); print(image_down_url.toString());
}
_onTapButton(BuildContext context, data) { return AlertDialog(title: Text(data)); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( "CampFire", style: TextStyle(fontSize: 20), ), actions: [ GestureDetector( onTap: () { Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => Home())); }, child: Container( padding: EdgeInsets.symmetric(horizontal: 16), child: Icon(Icons.exit_to_app))) ], ), body: Column( children:[
RaisedButton(
onPressed: () => selectimage(),
child: Text("Select Image"),
),
RaisedButton(
onPressed: () => selectsong(),
child: Text("Select Audio"),
),
Padding(
padding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
child: TextField(
controller: songname,
style: TextStyle(color: Colors.white),
decoration: textFieldInputDecoration("Enter a song name"),
),
),
Padding(
padding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
child: TextField(
controller: artistname,
style: TextStyle(color: Colors.white),
decoration: textFieldInputDecoration("Enter artist name"),
),
),
RaisedButton(
onPressed: () => finalupload(context),
child: Text("Upload"),
)
],
));
}
}