在抖动中滚动Gridview时视图消失

时间:2019-05-28 07:17:30

标签: android flutter dart

在视图中,当我尝试滚动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),
              ),
            ],
          )
        ],
      ),
    );
  }
}

enter image description here

0 个答案:

没有答案