显示带有抖动的Smoothstar评分

问题描述 投票:0回答:1

我已经在网络端完成了图像评级,所以我在这里尝试做的是,当我调用api时,api返回一些细节,例如图像,说明,图像评级,回复,但我不确定如何实现图像评级值以平滑星星它无法正常工作,我从api获取了所有值,但是当我尝试与smoothstar集成时,我无法使用“ Imge_Rating正常”]

  class ImagesDetailScreenStateful extends State<ImageDetailState> {


  String Description;
  String image_path;
  String Image_Rating;
  String replay;
  var rating=0.0;
  void initState() {
    getImageView(imageid);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text(
            imageid,
            style: TextStyle(color: Colors.white, fontSize: 15),
          ),
          backgroundColor: Color.fromRGBO(23, 84, 119, 1),
        ),
        body: SingleChildScrollView(
          child: Container(
            padding: EdgeInsets.all(10),
            child: Column(
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Container(
                  width:350,
                  height: 250,
                  padding: EdgeInsets.all(10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Expanded(
                        flex: 1,
                          child: FadeInImage.assetNetwork(
                              placeholder: 'assets/images/loading.gif',
                              image:image_path.toString()
                          )
                      ),
                    ],
                  ),
                ),
                Expanded(
//              padding: EdgeInsets.all(5),
                  flex: 0,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                          flex: 3,
                          child: Padding(
                            padding: EdgeInsets.all(8),
                            child: Text('Remarks',
                                style: TextStyle(
                                    color: Colors.redAccent,
                                    fontSize: 15,
                                    fontWeight: FontWeight.bold)),
                          )),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.all(5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                          flex: 1,
                          child: Padding(
                            padding: EdgeInsets.all(5),
                            child: Text(
                                Description.toString(),
                            style: TextStyle(
                                    color: Colors.black,
                                    fontSize: 15,
                                    )),
                          )),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.all(5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                          flex: 1,
                          child: Padding(
                            padding: EdgeInsets.all(5),
                            child: Text('Reply',
                                style: TextStyle(
                                    color: Colors.deepOrange,
                                    fontSize: 15,
                                    fontWeight: FontWeight.bold)),
                          ),),

                      SmoothStarRating(
                                  allowHalfRating: false,
                                  onRated: (v) {
                                    rating = v;
                                    setState(() {});
                                  },
                                  starCount: 5,
                                  rating: rating,
                                  size: 20.0,
                                  filledIconData: Icons.blur_off,
                                  halfFilledIconData: Icons.blur_on,
                                  color: Colors.deepOrange[700],
                                  borderColor: Colors.deepOrange[700],
                                  spacing:0.0
                              ),

                    ],
                  ),
                ),

                //Remarks Section
                Container(
                  padding: EdgeInsets.all(5),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: <Widget>[
                      Expanded(
                          flex: 2,
                          child: Padding(
                            padding: EdgeInsets.all(5),
                            child: Text(replay.toString(),style: TextStyle(fontSize: 15,color: Colors.black),),
                          )

                      ),
                    ],
                  ),
                ),

              ],
            ),
          ),
        ));
  }

api的代码

尝试{var resp = response.body;

  Map<String, dynamic> value = json.decode(resp);
  var name = value['doc']['image'];

  Description = name["Description"].toString();
  image_path = name["image_path"].toString();
  Image_Rating = name["Image_Rating"].toString();
  replay = value['doc']["replays"][0]["replay"].toString();


setState(() {
  Description = name["Description"].toString();
  image_path = name["image_path"].toString();
  replay = value['doc']["replays"][0]["replay"].toString();
  Image_Rating = name["Image_Rating"].toString();
});



} catch (e) {
  e.toString();
}
flutter dart flutter-layout
1个回答
0
投票

Image_Rating是字符串。

SmoothStarRating的rating属性是double。您需要将Image_Rating转换为double

SmoothStarRating(
                              ...,
                              starCount: 5,
                              rating: double.parse(Image_Rating),
                              ...
                          ),

小心属性命名。

Image_Rating必须为image_rating(首字母大写用于类名称,属性必须采用蛇形格式)。

© www.soinside.com 2019 - 2024. All rights reserved.