Browse Source

ComPDFKit(flutter) - 1.修复ios上Sliderbar显示问题

liuxiaolong 1 year ago
parent
commit
728cabac1b

+ 1 - 1
example/ios/Podfile.lock

@@ -25,4 +25,4 @@ SPEC CHECKSUMS:
 
 PODFILE CHECKSUM: 3fa3b71e93b773646ea923db9defae9e3f1717ab
 
-COCOAPODS: 1.12.1
+COCOAPODS: 1.11.3

+ 22 - 1
example/lib/main.dart

@@ -19,6 +19,8 @@ class MyApp extends StatefulWidget {
 class _MyAppState extends State<MyApp> {
   String _version = '';
 
+  String _buildTag = '';
+
   @override
   void initState() {
     super.initState();
@@ -34,6 +36,11 @@ class _MyAppState extends State<MyApp> {
     setState(() {
       _version = ver;
     });
+    comPDFKit.getSDKBuildTag().then((value) {
+      setState(() {
+        _buildTag = value;
+      });
+    });
   }
 
   @override
@@ -44,7 +51,21 @@ class _MyAppState extends State<MyApp> {
       darkTheme: comPDFKitDarkTheme,
       home: Scaffold(
           body: SafeArea(
-              child: const CPDFReaderViewPage())),
+              child: Stack(
+        children: [
+          const CPDFReaderViewPage(),
+          Positioned(
+            top: 20,
+            left: 10,
+            child: Text('VersionCode:$_version', style: TextStyle(fontSize: 10),),
+          ),
+          Positioned(
+            top: 50,
+            left: 10,
+            child: Text('BuildTag:$_buildTag', style: TextStyle(fontSize: 10),),
+          )
+        ],
+      ))),
     );
   }
 }

+ 29 - 14
lib/tools/common/views/pdfview/cpdf_page_slider_bar.dart

@@ -27,7 +27,7 @@ class CPDFPageNavigationSliderBar extends StatefulWidget {
 
 class _CPDFPageNavigationSliderBarState
     extends State<CPDFPageNavigationSliderBar> {
-  int _pageCount = 0;
+  int _pageCount = 1;
 
   @override
   void initState() {
@@ -36,26 +36,41 @@ class _CPDFPageNavigationSliderBarState
   }
 
   void _initDocumentData() async {
-    int pageCount = await widget.ctrl.document.getPageCount();
-    setState(() {
-      _pageCount = pageCount;
-    });
+    try{
+      int pageCount = await widget.ctrl.document.getPageCount();
+      setState(() {
+        _pageCount = pageCount;
+      });
+    }catch(e){
+
+    }
   }
 
   @override
   Widget build(BuildContext context) {
     return StreamBuilder(
-      initialData: 1,
+      initialData: 0,
       stream: widget.ctrl.currentPageIndexStream.stream,
       builder: (context, pageIndex) {
-        return CPDFSliderBar(
-          position: widget.position,
-          value: (pageIndex.data! + 1).toDouble(),
-          maxValue: _pageCount.toDouble(),
-          callback: (pageIndex) {
-            widget.ctrl.setDisplayPageIndex(pageIndex);
-          },
-        );
+        if (pageIndex.data != null) {
+          return CPDFSliderBar(
+            position: widget.position,
+            value: (pageIndex.data! + 1).toDouble(),
+            maxValue: _pageCount.toDouble(),
+            callback: (pageIndex) {
+              widget.ctrl.setDisplayPageIndex(pageIndex);
+            },
+          );
+        } else {
+          return CPDFSliderBar(
+            position: widget.position,
+            value: 1,
+            maxValue: _pageCount.toDouble(),
+            callback: (pageIndex) {
+              widget.ctrl.setDisplayPageIndex(pageIndex);
+            },
+          );
+        }
       },
     );
   }