dart 项目消失,而滚动Gridview在 Flutter

mtb9vblg  于 2023-09-28  发布在  Flutter
关注(0)|答案(1)|浏览(107)

在视图中,当我试图滚动GridView视图消失,并尝试重新打开屏幕,然后它显示较少的项目。我已经添加了滚动属性physics: ScrollPhysics(),shrinkWrap: true,,但什么也没有发生。

class PlayerOption extends StatefulWidget {
  @override
  _PlayerOptionState createState() => _PlayerOptionState();
}
  class _PlayerOptionState extends State<PlayerOption> {

  List<PlayerOptionBean> playerList=new List<PlayerOptionBean>();

  @override
  void initState() {
    populateData();
  }

  populateData(){
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Naaz',''));
    playerList.add(PlayerOptionBean('1','Ansari',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));
    playerList.add(PlayerOptionBean('1','Farhana',''));

  }

  @override
  Widget build(BuildContext context) {

    MediaQueryData queryData;
    queryData = MediaQuery.of(context);
    double width=queryData.size.width;
    double height=queryData.size.height;

    BoxDecoration _buildBackground() {
      return BoxDecoration(
        image: DecorationImage(
          image: AssetImage("assets/images/appmain_bg.png"),
          fit: BoxFit.fill,
        ),
      );
    }

    Widget _bottomView1(double width){
      return Row(
        mainAxisAlignment: MainAxisAlignment.end,
        children: <Widget>[
          Container(
              margin: EdgeInsets.only(left: width*0.05, top: width*0.05, bottom: width*0.02, right: width*0.05),
              decoration: BoxDecoration(
                color: MyColors.yellowBg,
                borderRadius: new BorderRadius.circular(12.0),
              ),
              child:FlatButton(
                  onPressed: (){
                  },
                  child: Text(
                      'Connect',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 20.0,

                      )
                  )
              ))
        ],
      );
    }
    Widget _logoContainer(double width){
      return Container(
        margin: EdgeInsets.only(left:width*0.05),
        height: 100.0,
        width: 100.0,
        decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/images/cmp_click.png"),
              fit: BoxFit.fill,
            )
        ),
      );
    }
    Widget searchContainer(){
      return Container(decoration: BoxDecoration(
          color: Colors.transparent),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(left: width*0.05,top: width*0.02, right: width*0.05),
                child:Text('SELECT AND CONNECT',style: TextStyle(fontFamily: 'bold'),) ,)
           ,
        Container(
          padding: EdgeInsets.only(left: width*0.05, right: width*0.05),
          margin: EdgeInsets.only(left: width*0.05,top: width*0.05, right: width*0.05),
          decoration: BoxDecoration(
            color: MyColors.yellowBg,
            borderRadius: new BorderRadius.circular(12.0),
          ),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Expanded(flex:80,child: TextField(
            decoration: new InputDecoration(
              hintText: 'Search',
              hintStyle: TextStyle(color: Colors.white70),
              border: InputBorder.none,)

              ),),
              Expanded(flex:20,child:  Icon(Icons.search,color: Colors.white70,),),

          ],),
        )
      ],),);
    }
    Widget MyFeedTile(int index){
      return GestureDetector(
        onTap: (){
          Navigator.push(context, MaterialPageRoute(builder: (context) => FeedView()),);
        },
          child:Column(
            children: <Widget>[
              SizedBox(height: width*0.02,),
              Container(
                //decoration: BoxDecoration(color: Colors.green[100]),
                height: 50,
                width: 50,
                margin: EdgeInsets.all(width*0.01),
                child: CircleAvatar(
                  radius: 40.0,
                  backgroundImage:
                  NetworkImage('https://via.placeholder.com/150'),
                  backgroundColor: Colors.transparent,),),
              SizedBox(height: width*0.02,),
              Text('${playerList[index].username}',style: TextStyle(color: Colors.white,fontFamily: 'bold'),),
            ],),
        );}

    Widget PlayerOptionContainer(){
      return Column(
        children: <Widget>[
          Expanded(flex:25,
            child: Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Expanded(flex: 30,child: _logoContainer(width),),
                Expanded(flex: 70,child:  searchContainer(),),

            ],),),
          Expanded(flex:75,child: Container(
            decoration: BoxDecoration(color: Colors.transparent),
            child: GridView.count(
              crossAxisCount: 3,
              physics: ScrollPhysics(),
              shrinkWrap: true,
              children: List.generate(playerList.length, (index) {
                return Container(
                  margin: EdgeInsets.only(left: width*0.02, bottom: width*0.02, right: width*0.02),
                  decoration: BoxDecoration(
                    color: MyColors.yellowBg,
                    borderRadius: new BorderRadius.circular(12.0),
                  ),
                  child: Center(child: MyFeedTile(index),),
                );
              }),
            ),
           ),)],
      );
    }

    return Scaffold(
        resizeToAvoidBottomInset:false,
      body: Stack(
        children: <Widget>[
          Container(
            decoration: _buildBackground(),
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              Expanded(
                flex: 13,
                //child:_toolBar('VENUE LOGIN')
                child:MyWidget(headerText: 'Player Option',)
              ),
             Expanded(
                flex: 70,
                child: Container(
                  margin: EdgeInsets.only(top: width*0.03),
                  decoration: BoxDecoration(color: Colors.transparent),child: PlayerOptionContainer(),),
              ),

              Expanded(
                flex: 17,
                child: _bottomView1(width),
              ),
            ],
          )
        ],
      ),
    );
  }
}

ilmyapht

ilmyapht1#

我的GridView.builder有这个问题。问题是由透明背景图像引起的。

相关问题