请解释语法 - flutter bloc provider using inherited widget

Please Explain syntax - flutter bloc provider using inherited widget

我不明白构造函数部分和静态函数部分。 极好的? dependOnInheritedWidgetOfExactType?

import 'comments_bloc.dart';
export 'comments_bloc.dart';

class CommentsProvider extends InheritedWidget {
  final CommentsBloc commentsBloc;
  CommentsProvider({Key key, Widget child})
      : commentsBloc = CommentsBloc(), // what this line is doing.
        super(key: key, child: child);

  bool updateShouldNotify(_) => true;

//below code?
  static CommentsBloc of(BuildContext context) {
    return context
        .dependOnInheritedWidgetOfExactType<CommentsProvider>()
        .commentsBloc;
  }
}

第 1 步:dependOnInheritedWidgetOfExactType 方法使后代小部件能够访问其 BuildContext 中包含的最近的祖先 InheritedWidget 实例,在您的代码中是 CommentsProvider

第 2 步:而 .commentsBloc 表示访问此 CommentsProvider 的属性,在您的代码中是 final CommentsBloc commentsBloc;