Lorsque je sélectionne une image dans le sélecteur d'images, j'obtiens cette erreur le fichier de type n'est pas un sous-type de type 'imageprovider dynamic'
J'ai essayé d'utiliser stack même si la même erreur
class _ProfileState extends State<Profile> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: true,
title: Text('Profile'),
centerTitle: true,
elevation: 10.0,
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: _imageFile == null
? AssetImage('assets/tom.jpg')
: _imageFile,
fit: BoxFit.cover)),
child: ListView(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height / 1.4,
),
Card(
color: Colors.grey.withOpacity(0.1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: cameraAndEdit(context),
),
Container(
width: MediaQuery.of(context).size.width,
color: Colors.white70,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
box(),
line(color: Colors.deepPurple, lineHeight: 5.0),
// nameDesignation(),
infoRow(
infoIcon: Icon(Icons.person),
infoText: 'Name',
detail: 'Tom Cruise',
textColor: Colors.black),
Divider(),
infoRow(
infoIcon: Icon(Icons.location_on),
infoText: 'Address',
detail: '#9/1 1st main Circle street Bangalore 560-096',
textColor: Colors.black),
Divider(),
infoRow(
infoIcon: Icon(Icons.gesture),
infoText: 'Age',
detail: '25',
textColor: Colors.black),
Divider(),
infoRow(
infoIcon: Icon(Icons.phone),
infoText: 'Phone',
detail: '+91 9148046273',
textColor: Colors.black),
line(color: Colors.deepPurple, lineHeight: 5.0),
box(),
],
),
),
),
],
),
),
);
}
3 Réponses :
image: _imageFile == null
? AssetImage('assets/tom.jpg')
: FileImage(_imageFile),
Si vous avez utilisé image_picker , essayez le code ci-dessous.
import 'package:image_picker/image_picker.dart';
PickedFile _imageFile;
image: _imageFile == null
? AssetsImage("sample_image_path")
: FileImage(File(_imageFile.path)),
Ce code m'a sauvé la journée. Merci beaucoup mec.
Si vous chargez l'image à partir du réseau et dans une BoxDecoration , vous devez utiliser NewtworkImage ('...') et non Image.network ( '...')
Exemple:
decoration: BoxDecoration(
image: DecorationImage(image: NetworkImage("imageUrl"),
fit: BoxFit.cover)
),