如何传递设备 ID (flutter)

How do I pass the device ID (flutter)

我有一个名为 PhotosList 的小部件,它是一个无状态小部件我正在尝试将 $_deviceId 发送到该小部件,但我已经将数据发送到该小部件并且我不想打乱该小部件.

class PhotosList extends StatelessWidget {
  final Photo photos;
  FlutterRadioPlayer _flutterRadioPlayer = new FlutterRadioPlayer();

  PhotosList({Key key, this.photos}) : super(key: key);




  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 1,
      //  childAspectRatio: MediaQuery.of(context).size.width /
      //      (MediaQuery.of(context).size.height / 4), //childAspectRatio: 200,
      ),
      scrollDirection: Axis.horizontal,
      itemCount: photos.data.length,
      itemBuilder: (context, index) {
        return  RaisedButton(
            padding: const EdgeInsets.all(0),
            textColor: Colors.white,
            color: Colors.black,
            onPressed: () async {  await _flutterRadioPlayer.setUrl(photos.data[index].listenlive, "true");
            },

          child: CachedNetworkImage(
            imageUrl: photos.data[index].imageurl,
            placeholder: (context, url) => CircularProgressIndicator(),
            errorWidget: (context, url, error) => Icon(Icons.error),
          ),
        );
        // return Image.network(photos.data[index].imageurl, width: 80.0, height: 80.0,);
      },
    );
  }
}

我们使用下面的方式加载它。

FutureBuilder<Photo>(
                        future: fetchPhotos(http.Client()),
                        builder: (context, snapshot) {
                        if (snapshot.hasError) print(snapshot.error);

                        return snapshot.hasData
                        ? Expanded(child: PhotosList(photos: snapshot.data))
                            : Center(child: CircularProgressIndicator());
                        },
                    ),

有效 - 但现在我想随该请求一起发送 $_DeviceID。

我已经设置好了$_deviceId。根据我的理解,我需要像这样发送它:

PhotosList(photos: snapshot.data, uuid: $_deviceId))

然后在照片列表中放入


class PhotosList extends StatelessWidget {
  final Photo photos;
  final String uuid;
  FlutterRadioPlayer _flutterRadioPlayer = new FlutterRadioPlayer();

  PhotosList({Key key, this.photos}) : super(key: key);




  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 1,
      //  childAspectRatio: MediaQuery.of(context).size.width /
      //      (MediaQuery.of(context).size.height / 4), //childAspectRatio: 200,
      ),
      scrollDirection: Axis.horizontal,
      itemCount: photos.data.length,
      itemBuilder: (context, index) {
        return  RaisedButton(
            padding: const EdgeInsets.all(0),
            textColor: Colors.white,
            color: Colors.black,
            onPressed: () async {  await _flutterRadioPlayer.setUrl(photos.data[index].listenlive+'?uuid'+uuid, "true");
            },

          child: CachedNetworkImage(
            imageUrl: photos.data[index].imageurl,
            placeholder: (context, url) => CircularProgressIndicator(),
            errorWidget: (context, url, error) => Icon(Icons.error),
          ),
        );
        // return Image.network(photos.data[index].imageurl, width: 80.0, height: 80.0,);
      },
    );
  }
}

我得到的错误是

Error: No named parameter with the name 'uuid'.
                        ? Expanded(child: PhotosList(photos: snapshot.data,uuid:$_deviceId))

你应该这样做:PhotosList({Key key, this.photos, this.uuid}) : super(key: key);