小部件库捕获到异常。抛出构建PDFMain(脏,状态:_PDFMainState#aa56c):在构建过程中调用setState()或markNeedsBuild()

时间:2020-10-24 16:08:34

标签: firebase flutter firebase-realtime-database firebase-storage

从firebase存储中获取和检索PDF文件时出现异常,我无法在屏幕上显示pdf文件。

。这是代码。

awk '                                        ##Starting awk program from here.
{
  a[$0]++                                    ##Creating array a with index of current line and increasing its value with 1 here.
}
END{                                         ##Starting END block of this program from here.
  PROCINFO["sorted_in"] = "@val_num_desc"    ##Making gwk to sort from value in array gawk GREAT function :)
  for(i in a){                               ##Traversing through a here.
    c[a[i]]=(c[a[i]]>i?c[a[i]]:i)            ##Creating array c with index of value of a with condition if
                                             ##value of c(with index of a[i]) is greater than i then keep its value else assign i to it.
  }
  PROCINFO["sorted_in"] = "@ind_num_desc"    ##Making gawk to sort by index in array gawk another GREAT function :)
  for(o in c){                               ##Traversing through c here.
    print o,c[o]                             ##Printing index and value of c with index of o here.
  }
}' Input_file                                ##Mentioning Input_file name here.

我正面临这个问题,现在我很困惑如何解决..我的调试控制台看起来像这样...

import 'dart:io';

import 'package:firebase_storage/firebase_storage.dart';
// import 'package:flutter/services.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
// import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:http/http.dart' as http;

class PDFMain extends StatefulWidget {
  @override
  _PDFMainState createState() => _PDFMainState();
}

// final FirebaseStorage storage = FirebaseStorage.instance;

// Future<String> uploadImage(var durl) async {
//   StorageReference ref = storage.ref().child("/testing/LT.pdf");
//   StorageUploadTask uploadTask = ref.putFile(durl);
//   var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
//   var url = dowurl.toString();
//   return url;
// }

class _PDFMainState extends State<PDFMain> {
  Future downloadurl() async {
    String downloadAddress = await _reference.getDownloadURL();
    print(_reference);
    setState(() {
      urlPDFPath = downloadAddress;
      print("URL =====>>>>" + urlPDFPath);
    });
  }

  @override
  Widget build(BuildContext context) {
    return urlPDFPath != null
        ? Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => PDFViewPage(
                path: urlPDFPath,
              ),
            ),
          )
        : Offset;
  }
}

String urlPDFPath = '';


StorageReference _reference =
    FirebaseStorage.instance.ref().child("Laplace transforms.pdf");

Future<File> getFileFromUrl(String url) async {
  try {
    var data = await http.get(url);
    // StorageReference sr = StorageReference.getReference();
    var byte = data.bodyBytes;
    var dir = await getApplicationDocumentsDirectory();
    File file = File("${dir.path}/Laplace transforms.pdf");

    File urlFile = await file.writeAsBytes(byte);
    return urlFile;
  } catch (e) {
    throw Exception("Error In Loding The file");
  }
}

class PDFViewPage extends StatefulWidget {
  final String path;

  const PDFViewPage({Key key, this.path}) : super(key: key);

  @override
  _PDFViewPageState createState() => _PDFViewPageState();
}

class _PDFViewPageState extends State<PDFViewPage> {
  bool pdfready = false;
  int _totalPages = 0;
  int _currentPage = 0;
  PDFViewController _pdfViewController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Document"),
      ),
      body: Stack(
        children: <Widget>[
          PDFView(
            filePath: widget.path,
            enableSwipe: true,
            autoSpacing: true,
            pageSnap: true,
            onError: (e) {
              print(e);
            },
            onRender: (_pages) {
              setState(() {
                _totalPages = _pages;
                pdfready = true;
              });
            },
            onViewCreated: (PDFViewController vc) {
              _pdfViewController = vc;
            },
            onPageChanged: (int page, int total) {
              setState(() {});
            },
            swipeHorizontal: true,
          ),
          !pdfready ? Center(child: CircularProgressIndicator()) : Offstage(),
        ],
      ),
    );
  }
}

这是Flutter Doctor

