【问题标题】:How do I pass the device ID (flutter)如何传递设备 ID(颤振)
【发布时间】:2021-03-14 04:00:25
【问题描述】:

我有一个名为 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))

然后在 PhotosList 中放


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))

【问题讨论】:

    标签: flutter widget device


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-18
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      • 2021-12-26
      • 1970-01-01
      • 2021-09-28
      相关资源
      最近更新 更多