didChangeDependencies method

  1. @override
void didChangeDependencies()
override

Called when a dependency of this State object changes.

For example, if the previous call to build referenced an InheritedWidget that later changed, the framework would call this method to notify this object about the change.

This method is also called immediately after initState. It is safe to call BuildContext.dependOnInheritedWidgetOfExactType from this method.

Subclasses rarely override this method because the framework always calls build after a dependency changes. Some subclasses do override this method because they need to do some expensive work (e.g., network fetches) when their dependencies change, and that work would be too expensive to do for every build.

Implementation

@override
void didChangeDependencies() {
  final ThemeData themeData = Theme.of(context);
  final SfColorScheme colorScheme = SfTheme.colorScheme(context);

  _dataGridConfiguration.isDesktop = kIsWeb ||
      themeData.platform == TargetPlatform.macOS ||
      themeData.platform == TargetPlatform.windows ||
      themeData.platform == TargetPlatform.linux;

  _dataGridConfiguration.isMacPlatform =
      themeData.platform == TargetPlatform.macOS;
  _dataGridConfiguration.columnDragAndDropController.isWindowsPlatform =
      themeData.platform == TargetPlatform.windows && !kIsWeb;
  // Sets column resizing hitTestPrecision based on the platform.

  if (_dataGridConfiguration.allowColumnsResizing) {
    _dataGridConfiguration.columnResizeController.setHitTestPrecision();
  }

  _onDataGridTextDirectionChanged(Directionality.of(context));

  _onDataGridThemeDataChanged(SfDataGridTheme.of(context), colorScheme);
  _onDataGridTextScaleFactorChanged(
      MediaQuery.textScalerOf(context).scale(1));
  _updateVisualDensity(themeData.visualDensity);
  _dataGridConfiguration.defaultColumnWidth = widget.defaultColumnWidth.isNaN
      ? _dataGridConfiguration.isDesktop
          ? 100
          : 90
      : widget.defaultColumnWidth;
  _onDataGridLocalizationsChanged(SfLocalizations.of(context));

  // This is used to dismiss the filtering popup menu manually when resizing
  // the current window size. By default, the popup menu will not be
  // dismissed when resizing the window. So, we have used this workaround to
  // achieve this behavior.
  if (_dataGridConfiguration.isDesktop) {
    final Size currentScreenSize = MediaQuery.of(context).size;
    _screenSize ??= currentScreenSize;
    if (_screenSize != currentScreenSize &&
        _dataGridConfiguration
            .dataGridFilterHelper!.isFilterPopupMenuShowing) {
      Navigator.pop(context);
      _dataGridConfiguration.dataGridFilterHelper!.isFilterPopupMenuShowing =
          false;
    }
    _screenSize = currentScreenSize;
  }

  super.didChangeDependencies();
}