Image 在Flitter中,如何在主屏幕中接收图像,然后将其重定向到另一个屏幕?

Image 在Flitter中,如何在主屏幕中接收图像,然后将其重定向到另一个屏幕?,image,flutter,Image,Flutter,我正在开发一款纸牌游戏,用户可以在其中添加新的纸牌。每个卡都有一个映像路径。 我正在尝试用来自另一个应用程序(例如:Gallery)的图像预填充我的新卡片屏幕。 为此,我正在使用软件包,已成功打印到我的应用程序中的控制台图像路径。现在我不能做的是在获得图像后重定向到新屏幕。 以下是我的主屏幕上的相关代码: class Menu extends StatefulWidget { final String title; Menu({Key key, this.title}) : super

我正在开发一款纸牌游戏,用户可以在其中添加新的纸牌。每个卡都有一个映像路径。 我正在尝试用来自另一个应用程序(例如:Gallery)的图像预填充我的新卡片屏幕。 为此,我正在使用软件包,已成功打印到我的应用程序中的控制台图像路径。现在我不能做的是在获得图像后重定向到新屏幕。 以下是我的主屏幕上的相关代码:

class Menu extends StatefulWidget {
  final String title;

  Menu({Key key, this.title}) : super(key: key);

  @override
  _MenuState createState() => _MenuState();
}

class _MenuState extends State<Menu> {
  StreamSubscription _intentDataStreamSubscription;
  List<SharedMediaFile> _sharedFiles;

  @override
  void initState() {
    super.initState();
    bootstrapCards();
    getOurCards();
    // For sharing images coming from outside the app while the app is in the memory
    _intentDataStreamSubscription = ReceiveSharingIntent.getMediaStream()
        .listen((List<SharedMediaFile> value) {
      setState(() {
        _sharedFiles = value;
        print("Shared:" + (_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));
        _goCardAdd((_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));

      });
    }, onError: (err) {
      print("getIntentDataStream error: $err");
    });

    // For sharing images coming from outside the app while the app is closed
    ReceiveSharingIntent.getInitialMedia().then((List<SharedMediaFile> value) {
      setState(() {
        _sharedFiles = value;
        print("Shared:" + (_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));
        _goCardAdd((_sharedFiles?.map((f) => f.path)?.join(",") ?? ""));

      });
    });

  }
  @override
  void dispose() {
    _intentDataStreamSubscription.cancel();
    super.dispose();
  }
  void _goCardAdd(path) {
    MyCard myEmptyCard = new MyCard();
    myEmptyCard.url=path;
    Navigator.of(context).push(
      MaterialPageRoute<void>(
          builder: (BuildContext context) => AddEditScreen(myCard: myEmptyCard)),
    );
  }
class菜单扩展了StatefulWidget{
最后的字符串标题;
菜单({Key-Key,this.title}):超级(Key:Key);
@凌驾
_MenuState createState()=>\u MenuState();
}
类_MenuState扩展状态{
StreamSubscription\u意向数据流订阅;
列出共享文件;
@凌驾
void initState(){
super.initState();
bootstrapCards();
getOurCards();
//用于在应用程序位于内存中时共享来自应用程序外部的图像
_intentDataStreamSubscription=ReceiveSharingContent.getMediaStream()
.listen((列表值){
设置状态(){
_sharedFiles=值;
打印(“共享:”+(_sharedFiles?.map((f)=>f.path)?.join(“,”);
_goCardAdd(_sharedFiles?.map((f)=>f.path)?.join(“,”);
});
},onError:(错误){
打印(“getIntentDataStream错误:$err”);
});
//用于在应用关闭时共享来自应用外部的图像
ReceiveSharingContent.getInitialMedia().then((列表值){
设置状态(){
_sharedFiles=值;
打印(“共享:”+(_sharedFiles?.map((f)=>f.path)?.join(“,”);
_goCardAdd(_sharedFiles?.map((f)=>f.path)?.join(“,”);
});
});
}
@凌驾
无效处置(){
_intentDataStreamSubscription.cancel();
super.dispose();
}
void _gocardd(路径){
MyCard myEmptyCard=新的MyCard();
url=path;
导航器.of(上下文).push(
材料路线(
builder:(BuildContext context)=>AddEditScreen(myCard:mymptycard)),
);
}
看来_goCardAdd电话什么也没做,我不明白为什么。 如果我把它放在setState调用之后,我会得到一个错误

在生成过程中调用setState()或markNeedsBuild()

完整的代码可以在