Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 我想在用户点击封面时查看PDF文件_Flutter_Dart - Fatal编程技术网

Flutter 我想在用户点击封面时查看PDF文件

Flutter 我想在用户点击封面时查看PDF文件,flutter,dart,Flutter,Dart,我想在用户点击封面时查看PDF文件。我是个新手 你们能找出我的密码有什么问题吗?当我轻敲这本书时,它什么也不做 我认为问题在于PDF查看器的功能 我正在使用 类书扩展了StatefulWidget{ @凌驾 _bookstate createState()=>\u bookstate(); } 类(状态扩展状态){ bool_isLoading=true; PDF文件; var-url; @凌驾 void initState(){ super.initState(); loadDocument(

我想在用户点击封面时查看PDF文件。我是个新手

你们能找出我的密码有什么问题吗?当我轻敲这本书时,它什么也不做

我认为问题在于PDF查看器的功能

我正在使用

类书扩展了StatefulWidget{
@凌驾
_bookstate createState()=>\u bookstate();
}
类(状态扩展状态){
bool_isLoading=true;
PDF文件;
var-url;
@凌驾
void initState(){
super.initState();
loadDocument();
}
loadDocument()异步{
document=wait PDFDocument.fromURL(url);
设置状态(()=>_isLoading=false);
}
changePDF(值)异步{
设置状态(()=>_isLoading=true);
如果(值==1){
document=wait PDFDocument.fromURL(url);
}否则{
打印(“无”);
}
设置状态(()=>_isLoading=false);
}
@凌驾
小部件构建(构建上下文){
返回流生成器(
流:Firestore.instance.collection('books').snapshots(),
建造商:(
上下文
快照
) {
如果(snapshot.data==null)
返回中心(
子对象:循环压缩机指示器(
背景颜色:Colors.red,
valueColor:new AlwaysStoppedAnimation(Colors.teal),
),
);
返回GridView.builder(
收缩膜:对,
gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount:3,childAspectRatio:0.7),
itemCount:snapshot.data.documents.length,
itemBuilder:(上下文,索引)=>填充(
填充:常数边集全部(8.0),
孩子:格子(
孩子:InkWell(
onTap:()异步{
PDFDocument.fromURL(snapshot.data.documents[index]['url']);
_卸载
?中心(子项:循环压缩机指示器())
:PDFViewer(文档:文档);
},
子:容器(
身高:200,
宽度:110,
装饰:盒子装饰(
boxShadow:[
箱形阴影(
颜色:颜色。红色[500]。不透明度(0.6),
扩展半径:0.5,
半径:1,
偏移量:偏移量(2,0),
),
],
颜色:颜色,白色,
边界半径:边界半径。圆形(3),
边界:边界(
样式:BorderStyle.solid,
颜色:颜色。红色[500],
宽度:0.3毫米),
子项:列(子项:[
填充物(
填充:常数边集全部(5.0),
子:容器(
孩子:Image.network(
snapshot.data.documents[索引]['image'],
宽度:100,
),
),
),
尺寸箱(高度:5),
正文(
snapshot.data.documents[索引]['name'],
)
]),
),
),
),
),
);
});
}
}

PDFViewer
返回一个小部件。如果您想在点击
InkWell
时查看pdf文件,您需要制作一个小部件,显示
PDFViewer
返回的小部件,例如

class PDFScreen extends StatelessWidget {
  PDFDocument document;
  PDFScreen({@required this.document});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      child: PDFViewer(document: document)
    );
  }
}
并将
InkWell
onTap()
更改为:

onTap: () async {
    PDFDocument.fromURL(snapshot.data.documents[index]['url']);

    _isLoading
    ? Center(child: CircularProgressIndicator())
        : Navigator.push(context, MaterialPageRoute(builder: (context) => PDFScreen(document: document)));
  },


谢谢你的回答,但我没帮上忙。点击时它什么也不做
onTap: () async {
    PDFDocument.fromURL(snapshot.data.documents[index]['url']);

    _isLoading
    ? Center(child: CircularProgressIndicator())
        : Navigator.push(context, MaterialPageRoute(builder: (context) => PDFScreen(document: document)));
  },