gpt4 book ai didi

flutter - 错误 : A value of type 'Widget' can't be assigned to a variable of type 'File'

转载 作者:IT王子 更新时间:2023-10-29 07:15:51 25 4
gpt4 key购买 nike

'File _image' 在类 State 中声明,编码意味着在 Widget 主体中声明'null -> image'(同步?)。但这种编码不合适。 我该怎么办?

我什么也做不了。

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;
..});
..}
..}

我看到图像的选择就像 instargram 的写作。

最佳答案

替换

_image = null ? Text('No image'): Image.file(_image), // problem coding

_image == null ? Text('No image'): Image.file(_image), // problem solved

关于flutter - 错误 : A value of type 'Widget' can't be assigned to a variable of type 'File' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57411426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com