簡體   English   中英

async_provider.dart 中的 StreamProvider._ 構造函數有什么好處?

[英]What is the benefit of the StreamProvider._ constructor in async_provider.dart?

我正在學習 Flutter 的 state 管理的 Provider。 我不明白為什么要為 StreamProvier 設置“_”構造函數。 是否可以在沒有構造函數“_”的情況下實現 StreamProvider.value? 謝謝! 這是代碼片段和文件鏈接

/// Listens to [value] and expose it to all of [StreamProvider] descendants.
  StreamProvider.value({
    Key key,
    @required Stream<T> value,
    T initialData,
    ErrorBuilder<T> catchError,
    UpdateShouldNotify<T> updateShouldNotify,
    Widget child,
  }) : this._(
          key: key,
          delegate: SingleValueDelegate(value),
          initialData: initialData,
          catchError: catchError,
          updateShouldNotify: updateShouldNotify,
          child: child,
        );
  StreamProvider._({
    Key key,
    @required ValueStateDelegate<Stream<T>> delegate,
    this.initialData,
    this.catchError,
    this.updateShouldNotify,
    this.child,
  }) : super(key: key, delegate: delegate);

使用此構造函數主要是因為 MultiProvider 當前的工作方式:MultiProvider 依賴於克隆小部件。

問題是,提供者(包括 StreamProvider)往往有兩個公共構造函數,具有不同的參數。

因此,該私有構造函數用作使用 MultiProvider 的“克隆”方法的實現細節。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM