Este Es Mi Codigo
import 'dart:ui';
import 'package:image_picker/image_picker.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:social/MyHomePage.dart';
class NuevaPublicacion extends StatefulWidget {
String US;
NuevaPublicacion(this.US);
@override
_NuevaPublicacionState createState() => _NuevaPublicacionState();
}
var _image;
class _NuevaPublicacionState extends State<NuevaPublicacion> {
var muestra;
var file;
final Titulo = TextEditingController();
final Descripcion = TextEditingController();
String Crea = DateTime.now().day.toString() + "/" + DateTime.now().month.toString() + "/" +DateTime.now().year.toString() + " " +
DateTime.now().hour.toString() + ":" +DateTime.now().minute.toString();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.black,
title: Text('Nueva Publicacion'),
),
body: Center(
child: SingleChildScrollView(
child: Column(
children: [
Container(
width: 500,
child: TextField(
maxLength: 60,
controller: Titulo,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
obscureText: false,
autocorrect: true,
textCapitalization: TextCapitalization.sentences,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.black,
fontStyle: FontStyle.italic,
fontSize: 16,
),
cursorColor: Colors.black,
decoration: InputDecoration(
hintText: "Titulo",
hintStyle:
TextStyle(color: Colors.black.withOpacity(0.5)),
helperText: "Titulo de la publicacion",
contentPadding: EdgeInsets.all(5),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
borderSide: BorderSide(
color: Colors.black,
width: 1,
)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: Colors.red,
width: 1,
)))),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 5),
),
_image == null?
Image.asset('assets/mundogris.png',height: 200,):
Image.network(muestra,height: 100,),
OutlinedButton.icon(
onPressed: () async {
ElegirImagen();
}, icon: Icon(Icons.image_outlined,
color: Colors.black,),
label: Text('Elegir Imagen',style: TextStyle(
color: Colors.black
),
)
),
Padding(
padding: EdgeInsets.symmetric(vertical: 5),
),
Container(
width: 500,
child: TextField(
maxLength: 500,
maxLines: 10,
controller: Descripcion,
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
obscureText: false,
autocorrect: true,
textCapitalization: TextCapitalization.sentences,
textAlign: TextAlign.start,
style: TextStyle(
color: Colors.black,
fontStyle: FontStyle.italic,
fontSize: 16,
),
cursorColor: Colors.black,
decoration: InputDecoration(
hintText: "Descripcion",
hintStyle:
TextStyle(color: Colors.black.withOpacity(0.5)),
helperText: "Descripcion de la publicacion",
contentPadding: EdgeInsets.all(5),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
borderSide: BorderSide(
color: Colors.black,
width: 1,
)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
borderSide: BorderSide(
color: Colors.red,
width: 1,
)))),
),
],
),
)
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () async {
if(!Titulo.text.isEmpty || !Descripcion.text.isEmpty
|| !_image == null
){
UploadTask UT = FirebaseStorage.instance.ref(
'Fotos de =>' + widget.US).child(Crea).putFile(_image);
var url = await (await UT).ref.getDownloadURL();
var _imageUrl = url.toString();
FirebaseFirestore.instance
.collection('Familia')
.doc(widget.US).collection('Publicaciones').doc(Crea)
.set({
'Titulo': Titulo.text,
'Imagen': _imageUrl,
'Descripcion': Descripcion.text,
});
Titulo.clear();
Descripcion.clear();
_imageUrl = " ";
Navigator.of(context).pop();
Navigator.of(context).push(MaterialPageRoute<Null>(
builder: (BuildContext context) {
return MyHomePage(widget.US);
}, //fullscreenDialog: true,
));
}
}, label: Text('Publicar',style: TextStyle(color: Colors.white),),
tooltip: 'Subir Publicacion...',
icon: Icon(Icons.upload_outlined,color: Colors.white,),
backgroundColor: Colors.black,
),
);
}
Future<void> ElegirImagen() async {
final ImagePicker _picker = ImagePicker();
var image = await _picker.pickImage(source: ImageSource.gallery);
setState((){
_image = image;
muestra = image!.path;
});
}
}
ESTE ES EL ERROR
Error: Expected a value of type 'File', but got one of type 'XFile'
Veo la imagen correctamente asignada al widget que tiene q mostrarla en pantalla pero cuando quiero subirla a cloud firestore me da ese error. busque otros paquetes de picking images pero todos tiene diferentes formatos de archivo ninguno de los que vi para WEB me resuelve el problema de tener que convertir el formato que devuelven en file par apoder subirlo, sera que no estoy usando el codigo correcto para subir la imagen a firestore?
mil gracias por leerme.