在类State中声明了'File _image',并且编码意味着在小部件主体中声明了'null-> image'(Synchronous?)。但是这种编码是不合适的。 我该怎么办?
我什么也不能做。
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
class CreatePage extends StatefulWidget {
..@override
...._CreatePageState createState() => _CreatePageState();
}
class _CreatePageState extends State<CreatePage> {
..final textEditingController = TextEditingController();
..File _image;
..@override
..void dispose() {
....textEditingController.dispose();
....super.dispose();
..}
..@override
..Widget build(BuildContext context) {
....return Scaffold(
......appBar: _buildAppBar(),
......body: _buildBody(),
......floatingActionButton: FloatingActionButton(onPressed: _getImage,
......child: Icon(Icons.add_a_photo),
....),
....);
..}
..Widget _buildAppBar() {
....return AppBar(
......actions: <Widget>[
........IconButton(
..........icon: Icon(Icons.send), onPressed: () {},
..)
..],
..);
..}
Widget _buildBody() {
..return SingleChildScrollView(
.....child: Column(
.....children: <Widget>[
_image = null ? Text('No image'): Image.file(_image), // problem coding
.....TextField(
.....decoration: InputDecoration(hintText: 'write context'),
.....controller: textEditingController,
..)
..],
..),
..);
..}
Future _getImage() async {
..File image = await ImagePicker.pickImage(source: ImageSource.gallery);
..setState(() {
.._image = image;
..});
..}
..}
我看到了像填字笔这样的图像选择。
答案 0 :(得分:0)
替换
_image = null ? Text('No image'): Image.file(_image), // problem coding
使用
_image == null ? Text('No image'): Image.file(_image), // problem solved