flutter 如何将数据从一个屏幕发送到另一个屏幕

j2cgzkjk  于 2023-01-18  发布在  Flutter
关注(0)|答案(1)|浏览(127)
itemBuilder: (context, index) => MyImage( image: API.image +'/' `your text`+snapshot.data[index['MainPicture'].toString(), title: snapshot.data[index]['productName'],`your text`
                      subname: snapshot.data[index]['productSubname'],`your text`
                      price: snapshot.data[index][price].toString(),`your text`
                      discount: '% ' +
                          snapshot.data[index]['productDiscount'].toString(),`your text`
           

     ),

我想让这些参数进入另一个屏幕your text

v8wbuo2f

v8wbuo2f1#

使用类似go_router的导航器
稍后按照相应的步骤传递参数。

定义
GoRoute(
    path: '/sample/:id1/:id2',  👈 Defination of params in the path is important
    name: 'sample',
    builder: (context, state) => SampleWidget(
      id1: state.params['id1'],
      id2: state.params['id2'],
    ),
  ),
传递参数
ElevatedButton(
            onPressed: () {
              var param1 = "param1";
              var param2 = "param2";
              context.goNamed("sample", params: {'id1': param1, 'id2': param2});
            },
            child: const Text("Hello"),
          ),
接收器小部件:
class SampleWidget extends StatelessWidget {
  String? id1;
  String? id2;
  SampleWidget({super.key, this.id1, this.id2});

  @override
  Widget build(BuildContext context) {
     ...
  }
}

并参考以下答案:Flutter:go_router如何将多个参数传递给其他屏幕?

相关问题