在setState不生效的情况下,可使用StatefulBuilder

 Widget buildSpecialEffects() {
    return StatefulBuilder(builder: (context, setState) {
      return Container(
        width: 1920.w,
        height: 844.w,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Container(
              margin: EdgeInsets.only(bottom: 17.w),
              height: 125.w,
              width: 1183.w,
              alignment: Alignment.center,
              child: Slider(
                activeColor: Color(0xFFFFFFFF),
                inactiveColor: Color(0x80FFFFFF),
                max: 100,
                min: 0,
                value: specialEffectsSliderIndex,
                onChanged: (double value) {
                  setState(() {
                    specialEffectsSliderIndex = value.toInt().toDouble();
                  });
                },
              ),
            ),
            ///底下白色布局
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(58.w),
                        topRight: Radius.circular(58.w))),
                padding: EdgeInsets.only(left: 78.w, right: 78.w),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    ///清除
                    Container(
                      height: 255.w,
                      child: Row(
                        mainAxisSize: MainAxisSize.max,
                        children: [
                          Row(
                            children: [
                              Image.asset(
                                'image/icon57.png',
                                width: 68.w,
                              ),
                              Container(
                                width: 29.w,
                              ),
                              Text(
                                '清除',
                                style: TextStyle(fontSize: 71.w),
                              ),
                              Container(
                                width: 78.w,
                              ),
                              Container(
                                width: 2.w,
                                height: 96.w,
                                color: const Color(0xFFEEEEEE),
                              )
                            ],
                            mainAxisSize: MainAxisSize.min,
                          ),
                          Expanded(
                              child: Container(
                                margin: EdgeInsets.only(left: 39.w),
                                child: ListView.builder(
                                    controller: specialTypeController,
                                    scrollDirection: Axis.horizontal,
                                    itemCount: specialEffectsTypeList.length,
                                    itemBuilder: (context, index) {
                                      return GestureDetector(
                                        onTap: (){

                                          if(widget.methodListener != null){
                                            widget.methodListener('onSpecialTypeIndex',index);
                                          }
                                          setState((){
                                            specialEffectsTypeIndex = index;
                                          });

                                        },
                                        child: Container(
                                          color: Colors.transparent,
                                          padding: EdgeInsets.only(
                                              left: 39.w,
                                              right: 39.w,
                                              bottom: 78.w,
                                              top: 78.w),
                                          child: Text(
                                            '${specialEffectsTypeList[index].name}',
                                            style: TextStyle(
                                              fontSize: 71.sp,
                                              color: (index == specialEffectsTypeIndex)
                                                  ? Colors.red
                                                  : Colors.black,
                                              fontWeight: (index == specialEffectsTypeIndex)
                                                  ? FontWeight.bold
                                                  : FontWeight.w400,
                                            ),
                                          ),
                                        ),
                                      );
                                    }),
                              ))
                        ],
                      ),
                    ),
                    ///分类列表
                    Expanded(
                      child: ListView.builder(
                          padding: EdgeInsets.only(top: 0),
                          scrollDirection: Axis.horizontal,
                          itemCount: specialEffectsList.length,
                          itemBuilder: (context, index) {
                            return GestureDetector(
                              onTap: (){
                                if(widget.methodListener != null){
                                  widget.methodListener('onSpecialIndex',index);
                                }
                              },
                              child: Container(
                                margin: EdgeInsets.only(right: 39.w,bottom: 21.w),
                                child: Column(
                                  children: [
                                    Container(
                                      decoration: BoxDecoration(
                                          image: DecorationImage(
                                              image: NetworkImage(Request.assertUrl + specialEffectsList[index].cover)
                                          ),
                                          borderRadius: BorderRadius.circular(28.w),
                                          border: (index == specialEffectsContentIndex)?Border.all(color: Colors.red,width: 3.w):null
                                      ),
                                      width: 286.w,
                                      height: 286.w,
                                    ),
                                    Container(
                                      height: 25.w,
                                    ),
                                    Text('${specialEffectsList[index].name}',style: TextStyle(fontSize: 61.w,color: Colors.black),)
                                  ],
                                ),
                              ),
                            );
                          }),
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      );
    });
  }

你可能感兴趣的:(在setState不生效的情况下,可使用StatefulBuilder)