類pdf screen extends stateful widget {
最終字符串;
?最終字符串路徑;
?最終字符串標題;
?PDFScreen({Key key,this.url,this.path,this . title }):super(Key:Key);
?_ pdfscreenstate createstate()= & gt;_ pdf screenstate();
}
class _ pdfscrenstateextends state with WidgetsBindingObserver {
最終完成者_控制器=
完成符();
?int pages = 0;
?intcurrentPage = 0;
?boolisReady = false
?StringerrorMessage =“”;
?@覆蓋
?Widgetbuild(BuildContext上下文){
返回腳手架(
appBar:AppBar(
標高:0,
前導:新圖標按鈕(
圖標:Image.asset(
Utils.getImgPath('icon_back '),
寬度:18,
身高:36,
?),
?onPressed: () {
Navigator.of(上下文)。pop();
?},
),
中心標題:沒錯,
標題:正文(
widget.title,
?樣式:TextStyle(fontSize:17.0),
),
?),
?正文:堆棧(
兒童:[
已定位(
height:media query . of(context). size . height-(utils . getheightsize(80,context) *2),
?width:media query . of(context). size . width,
?子項目:PDFView(
filePath:widget.path,
enableSwipe:真的,
swipeHorizontal:沒錯,
自動間距:假,
pageFling:沒錯,
pageSnap:沒錯,
defaultPage:currentPage
fitPolicy: FitPolicy。兩者都有,
預防導航:
false,//如果設置為true,則在flutter中處理鏈接
onRender: (_pages) {
setState(() {
pages = _ pages
isReady = true
?});
},
onError:(錯誤){
setState(() {
error message = error . tostring();
?});
?print(error . tostring());
},
onPageError:(第頁,錯誤){
setState(() {
error message = ' $ page:$ { error . tostring()} ';
?});
?print(' $ page:$ { error . tostring()} ');
},
onview created:(pdf view controller pdf view controller){
_ controller . complete(pdf view controller);
},
onLinkHandler:(字符串uri) {
print(' goto uri:$ uri ');
},
onPageChanged: (int page,int total) {
print('換頁:$ page/$ total ');
?setState(() {
currentPage = page
?});
},
?),
?),
?已定位(
底部:0,
?height: Utils.getHeightSize(80,上下文),
?width:media query . of(context). size . width,
?子:容器(
// padding: EdgeInsets.only(左:10.0,右:10.0,上:10.0,下:10.0),
裝飾:BoxDecoration(
顏色:彩色.白色,
?border:border . all(color:app colors . shade Gary),
?boxShadow: [
//參考:/video/6443
箱形陰影(
顏色:AppColors.shadeGary,
offset:Offset(0.0,0.0),
模糊半徑:3.0,
擴散半徑:0.0),
?],
),
子:堆棧(
兒童:[
行(
mainAxisSize: MainAxisSize.min,
?兒童:[
容器(),
展開(子級:SizedBox()),
容器(
身高:42.0,
?width: Utils.getWidthSize(90,上下文),
?margin:EdgeInsets.only(右:20.0,下:5.0),
?裝飾:BoxDecoration(//邊框線
borderRadius:borderRadius . circular(21.0),?//圓角
漸變:線性漸變(
顏色:[顏色(0xFF5FD27A),顏色(0xFF3FAF6F)],
),
?),
?child:TextButton(
樣式:ButtonStyle(
overlay color:materialstateproperty . all(colors . transparent),
?foreground color:materialstateproperty . resolve with(
(州){
if(States . contains(material state . pressed)){
//按下時的顏色
返回Colors.transparent
?}
//默認狀態是灰色。
?返回Colors.transparent
},
?),
),
子代:文本(
global translations . text(" msg _ download ")。
?樣式:TextStyle(顏色:Colors.white),
),
onPressed: () {
launchPdfURL(widget . URL);
},
?),
),
?],
),
?],
),
?)),
?errorMessage.isEmpty
!isReady
中心(
child:circular progression indicator(),
?)
:容器()
:居中(
child:Text(錯誤消息),
?)
],
?),
?//floating action button:future builder(
//?未來:_controller.future,
//?生成器:(上下文,異步快照快照){
// if (snapshot.hasData) {
// ?return floating action button . extended(
// label: Text("Go to ${pages ~/ 2} ",
// onPressed: () async {
// ?await snapshot . data . set page(pages ~/2);
// },
// ?);
// }
//
//返回容器();
//?},
// ),
);
?}
launchPdfURL(字符串url) {
啟動(網址);
?}
}