首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少StatelessWidget的具体实现

缺少StatelessWidget的具体实现
EN

Stack Overflow用户
提问于 2021-04-03 23:17:35
回答 2查看 36关注 0票数 0

这个页面是我的PhotoPreviewScreen,单击下面代码中的按钮后,我将来自相机屏幕的照片发送到主页。

我得到了一些有趣的错误,我以前没有见过,在文档中很少,在屏幕截图中。以前有没有人见过这些?我该怎么纠正呢?

代码语言:javascript
复制
import 'package:flutter/material.dart';
import 'dart:io';

class PhotoPreviewScreen extends StatelessWidget {
  Function setData;
  PhotoPreviewScreen({Key key, this.setData}) : super(key: key);
}

class _PhotoPreviewScreenState extends State<PhotoPreviewScreen> {
  final String imagePath;
  var image;

  Future _openGallery() async {}


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () => Navigator.pop(
            context), // Go back to the camera to take the picture again
        child: Icon(Icons.camera_alt),
      ),
      appBar: AppBar(title: Text('Photo Preview')),
      body: Column(children: [
        Expanded(child: Image.file(File(imagePath))),
        const SizedBox(height: 16.0),
        OutlineButton(
          onPressed: () {
            _openGallery();
            Navigator.pop(context);
          },
          child: Text('Okay'),
          borderSide: BorderSide(
              color: Color(
                  0xff33333D)), 
        ),
      ]),
    );
  }
}

错误

EN

回答 2

Stack Overflow用户

发布于 2021-04-03 23:24:51

代码语言:javascript
复制
class PhotoPreviewScreen extends StatefulWidget {Function setData;   PhotoPreviewScreen({Key key, this.setData}) : super(key: key); }

我想应该是"StatefulWidget“而不是"StatelesWidget”。

票数 0
EN

Stack Overflow用户

发布于 2021-04-04 01:17:12

试试下面的代码片段:

代码语言:javascript
复制
import 'package:flutter/material.dart';
import 'dart:io';

class PhotoPreviewScreen extends StatefulWidget {
  Function setData;
  PhotoPreviewScreen({Key key, this.setData}) : super(key: key);

_PhotoPreviewScreenState createState() => _PhotoPreviewScreenState();
}

class _PhotoPreviewScreenState extends State<PhotoPreviewScreen> {
  final String imagePath = ' ';
  var image;

  Future _openGallery() async {}


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        onPressed: () => Navigator.pop(
            context), // Go back to the camera to take the picture again
        child: Icon(Icons.camera_alt),
      ),
      appBar: AppBar(title: Text('Photo Preview')),
      body: Column(children: [
        Expanded(child: Image.file(File(imagePath))),
        const SizedBox(height: 16.0),
        OutlineButton(
          onPressed: () {
            _openGallery();
            Navigator.pop(context);
          },
          child: Text('Okay'),
          borderSide: BorderSide(
              color: Color(
                  0xff33333D)), 
        ),
      ]),
    );
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66932716

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档