環境
flutter2.2.3手順
pubspec.yamlに下記を追加します。image_picker: ^0.8.1+3
実装ファイルで下記をインポートします。
import 'dart:io';
import 'package:image_picker/image_picker.dart';
実装dartファイルのState内で下記を実装します。
File? _image;
final picker = ImagePicker();
Future getImageFromGallery() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
_image = File(pickedFile!.path);
});
}
実装dartファイルのUserAccountsDrawerHeader内で下記プロパティを実装します。
currentAccountPicture: GestureDetector(
onTap: () => getImageFromGallery(),
child: CircleAvatar(
backgroundColor: Colors.black54,
child: _image == null
? Icon(Icons.photo_camera, color: Colors.white)
: Image.file(_image!),
),
)
エミュレータでギャラリーに画像を準備する手順


ここでpngファイルなどをドラッグ&ドロップ 