如何在颤振评分栏中保存用户评分?

问题描述

我正在尝试保存用户评分以在用户返回页面时显示它。但我正在挣扎,无法弄清楚如何做到这一点。评级有效,但正如我所说,储蓄无效。 所以发生的事情是它总是空的。我真正想要的是,如果用户返回该页面,他会看到他的评分,如果他再次评分并且评分与上次评分不同,我让他评分,如果没有,则不评分,如果他按清除,评分将删除什么也工作正常。

也许任何人都可以提供帮助。

lass Ratingpage extends StatefulWidget {
  final int maximumRating;
  final Function(int) onRatingSelected;

  Ratingpage(this.onRatingSelected,[this.maximumRating = 5]);

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

class _RatingpageState extends State<Ratingpage> {
  int haveusercurrentchoice;

  int _currentRating = 0;

  Widget _buildRatingStar(int index) {
    if (index < _currentRating) {
      return Icon(
        Icons.star,color: Colors.yellow,);
    } else {
      return Icon(
        Icons.star,color: Colors.white,);
    }
  }

  Widget _buildBody() {
    final stars = List<Widget>.generate(this.widget.maximumRating,(index) {
      return Expanded(
        child: GestureDetector(
          child: _buildRatingStar(index),onTap: () {
            setState(() {
              _currentRating = index;
            });

            this.widget.onRatingSelected(_currentRating);
          },),);
    });
    return Row(
      children: [
        Expanded(
          child: Row(
            children: stars,Expanded(
          child: TextButton(
            onPressed: () {
              setState(() {
                _currentRating = 0;
              });

              this.widget.onRatingSelected(_currentRating);
            },child: Text(
              "Clear",style: TextStyle(color: Colors.white),],);
  }

  @override
  Widget build(BuildContext context) {
    return _buildBody();
  }

如果您需要更多信息,请发表评论。

这就是我调用页面的方式

 Container(
                                width: 210,height: 94,//color: Colors.blue.withOpacity(0.5),child: Column(
                                  children: [
                                    InkWell(
                                      onTap: () {
                                        setState(() {
                                          israting = true;
                                        });
                                        //  if( _rating !=null && _rating >0){
                                        // likevideo(videos.data()['id']);}
                                      },child: israting
                                          ? Container(
                                              height: 50,margin: EdgeInsets.fromLTRB(
                                                  0,5,0),child: Column(
                                                children: [
                                                  Ratingpage((rating) {
                                                    setState(() {
                                                      _rating = rating;
                                                    });

                                                    if (_rating != null &&
                                                        _rating > 0) {
                                                      likevideo(
                                                          videos.data()['id'],_rating);

                                                      print(delteuserchoicing);
                                                    } else if (_rating ==
                                                            null ||
                                                        _rating == 0) {
                                                      dislike(
                                                          videos.data()['id'],_rating);
                                                    }
                                                  }),)
                                          : Icon(
                                              Icons.star,size: 37,color: videos
                                                      .data()['likes']
                                                      .contains(uid)
                                                  ? Colors.yellow
                                                  : Colors.white,

实际上是在一个列内

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)