Flutter 颤振UI列表项

Flutter 颤振UI列表项,flutter,flutter-layout,Flutter,Flutter Layout,我正在使用下面的代码,但无法达到预期的结果,我是颤振世界的新手,请让我知道在哪里可以改进以获得预期的结果。下面是我所做的工作的源代码 return Expanded( child: GridView.builder( controller: _scrollController, gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCou

我正在使用下面的代码,但无法达到预期的结果,我是颤振世界的新手,请让我知道在哪里可以改进以获得预期的结果。下面是我所做的工作的源代码

return Expanded(
        child: GridView.builder(
          controller: _scrollController,
          gridDelegate:
              SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
          itemCount: albumList.length,
          itemBuilder: (BuildContext context, int index) {
            return buildRow(index);
          },
        ),
      );


  Widget buildRow(int index) {
    return AlbumTile(
      index: index,
      albumList: albumList,
      deleteAlbum: _deleteAlbum,
    );
  }
这是相册磁贴

class AlbumTile extends StatelessWidget {

  AlbumTile(
      {Key key,
      @required this.index,
      @required this.albumList,
      @required this.deleteAlbum})
      : super(key: key);

  final int index;
  final List<Album> albumList;
  final Function deleteAlbum;

  @override
  build(BuildContext context) {
    String thumb;

    if (albumList.elementAt(index).thumbUrl != "") {
      thumb = WEBSERVICE_IMAGES +
          albumList.elementAt(index).userId.toString() +
          '/' +
          albumList.elementAt(index).id.toString() +
          '/' +
          albumList.elementAt(index).thumbUrl;
    } else {
      thumb = "https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823__340.jpg";
    }

    return GestureDetector(
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) =>
                new AlbumPage(tabIndex: index, albumList: albumList),
          ),
        );
      },
      child: Container(
        // height of the card which contains full item
        height: MediaQuery.of(context).size.height * 0.4,
        width: MediaQuery.of(context).size.width * 0.28,
        // this is the background image code
        decoration: BoxDecoration(
            image: DecorationImage(
                fit: BoxFit.cover,
                // url is my own public image url
                image: NetworkImage(thumb),
            ),
            borderRadius: BorderRadius.circular(12.0)),
        // this is the item which is at the bottom
        child: Align(
          // aligment is required for this
          alignment: Alignment.bottomLeft,
          // items height should be there, else it will take whole height
          // of the parent container
          child: Container(
            padding: EdgeInsets.only(left: 10.0, right: 0.0),
            height: MediaQuery.of(context).size.height * 0.1,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      // Text() using hard coded text right now
                      Text(albumList.elementAt(index).name,
                          style: TextStyle(
                              fontSize: 18.5,
                              color: Colors.white,
                              fontWeight: FontWeight.w500)),
                      SizedBox(height: 3.0),
                      Text(albumList.elementAt(index).photos.toString() +' photos',
                          style: TextStyle(
                              fontSize: 12.5,
                              color: Colors.white,
                              fontWeight: FontWeight.w500))
                    ],
                  ),
                ),

                // pop-up item
                PopupMenuButton(
                  icon: Icon(Icons.more_vert, color: Colors.white),
                  itemBuilder: (_) => <PopupMenuItem<String>>[
                    new PopupMenuItem<String>(
                      child: Row(
                        children: <Widget>[
                          Icon(Icons.delete),
                          Text(
                            'Delete Album',
                          ),
                        ],
                      ),
                      value: 'Delete',
                    ),
                  ],
                  onSelected: (value) {
                    deleteAlbum(albumList.elementAt(index).id, index);
                  },
                ),
              ],
            ),
          ),
        ),
      ),
    );

    GestureDetector(
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) =>
                new AlbumPage(tabIndex: index, albumList: albumList),
          ),
        );
      },
      child: Padding(
        padding: const EdgeInsets.all(12.0),
        child: Stack(
          fit: StackFit.loose,
          children: <Widget>[
            ClipRRect(
              borderRadius: new BorderRadius.circular(8.0),
              child: FadeInImage.assetNetwork(
                height: 1000,
                placeholder: kPlaceHolderImage,
                image: thumb,
                fit: BoxFit.cover,
              ),
            ),
            Align(
              alignment: Alignment.bottomLeft,
              child: Row(
                children: [
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
                      child: Text(
                        albumList.elementAt(index).name,
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 18.5,
                        ),
                        textAlign: TextAlign.left,
                      ),
                    ),
                  ),
                  PopupMenuButton(
                      icon: ImageIcon(
                        AssetImage("graphics/horizontal_dots.png"),
                        color: Colors.white,
                      ),
                      itemBuilder: (_) => <PopupMenuItem<String>>[
                            new PopupMenuItem<String>(
                              child: Row(
                                children: <Widget>[
                                  Icon(Icons.delete),
                                  Text(
                                    'Delete Album',
                                  ),
                                ],
                              ),
                              value: 'Delete',
                            ),
                          ],
                      onSelected: (value) {
                        deleteAlbum(albumList.elementAt(index).id, index);
                      }),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
类AlbumTile扩展了无状态小部件{
相册(
{键,
@需要这个索引,
@需要此列表,
@此项为必需。deleteAlbum})
:super(key:key);
最终整数指数;

最终列表

欢迎来到Flatter。非常棒的平台,让您在
构建跨平台移动应用程序
上开始职业生涯

我的代码对你来说会有点不同,但是相信我,这会适合你的

请注意:您需要更改某些部分,例如更改
NetworkImage()
图像url
onTap
函数、
Text()
内容等。但整个小部件代码中没有太多更改。因此,请查找这些更改,并进行相应的更改。您将到达:)


如果您对间距不满意,请继续玩。我希望这会有帮助。请让我知道。:)

您需要在代码中添加一些东西来获得结果……要获得照片小部件的数量,您可以使用列包装它,也可以使用richtext。单击三点图标称为more\u vert更垂直的按钮会弹出弹出菜单对话框。为什么@kanwarpreething的输出是代码的结果。如果您从该代码中获得了任何帮助,请共享您的代码,以及您在这里遇到的问题。编辑:)让我们看看问题并解决它伟大的@kanwarpreething等待!让我e know:)完成。请检查当前代码和屏幕截图。请参阅@KanwarpreetSingh它是否正常。您关心的是小部件的UI,而不是整个UI。因此,您只指出了卡片代码。我只对卡片代码进行了更改。现在是关于这些卡片的整个页面UI。这两件事是不同的Kanwar。我是我现在就为你做。请等一会儿:)等等,我也会给你提供格里夫视图的代码。
       GestureDetector(
          onTap: () => print('Works!'), // <-- onTap change, I have used print()
          child: Container(
             // height of the card which contains full item
             height: MediaQuery.of(context).size.height * 0.4, 
             width: MediaQuery.of(context).size.width * 0.28,
             // this is the background image code
             decoration: BoxDecoration(
               image: DecorationImage(
                fit: BoxFit.cover,
                // url is my own public image url
                image: NetworkImage('https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823__340.jpg')
               ),
               borderRadius: BorderRadius.circular(12.0)
            ),
            // this is the item which is at the bottom
            child: Align(
              // aligment is required for this
              alignment: Alignment.bottomLeft,
              // items height should be there, else it will take whole height
              // of the parent container
              child: Container(
                padding: EdgeInsets.only(left: 10.0, right: 0.0),
                height: MediaQuery.of(context).size.height * 0.1,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Expanded(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: [
                          // Text() using hard coded text right now
                          Text('Potraits', style: TextStyle(fontSize: 20.0, color: Colors.white, fontWeight: FontWeight.w500)),
                          SizedBox(height: 3.0),
                          Text('150 photos', style: TextStyle(fontSize: 17.0, color: Colors.white, fontWeight: FontWeight.w500))
                        ]
                      )
                    ),
                    
                    // pop-up item
                    PopupMenuButton(
                      icon: Icon(Icons.more_vert, color: Colors.white),
                      itemBuilder: (_) => <PopupMenuItem<String>>[
                        new PopupMenuItem<String>(
                          child: Row(
                            children: <Widget>[
                              Icon(Icons.delete),
                              Text(
                                'Delete Album',
                              ),
                            ],
                          ),
                          value: 'Delete',
                        ),
                      ],
                      onSelected: (value) {
                        //your function
                      }
                    )
                  ]
                )
              )
            )
          )
        )
  Widget buildRow(int index) {
    return Padding(
      padding: EdgeInsets.all(10.0),
      child: AlbumTile(
        index: index,
        albumList: albumList,
        deleteAlbum: _deleteAlbum,
      )
    );
  }