1.在 pubspec.yaml 檔案中新增如下的包:
dependencies:
# pdf 閱讀器
flutter_full_pdf_viewer: ^1.0.6
# 獲取系統目錄,因為從網路獲取的pdf檔案,需要儲存到手機,所以需要用到這個包
path_provider: ^1.5.0
2.官方demo:
import 'dart:async';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_full_pdf_viewer/full_pdf_viewer_scaffold.dart';
import 'package:path_provider/path_provider.dart';
void main()
@override
} string pathpdf = "";
@override
void initstate() );
});} futurecreatefileofpdfurl() async
@override
widget build(buildcontext context)
}/// /////////////////////////// 顯示 pdf **件 //////////////////////////// ///
class pdfscreen extends statelesswidget ,
),],
),path: pathpdf,
);}}
3.官方demo 顯示效果:
主要有兩個原始碼檔案,分別是 full_pdf_viewer_plugin.dart 和 full_pdf_viewer_scaffold.dart 檔案
1.full_pdf_viewer_plugin.dart
import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
enum pdfviewstate
class pdfviewerplugin
final _ondestroy = new streamcontroller.broadcast();
streamget ondestroy => _ondestroy.stream;
future_handlemessages(methodcall call) async
} futurelaunch(string path, ) async ;
if (rect != null) ;
}await _channel.invokemethod('launch', args);
} /// close the pdfviewer
/// will trigger the [ondestroy] event
future close() => _channel.invokemethod('close');
/// adds the plugin as activityresultlistener
/// only needed and used on android
future registeracitivityresultlistener() =>
_channel.invokemethod('registeracitivityresultlistener');
/// removes the plugin as activityresultlistener
/// only needed and used on android
future removeacitivityresultlistener() =>
_channel.invokemethod('removeacitivityresultlistener');
/// close all streams
void dispose()
/// resize pdfviewer
futureresize(rect rect) async ;
args['rect'] = ;
await _channel.invokemethod('resize', args);
}}
2.full_pdf_viewer_scaffold.dart其實筆者在實際的使用過程中,是把它提取出來使用的,這樣做是為了可以修改原始碼,讓他符合自己的使用場景。當pdf不是全屏顯示時,就會遇到狀態列、導航欄高度的問題,可以看筆者寫的這篇文章。
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_full_pdf_viewer/full_pdf_viewer_plugin.dart';
class pdfviewerscaffold extends statefulwidget ) : super(key: key);
@override
_pdfviewscaffoldstate createstate() => new _pdfviewscaffoldstate();
}class _pdfviewscaffoldstate extends state
@override
void dispose()
@override
widget build(buildcontext context) else );}}
return new scaffold(
body: const center(child: const circularprogressindicator()));
} rect _buildrect(buildcontext context)
return new rect.fromltwh(0.0, top, mediaquery.size.width, height);
}}
原文:
檔案瀏覽命令
用處 日誌檔案,xml等檔案 一,cat命令 快捷檢視當前檔案的內容 格式 cat 檔名 注意 適合檢視少量資訊檔案,無法檢視大量資訊檔案 二,more命令 分頁顯示檔案內容 支援跳轉行等功能 格式 more檔名 操作 enter 向下n行,需要定義,預設為1行 空格 向下滾動一屏或ctrl f q...
C 瀏覽檔案按鈕選項 瀏覽檔案所在路徑
選擇計算機磁碟中的檔案 顯示檔案路徑 openfiledialog open new openfiledialog open.showdialog filepath txt.text open.filename 選擇計算機某檔案所在資料夾 顯示資料夾的路徑 folderbrowserdialog o...
瀏覽資料夾
browseinfo stbrowseinfo itemidlist pstitemidlist tchar acfilepath max path open select directory dialog memset stbrowseinfo,0,sizeof browseinfo stbrow...