[38;5;248mLaunching lib\main.dart on AOSP on IA Emulator in debug mode...[39;49m
 lib\main.dart
Parameter format not correct -
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:53055/BXqeXOMktEU=/ws
D/EGL_emulation( 4320): eglMakeCurrent: 0xcae376c0: ver 3 0 (tinfo 0xcae3ae00)
D/eglCodecCommon( 4320): setVertexArrayObject: set vao to 0 (0) 1 0

[38;5;248m════════ Exception caught by widgets library ═══════════════════════════════════[39;49m
[38;5;244mThe following assertion was thrown building PDFMain(dirty, state: _PDFMainState#aa56c):[39;49m
setState() or markNeedsBuild() called during build.

[38;5;244mThis Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets.  A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.[39;49m
[38;5;244mThe widget on which setState() or markNeedsBuild() was called was: Overlay-[LabeledGlobalKey<OverlayState>#55b78][39;49m
    [38;5;244mstate: OverlayState#d09f8(entries: [OverlayEntry#513dc(opaque: true; maintainState: false), OverlayEntry#a615b(opaque: false; maintainState: true), OverlayEntry#e59a6(opaque: false; maintainState: false), OverlayEntry#ff6b4(opaque: false; maintainState: true), OverlayEntry#41b02(opaque: false; maintainState: false), OverlayEntry#37232(opaque: false; maintainState: true)])[39;49m
[38;5;244mThe widget which was currently being built when the offending call was made was: PDFMain[39;49m
    [38;5;244mdirty[39;49m
    [38;5;244mstate: _PDFMainState#aa56c[39;49m
[38;5;244mThe relevant error-causing widget was[39;49m
[38;5;248mPDFMain[39;49m
 lib\routes_map.dart
[38;5;244mWhen the exception was thrown, this was the stack[39;49m
[38;5;244m#0      Element.markNeedsBuild.<anonymous closure>[39;49m
 package:flutter/…/widgets/framework.dart
[38;5;244m#1      Element.markNeedsBuild[39;49m
 package:flutter/…/widgets/framework.dart
[38;5;244m#2      State.setState[39;49m
 package:flutter/…/widgets/framework.dart
[38;5;244m#3      OverlayState.rearrange[39;49m
 package:flutter/…/widgets/overlay.dart
[38;5;244m#4      NavigatorState._flushHistoryUpdates[39;49m
 package:flutter/…/widgets/navigator.dart
[38;5;244m...[39;49m
[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m
E/flutter ( 4320): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2932 pos 18: 'ntState == _RouteLifecy': is not true.
[38;5;244mE/flutter ( 4320): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)[39;49m
[38;5;244mE/flutter ( 4320): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)[39;49m
[38;5;244mE/flutter ( 4320): #2      _RouteEntry.handlePush.<anonymous closure>[39;49m
 package:flutter/…/widgets/navigator.dart
[38;5;244mE/flutter ( 4320): #3      TickerFuture.whenCompleteOrCancel.thunk[39;49m
 package:flutter/…/scheduler/ticker.dart
[38;5;244mE/flutter ( 4320): #4      _rootRunUnary (dart:async/zone.dart:1198:47)[39;49m
[38;5;244mE/flutter ( 4320): #5      _CustomZone.runUnary (dart:async/zone.dart:1100:19)[39;49m
[38;5;244mE/flutter ( 4320): #6      _FutureListener.handleValue (dart:async/future_impl.dart:143:18)[39;49m
[38;5;244mE/flutter ( 4320): #7      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)[39;49m
[38;5;244mE/flutter ( 4320): #8      Future._propagateToListeners (dart:async/future_impl.dart:725:32)[39;49m
[38;5;244mE/flutter ( 4320): #9      Future._completeWithValue (dart:async/future_impl.dart:529:5)[39;49m
[38;5;244mE/flutter ( 4320): #10     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)[39;49m
[38;5;244mE/flutter ( 4320): #11     _rootRun (dart:async/zone.dart:1190:13)[39;49m
[38;5;244mE/flutter ( 4320): #12     _CustomZone.run (dart:async/zone.dart:1093:19)[39;49m
[38;5;244mE/flutter ( 4320): #13     _CustomZone.runGuarded (dart:async/zone.dart:997:7)[39;49m
[38;5;244mE/flutter ( 4320): #14     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)[39;49m
[38;5;244mE/flutter ( 4320): #15     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)[39;49m
[38;5;244mE/flutter ( 4320): #16     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)[39;49m
E/flutter ( 4320):
E/flutter ( 4320): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2932 pos 18: 'ntState == _RouteLifecy': is not true.
[38;5;244mE/flutter ( 4320): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)[39;49m
[38;5;244mE/flutter ( 4320): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)[39;49m
[38;5;244mE/flutter ( 4320): #2      _RouteEntry.handlePush.<anonymous closure>[39;49m
 package:flutter/…/widgets/navigator.dart
[38;5;244mE/flutter ( 4320): #3      TickerFuture.whenCompleteOrCancel.thunk[39;49m
 package:flutter/…/scheduler/ticker.dart
[38;5;244mE/flutter ( 4320): #4      _rootRunUnary (dart:async/zone.dart:1198:47)[39;49m
[38;5;244mE/flutter ( 4320): #5      _CustomZone.runUnary (dart:async/zone.dart:1100:19)[39;49m
[38;5;244mE/flutter ( 4320): #6      _FutureListener.handleValue (dart:async/future_impl.dart:143:18)[39;49m
[38;5;244mE/flutter ( 4320): #7      Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)[39;49m
[38;5;244mE/flutter ( 4320): #8      Future._propagateToListeners (dart:async/future_impl.dart:725:32)[39;49m
[38;5;244mE/flutter ( 4320): #9      Future._completeWithValue (dart:async/future_impl.dart:529:5)[39;49m
[38;5;244mE/flutter ( 4320): #10     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:567:7)[39;49m
[38;5;244mE/flutter ( 4320): #11     _rootRun (dart:async/zone.dart:1190:13)[39;49m
[38;5;244mE/flutter ( 4320): #12     _CustomZone.run (dart:async/zone.dart:1093:19)[39;49m
[38;5;244mE/flutter ( 4320): #13     _CustomZone.runGuarded (dart:async/zone.dart:997:7)[39;49m
[38;5;244mE/flutter ( 4320): #14     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)[39;49m
[38;5;244mE/flutter ( 4320): #15     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)[39;49m
[38;5;244mE/flutter ( 4320): #16     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)[39;49m
E/flutter ( 4320):
E/flutter ( 4320): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: plugins.endigo.io/pdfview
E/flutter ( 4320):  at io.flutter.plugin.platform.PlatformViewsController$1.createVirtualDisplayForPlatformView(PlatformViewsController.java:199)
E/flutter ( 4320):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:104)
E/flutter ( 4320):  at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
E/flutter ( 4320):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/flutter ( 4320):  at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/flutter ( 4320):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
E/flutter ( 4320):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 4320):  at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter ( 4320):  at android.os.Looper.loop(Looper.java:160)
E/flutter ( 4320):  at android.app.ActivityThread.main(ActivityThread.java:6669)
E/flutter ( 4320):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 4320):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/flutter ( 4320):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter ( 4320): , null, null)
[38;5;244mE/flutter ( 4320): #0      StandardMethodCodec.decodeEnvelope[39;49m
 package:flutter/…/services/message_codecs.dart
[38;5;244mE/flutter ( 4320): #1      MethodChannel._invokeMethod[39;49m
 package:flutter/…/services/platform_channel.dart
E/flutter ( 4320): <asynchronous suspension>
[38;5;244mE/flutter ( 4320): #2      MethodChannel.invokeMethod[39;49m
 package:flutter/…/services/platform_channel.dart
[38;5;244mE/flutter ( 4320): #3      TextureAndroidViewController._sendCreateMessage[39;49m
 package:flutter/…/services/platform_views.dart
[38;5;244mE/flutter ( 4320): #4      AndroidViewController.create[39;49m
 package:flutter/…/services/platform_views.dart
[38;5;244mE/flutter ( 4320): #5      TextureAndroidViewController.create[39;49m
 package:flutter/…/services/platform_views.dart
[38;5;244mE/flutter ( 4320): #6      TextureAndroidViewController.setSize[39;49m
 package:flutter/…/services/platform_views.dart
[38;5;244mE/flutter ( 4320): #7      RenderAndroidView._sizePlatformView[39;49m
 package:flutter/…/rendering/platform_view.dart
[38;5;244mE/flutter ( 4320): #8      RenderAndroidView.performResize[39;49m
 package:flutter/…/rendering/platform_view.dart
[38;5;244mE/flutter ( 4320): #9      RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #10     RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244mE/flutter ( 4320): #11     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #12     RenderStack.performLayout[39;49m
 package:flutter/…/rendering/stack.dart
[38;5;244mE/flutter ( 4320): #13     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #14     MultiChildLayoutDelegate.layoutChild[39;49m
 package:flutter/…/rendering/custom_layout.dart
[38;5;244mE/flutter ( 4320): #15     _ScaffoldLayout.performLayout[39;49m
 package:flutter/…/material/scaffold.dart
[38;5;244mE/flutter ( 4320): #16     MultiChildLayoutDelegate._callPerformLayout[39;49m
 package:flutter/…/rendering/custom_layout.dart
[38;5;244mE/flutter ( 4320): #17     RenderCustomMultiChildLayoutBox.performLayout[39;49m
 package:flutter/…/rendering/custom_layout.dart
[38;5;244mE/flutter ( 4320): #18     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #19     RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244mE/flutter ( 4320): #20     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #21     RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244mE/flutter ( 4320): #22     _RenderCustomClip.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244mE/flutter ( 4320): #23     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #24     RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244mE/flutter ( 4320): #25     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #26     RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
[38;5;244mE/flutter ( 4320): #27     RenderObject.layout[39;49m
 package:flutter/…/rendering/object.dart
[38;5;244mE/flutter ( 4320): #28     RenderProxyBoxMixin.performLayout[39;49m
 package:flutter/…/rendering/proxy_box.dart
E/flutter ( 4320): #29     RenderObject.layout (package:flutter/src/re
W/le.Flutter_ICS( 4320): JNI critical lock held for 16.466ms on Thread[1,tid=4320,Runnable,Thread*=0xe67dc000,peer=0x74a79760,"main"]
W/le.Flutter_ICS( 4320): JNI critical lock held for 24.016ms on Thread[1,tid=4320,Runnable,Thread*=0xe67dc000,peer=0x74a79760,"main"]
I/le.Flutter_ICS( 4320): WaitForGcToComplete blocked ProfileSaver on None for 46.543ms

我正在学习颤抖。.请帮助我

0 个答案:

没有答案