Пожалуйста, объясните синтаксис - провайдер flutter blo c, используя унаследованный виджет - PullRequest
0 голосов
/ 09 апреля 2020

Я не понимаю конструкторскую часть и stati c функциональную часть. супер? зависимостьOnInheritedWidgetOfExactType?

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 Ответ

0 голосов
/ 09 апреля 2020

Шаг 1: метод dependOnInheritedWidgetOfExactType позволяет виджету-потомку обращаться к ближайшему экземпляру InheritedWidget предка, заключенному в его BuildContext, в вашем коде это CommentsProvider

Шаг 2: И .commentsBloc означает доступ к этому атрибуту CommentsProvider, в вашем коде это final CommentsBloc commentsBloc;

...