Gridview flatter如何在网格视图中显示画廊图像

Gridview flatter如何在网格视图中显示画廊图像,gridview,flutter,gallery,Gridview,Flutter,Gallery,我想尽一切办法在网格视图中快速显示画廊图片。但是我找不到任何合适的方法。您可以创建一个小部件列表,并将其添加到gridview中,如下所示: List<Widget> images = new List<Widget>(); images.add(Image.asset('assets/image.png', height: 35)); images.add(Image.asset('assets/image.png', height: 35)); images.add(

我想尽一切办法在网格视图中快速显示画廊图片。但是我找不到任何合适的方法。

您可以创建一个小部件列表,并将其添加到gridview中,如下所示:

List<Widget> images = new List<Widget>();
images.add(Image.asset('assets/image.png', height: 35));
images.add(Image.asset('assets/image.png', height: 35));
images.add(Image.asset('assets/image.png', height: 35));

CustomScrollView(
    primary: false,
    slivers: <Widget>[
      SliverPadding(
        padding: const EdgeInsets.all(3.0),
        sliver: SliverGrid.count(
          mainAxisSpacing: 1, //horizontal space
          crossAxisSpacing: 1, //vertical space
          crossAxisCount: 3, //number of images for a row
          children: images
        ),
      ),
    ],
  ),
列表图像=新列表();
添加(Image.asset('assets/Image.png',高度:35));
添加(Image.asset('assets/Image.png',高度:35));
添加(Image.asset('assets/Image.png',高度:35));
自定义滚动视图(
主要:错误,
条子:[
填缝料(
填充:常数边集全部(3.0),
sliver:SliverGrid.count(
主轴间距:1,//水平间距
横轴间距:1,//垂直间距
crossAxisCount:3,//一行的图像数
儿童:图像
),
),
],
),

您想要实现的目标相当复杂(文件夹位置、读取存储在那里的文件、识别您想要显示的内容……)

有两种选择:

如果您没有专门制作一个应用程序来访问用户手机中存储的照片,而没有自己的用户界面,请使用此插件

如果您正在开发一个专门用于访问存储在用户手机中的照片的应用程序(具有自己的UI)

以下链接可能会帮助您:

甚至还有一个小部件以网格的形式显示多个小部件,称为GridView

我建议将你的问题分成几个部分,然后以多个问题的形式逐一提问,因为你基本上是在问一个应用程序的整个模型,这需要很多解释。

此链接上的示例

@覆盖
小部件构建(构建上下文)
{
回归未来建设者(
未来:StoragePath.imagesPath,
生成器:(BuildContext上下文,异步快照){
if(snapshot.hasData){
List=json.decode(snapshot.data);
返回容器(
子项:GridView.builder(
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
交叉轴计数:2,
),
itemCount:list.length,
itemBuilder:(构建上下文,int索引){
ImageModel ImageModel=ImageModel.fromJson(列表[索引]);
返回容器(
子:堆栈(
对齐:对齐.bottomCenter,
儿童:[
法代尼玛(
image:FileImage(
文件(imageModel.files[0]),
),
占位符:MemoryImage(K透明图像),
适合:BoxFit.cover,
宽度:double.infinity,
高度:双无限,
),
容器(
颜色:颜色。黑色。不透明度(0.7),
身高:30,
宽度:double.infinity,
儿童:中心(
子:文本(
imageModel.folderName,
maxLines:1,
溢出:TextOverflow.省略号,
样式:TextStyle(
颜色:颜色,白色,
尺寸:16,
fontFamily:“常规”
),
),
),
)
],
),
);
},
),
);
}否则{
返回容器();
}
},
);

}

步骤1:在yaml文件“gallery\u view:^0.0.4”上导入程序包 步骤2:发布获取(安装包) 步骤4:将图像作为url或从资产图像添加 步骤3:最后运行代码b

import 'package:flutter/material.dart';
import 'package:gallery_view/gallery_view.dart';

void main() {
  runApp(GalleryGridScreen());
}

class GalleryGridScreen extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<GalleryGridScreen> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Gallery'),
        ),
        body: GalleryView(
          crossAxisCount: 2,
          imageUrlList: [
"imageurl1",
"imageurl2",
"imageurl3",
"imageurl4",


        ]),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:gallery_view/gallery_view.dart”;
void main(){
runApp(GalleryGridScreen());
}
类GalleryGridScreen扩展StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
字符串_platformVersion='未知';
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
appBar:appBar(
标题:常量文本(“图库”),
),
正文:GalleryView(
交叉轴计数:2,
imageUrlList:[
“imageurl1”,
“imageurl2”,
“imageurl3”,
“imageurl4”,
]),
),
);
}
}

我必须添加图库中的图像。图像不在我的资产中。哦,对不起,我的不好。您是否尝试使用此插件列出此列表?image_gallery的问题是,它超出了内存,因为它一次加载所有图像!没有广播或流媒体的MethodChannel!我绝对不推荐!
import 'package:flutter/material.dart';
import 'package:gallery_view/gallery_view.dart';

void main() {
  runApp(GalleryGridScreen());
}

class GalleryGridScreen extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<GalleryGridScreen> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Gallery'),
        ),
        body: GalleryView(
          crossAxisCount: 2,
          imageUrlList: [
"imageurl1",
"imageurl2",
"imageurl3",
"imageurl4",


        ]),
      ),
    );
  }
}