Flutter 为什么页面向下滚动时listview中的图像消失?

Flutter 为什么页面向下滚动时listview中的图像消失?,flutter,Flutter,我有一个叫做RecipesScreen的页面,在这个屏幕上我有4个小部件,我在listView中列出了它们 在第一个小部件中,用户可以添加照片,在用户上传照片并向下滚动页面后,图像消失 我添加了一些代码以避免它消失,但它还是消失了 这是我的密码: class RecipeScreen extends StatefulWidget { RecipeScreen({this.subCategoryCardId,this.subCategoryId}); final int subCatego

我有一个叫做RecipesScreen的页面,在这个屏幕上我有4个小部件,我在listView中列出了它们

在第一个小部件中,用户可以添加照片,在用户上传照片并向下滚动页面后,图像消失

我添加了一些代码以避免它消失,但它还是消失了

这是我的密码:

class RecipeScreen extends StatefulWidget {
  RecipeScreen({this.subCategoryCardId,this.subCategoryId});
  final int subCategoryId;
  final int subCategoryCardId;
  static String id="recipeScreen";
  @override
  _RecipeScreenState createState() => _RecipeScreenState();
}

class _RecipeScreenState extends State<RecipeScreen> with AutomaticKeepAliveClientMixin  {

  List<Widget>recipeScreenCards=[
    AddPhotoCard(),
    AddIngredientsCard(),
    AddIngredientsAmount(),
    AddRecipeVoice()];

  bool isPageSaved=false;
  double _animatedContainerHeight=200;
  String textValue;
  int index=-1;

  Future<bool> _showAlertDialog(BuildContext context){
    AlertDialog alert = AlertDialog(
      backgroundColor: kColorTheme10,
      elevation: 0,
      content: Container(decoration:BoxDecoration(
          color: Colors.white70.withOpacity(0.7),
          borderRadius: BorderRadius.circular(15)
      ),  child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Text(
            "Tarifiniz tamamlanmadı.Çıkmak istediğinizden emin misiniz?",
            style: TextStyle(
                fontSize: 25,
                fontFamily: "OpenSans")
        ),
      ),
      ),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
      actions: [
        Container(
          decoration: BoxDecoration(
              color: Colors.white70.withOpacity(0.7),
              borderRadius: BorderRadius.circular(30)
          ),
          child: TextButton(onPressed:()async{
            Navigator.of(context).pop(true);
          },
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text("EVET",style: TextStyle(fontWeight: FontWeight.bold,fontFamily: "OpenSans"),),
              )),
        ),
        Container(
          decoration: BoxDecoration(
              color:Colors.white70.withOpacity(0.7),
              borderRadius: BorderRadius.circular(30)
          ),
          child: TextButton(onPressed:()async{
            Navigator.of(context).pop(false);
          },
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text("HAYIR",style: TextStyle(fontWeight: FontWeight.bold, fontFamily: "OpenSans")),
            ),
          ),
        ),
      ],
    );
    return showDialog(
        context: context,
        builder: (_)=>alert);
  }


  void toggleAnimatedContainerHeight(){
    _animatedContainerHeight==200?_animatedContainerHeight=450:_animatedContainerHeight=200;
  }

  void _clearIngredient(BuildContext ctx) {
    Provider.of<IngredientsProvider>(ctx,listen: false).clearList();
  }


  @override
  Widget build(BuildContext context) {
    super.build(context);
    return WillPopScope(
      child: SafeArea(
        child: Scaffold(
          appBar: AppBar(
            automaticallyImplyLeading: false,
            centerTitle: true,
            title: BorderedText(
              child:Text(
                categoryModels[widget.subCategoryId].subCategoryModels[widget.subCategoryCardId].subCategoryName,
                style: TextStyle(
                    color: Colors.white,
                    fontSize: 30,
                    fontFamily: "OpenSans"
                ),
              ),
              strokeWidth: 5,
              strokeColor: Colors.black,
            ),
            elevation: 5,
            backgroundColor: categoryModels[widget.subCategoryId].
              subCategoryModels[widget.subCategoryCardId].categoryColor,
            leading: IconButton(
              icon: Icon(Icons.arrow_back),
              onPressed:()async{
                var response = await _showAlertDialog(context);
                if(response==true){
                  _clearIngredient(context);
                  Navigator.pop(context);

                }
              },
              iconSize: 40,
              color: Colors.white,
            ),
            actions: [
              CircleAvatar(
                radius: 27,
                backgroundColor: Colors.transparent,
                backgroundImage: AssetImage("images/cuttedlogo.PNG"),
              )
            ],
          ),
          body: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage(kBGWithLogoOpacity),
                fit: BoxFit.cover,
              ),
            ),
            child: Scrollbar(
              isAlwaysShown: true,
              thickness: 7,
              radius: Radius.circular(90),
              child: ListView(
                addAutomaticKeepAlives: true,
                scrollDirection: Axis.vertical,
                children: [
                  AddPhotoCard(subCategoryCardId: widget.subCategoryCardId, subCategoryId: widget.subCategoryId),
                  AddIngredientsCard(subCategoryCardId: widget.subCategoryCardId, subCategoryId: widget.subCategoryId),
                  AddIngredientsAmount(subCategoryCardId: widget.subCategoryCardId, subCategoryId: widget.subCategoryId),
                  AddRecipeVoice(subCategoryCardId: widget.subCategoryCardId, subCategoryId: widget.subCategoryId),
                  ]
                ),
            ),
          )
         )
      ),
      onWillPop: ()async{
        if(isPageSaved==false){
          var response = await _showAlertDialog(context);
          if(response==true){
            _clearIngredient(context);
            Navigator.pop(context);
            return true;
          }
        }
        return false;
      },
    );
  }
  @override
  bool get wantKeepAlive => true;
}
class RecipesScreen扩展StatefulWidget{
RecipesScreen({this.subCategoryCardId,this.subCategoryId});
最终int子类别id;
最终int子类别cardd;
静态字符串id=“RecipesScreen”;
@凌驾
_RecipesCrenstate createState()=>\u RecipesCrenstate();
}
类_recipescrenstate使用AutomaticEpaLiveClientMixin扩展状态{
克里恩卡德山脉=[
AddPhotoCard(),
AddIngredientsCard(),
AddIngredientsAmount(),
AddRecipeVoice();
bool isPageSaved=false;
双_animatedContainerHeight=200;
字符串文本值;
int指数=-1;
Future\u showAlertDialog(构建上下文){
AlertDialog alert=AlertDialog(
背景颜色:kColorTheme10,
海拔:0,
内容:容器(装饰:盒子装饰)(
颜色:颜色。白色70。不透明度(0.7),
边界半径:边界半径。圆形(15)
),child:Padding(
填充:常数边集全部(8.0),
子:文本(
“塔马兰玛德·切克马克·伊斯特迪奥登·埃明·米西兹的塔利班化?”,
样式:TextStyle(
尺寸:25,
fontFamily:“OpenSAN”)
),
),
),
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(30)),
行动:[
容器(
装饰:盒子装饰(
颜色:颜色。白色70。不透明度(0.7),
边界半径:边界半径。圆形(30)
),
子项:文本按钮(按下时:()异步{
Navigator.of(context.pop)(true);
},
孩子:填充(
填充:常数边集全部(8.0),
子项:文本(“EVET”,样式:TextStyle(fontWeight:fontWeight.bold,fontFamily:“OpenSans”),
)),
),
容器(
装饰:盒子装饰(
颜色:颜色。白色70。不透明度(0.7),
边界半径:边界半径。圆形(30)
),
子项:文本按钮(按下时:()异步{
Navigator.of(context.pop)(false);
},
孩子:填充(
填充:常数边集全部(8.0),
子项:文本(“HAYIR”,样式:TextStyle(fontWeight:fontWeight.bold,fontFamily:“OpenSans”),
),
),
),
],
);
返回显示对话框(
上下文:上下文,
生成器:()=>警报);
}
void toggleAnimatedContainerHeight(){
_animatedContainerHeight==200?\u animatedContainerHeight=450:\u animatedContainerHeight=200;
}
void\u ClearComponent(BuildContext ctx){
Provider.of(ctx,listen:false).clearList();
}
@凌驾
小部件构建(构建上下文){
super.build(上下文);
返回式示波器(
儿童:安全区(
孩子:脚手架(
appBar:appBar(
自动嵌入:false,
标题:对,
标题:带边框的文本(
子:文本(
categoryModels[widget.subCategoryId].subCategoryModels[widget.subCategoryCardId].subCategoryName,
样式:TextStyle(
颜色:颜色,白色,
尺寸:30,
fontFamily:“OpenSAN”
),
),
冲程宽度:5,
strokeColor:Colors.black,
),
标高:5,
backgroundColor:categoryModels[widget.subCategoryId]。
子类别模型[widget.subCategoryCardId].categoryColor,
领先:IconButton(
图标:图标(图标。箭头返回),
onPressed:()异步{
var response=Wait_showAlertDialog(上下文);
如果(响应==true){
_明确成分(上下文);
Navigator.pop(上下文);
}
},
iconSize:40,
颜色:颜色,白色,
),
行动:[
圆形(
半径:27,
背景颜色:颜色。透明,
背景图片:AssetImage(“images/cuttedlogo.PNG”),
)
],
),
主体:容器(
装饰:盒子装饰(
图像:装饰图像(
图像:AssetImage(kBGWithLogoOpacity),
适合:BoxFit.cover,
),
),
子:滚动条(
伊莎韦肖恩:没错,
厚度:7,
半径:半径。圆形(90),
子:ListView(
AddAutomaticEpaLifes:没错,
滚动方向:轴垂直,
儿童:[
AddPhotoCard(子类别CardId:widget.subCategoryCardId,子类别ID:widget.subCategoryId),
AddingCreditScard(子类别CardId:widget.SubCategory CardId,子类别ID:widget.SubCategory ID),
AddingCreditSamount(子类别CardId:widget.subCategoryCardId,子类别ID:widget.subCategoryId),
AddRecipeVoice(子类别ID:widget.subCategoryCardId,子类别ID:widget.subCategoryId),
]
),
),
)
)
),
onWillPop:()异步{
如果(isPageSaved==false){
var response=Wait_showAlertDialog(上下文);
如果(响应==true){
_明确成分(上下文);
Navigator.pop(上下文);
返回true;
}
}
返回false;
},
);
}
@凌驾
bool get wantKeepAlive=>true;
}

原因是小部件