https://pub.dev/packages/image_picker/install
image_picker: ^0.8.4+4
android:requestLegacyExternalStorage=”true”
エラーの解決方法を教えてください。
ソース
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File _image;
final picker = ImagePicker();
Future _getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() { if (pickedFile != null) { _image = File(pickedFile.path); } else { print('No image selected.'); } });
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: _image == null ? Text('No image selected.') : Image.file(_image),
),
floatingActionButton: FloatingActionButton(
onPressed: _getImage,
child: Icon(Icons.image),
),
);
}
}
エラー
error: The parameter 'title' can't have a value of 'null' because of its type, but the implicit default value is 'null'. (missing_default_value_for_parameter at [image_picker] lib\main.dart:25)
error: The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'. (missing_default_value_for_parameter at [image_picker] lib\main.dart:25)
error: Non-nullable instance field '_image' must be initialized. (not_initialized_non_nullable_instance_field at [image_picker] lib\main.dart:34)
error: The method 'ImagePicker' isn't defined for the type '_MyHomePageState'. (undefined_method at [image_picker] lib\main.dart:35)
error: Undefined name 'ImageSource'. (undefined_identifier at [image_picker] lib\main.dart:38)
error: The constructor being called isn't a const constructor. (const_with_non_const at [image_picker] test\widget_test.dart:16)
あなたの回答
tips
プレビュー