<commit_before>// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Copyright 2021 <NAME> - changes and modifications to original Flutter implementation of DataTable

import 'dart:math' as math;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;

/// Relative size of a column determines the share of total table width allocated
/// to each individual column. When determining column widths ratios between S, M and L
/// columns are kept (i.e. Large columns are set to 1.2x width of Medium ones)
/// - see [DataTable2.smRatio], [DataTable2.lmRatio] and same properties on [PaginatedDataTable2].
/// Default S/M ratio is 0.67,L/M ratio is 1.2
enum ColumnSize { S, M, L }

/// Extension of stock [DataColumn], adds the capability to set relative column
/// size via [size] property
@immutable
class DataColumn2 extends DataColumn {
  /// Creates the configuration for a column of a [DataTable2].
  ///
  /// The [label] argument must not be null.
  const DataColumn2(
      {required super.label,
      super.tooltip,
      super.numeric = false,
      super.onSort,
      this.size = ColumnSize.M,
      this.fixedWidth});

  /// Column sizes are determined based on available width by distributing it
  /// to individual columns accounting for their relative sizes (see [ColumnSize])
  final ColumnSize size;

  /// Defines absolute width of the column in pixel (as opposed to relative size used by default).
  /// Warning, if the width happens to be larger than available total width other
  /// columns can be clipped
  final double? fixedWidth;
}

/// Extension of standard [DataRow], adds row level tap events. Also there're
/// onSecondaryTap and onSecondaryTapDown which are not available in DataCells and
/// which can be useful in Desktop settings when a reaction to the right click is required.
@immutable
class DataRow2 extends DataRow {
  //DataRow2.fromDataRow(DataRow row) : this.cells = row.cells;

  /// Creates the configuration for a row of a [DataTable2].
  ///
  /// The [cells] argument must not be null.
  const DataRow2(
      {super.key,
      super.selected = false,
      super.onSelectChanged,
      super.color,
      required super.cells,
      this.specificRowHeight,
      this.onTap,
      this.onDoubleTap,
      super.onLongPress,
      this.onSecondaryTap,
      this.onSecondaryTapDown});

  DataRow2.byIndex(
      {int? index,
      super.selected = false,
      super.onSelectChanged,
      super.color,
      required super.cells,
      this.specificRowHeight,
      this.onTap,
      this.onDoubleTap,
      super.onLongPress,
      this.onSecondaryTap,
      this.onSecondaryTapDown})
      : super.byIndex(index: index);

  /// Specific row height, which will be used only if provided.
  /// If not provided, dataRowHeight will be applied.
  final double? specificRowHeight;

  /// Row tap handler, won't be called if tapped cell has any tap event handlers
  final GestureTapCallback? onTap;

  /// Row right click handler, won't be called if tapped cell has any tap event handlers
  final GestureTapCallback? onSecondaryTap;

  /// Row right mouse down handler, won't be called if tapped cell has any tap event handlers
  final GestureTapDownCallback? onSecondaryTapDown;

  /// Row double tap handler, won't be called if tapped cell has any tap event handlers
  final GestureTapCallback? onDoubleTap;

  // /// Row long press handler, won't be called if tapped cell has any tap event handlers
  // final GestureLongPressCallback? onLongPress;
}

/// In-place replacement of standard [DataTable] widget, mimics it API.
/// Has the header row always fixed and core of the table (with data rows)
/// scrollable and stretching to max width/height of it's container.
/// By using [DataColumn2] instead of [DataColumn] it is possible to control
/// relative column sizes (setting them to S, M and L). [DataRow2] provides
/// row-level tap event handlers.
class DataTable2 extends DataTable {
  DataTable2({
    super.key,
    required super.columns,
    super.sortColumnIndex,
    super.sortAscending = true,
    super.onSelectAll,
    super.decoration,
    super.dataRowColor,
    super.dataRowHeight,
    super.dataTextStyle,
    super.headingRowColor,
    this.fixedColumnsColor,
    this.fixedCornerColor,
    super.headingRowHeight,
    super.headingTextStyle,
    super.horizontalMargin,
    super.checkboxHorizontalMargin,
    this.bottomMargin,
    super.columnSpacing,
    super.showCheckboxColumn = true,
    super.showBottomBorder = false,
    super.dividerThickness,
    this.minWidth,
    this.scrollController,
    this.empty,
    this.border,
    this.smRatio = 0.67,
    this.fixedTopRows = 1,
    this.fixedLeftColumns = 0,
    this.lmRatio = 1.2,
    required super.rows,
  })  : _coreVerticalController = scrollController ?? ScrollController(),
        assert(fixedLeftColumns >= 0),
        assert(fixedTopRows >= 0) {
    // no point in removing listeners, evry widget instantiation will have a new scroll controller with no listeners
    // _fixedRowsHorizontalController
    //     .removeListener(_fixedRowsHorizontalControllerListener);
    _fixedRowsHorizontalController
        .addListener(_fixedRowsHorizontalControllerListener);
    if (fixedLeftColumns < columns.length + (showCheckboxColumn ? 1 : 0)) {
      _leftColumnVerticalContoller
          .addListener(_leftColumnVerticalContollerListener);
    }

    _coreHorizontalController
        .addListener(_scrollControllerCoreHorizontalListener);

    // Dirty hack to allow Stateless widget avoid memleaks and growing of number
    // of listeners for _coreVerticalController when it is provided externaly
    // via scrollController. This might brake is there're 2 data tables
    // in the screen at the same time, they have left fixed column and both
    // provide scrollController - look like a very unlikey case. Still that's
    // a tradeoff to keep DataTable2 stateless and inheriting DataTable

    if (scrollController != null) {
      _leftColumnVerticalContollerStatic = _leftColumnVerticalContoller;
      _coreVerticalControllerStatic = _coreVerticalController;
      _coreVerticalController
          .removeListener(_scrollControllerCoreVerticalListenerStatic);
      _coreVerticalController
          .addListener(_scrollControllerCoreVerticalListenerStatic);
    } else {
      _coreVerticalController
          .addListener(_scrollControllerCoreVerticalListener);
    }
  }

  // Check whether the scrollable to which the given controller is attached is currently
  // scrolling/animating it's contents, i.e. active.
  // On touch devices scrolling has intertia. E.g. when swiping up/down
  // on vertical scrollable the contents will shift gradually. During this thim
  // the controller will receive a series of events and push the to listeners.
  // Added this to address bug #106, circular jumpTo(). In a table with
  // one fixed row core controller will ask fixed row controller to jumpTo new potion.
  // In response the listener of fixed row controller will reqeuest the core scrollable to
  // do the jump which will halt intertial scrolling
  // TODO, fix issue when srolling up via core and then trying scroll to down via fixed col, fixed col scrolling is not becoming available until core stops scrolling
  static bool _isControllerActive(ScrollController controller) {
    // Somehow inertial scrolling is not an issue on Desktop platforms, the question is how that approach will work on touch Windows devices
    return !kIsWeb && (Platform.isAndroid || Platform.isIOS)
        ? controller.position.isScrollingNotifier.value
        : true;
  }

  void _fixedRowsHorizontalControllerListener() {
    if (_coreHorizontalController.hasClients &&
        _isControllerActive(_fixedRowsHorizontalController)) {
      _coreHorizontalController.jumpTo(_fixedRowsHorizontalController.offset);
    }
  }

  void _scrollControllerCoreHorizontalListener() {
    if (_fixedRowsHorizontalController.hasClients &&<commit_msg>Warning fix<commit_after>// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Copyright 2021 <NAME> - changes and modifications to original Flutter implementation of DataTable

import 'dart:math' as math;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'dart:io' show Platform;

/// Relative size of a column determines the share of total table width allocated
/// to each individual column. When determining column widths ratios between S, M and L
/// columns are kept (i.e. Large columns are set to 1.2x width of Medium ones)
/// - see [DataTable2.smRatio], [DataTable2.lmRatio] and same properties on [PaginatedDataTable2].
/// Default S/M ratio is 0.67,L/M ratio is 1.2
enum ColumnSize { S, M, L }

/// Extension of stock [DataColumn], adds the capability to set relative column
/// size via [size] property
@immutable
class DataColumn2 extends DataColumn {
  /// Creates the configuration for a column of a [DataTable2].
  ///
  /// The [label] argument must not be null.
  const DataColumn2(
      {required super.label,
      super.tooltip,
      super.numeric = false,
      super.onSort,
      this.size = ColumnSize.M,
      this.fixedWidth});

  /// Column sizes are determined based on available width by distributing it
  /// to individual columns accounting for their relative sizes (see [ColumnSize])
  final ColumnSize size;

  /// Defines absolute width of the column in pixel (as opposed to relative size used by default).
  /// Warning, if the width happens to be larger than available total width other
  /// columns can be clipped
  final double? fixedWidth;
}

/// Extension of standard [DataRow], adds row level tap events. Also there're
/// onSecondaryTap and onSecondaryTapDown which are not available in DataCells and
/// which can be useful in Desktop settings when a reaction to the right click is required.
@immutable
class DataRow2 extends DataRow {
  //DataRow2.fromDataRow(DataRow row) : this.cells = row.cells;

  /// Creates the configuration for a row of a [DataTable2].
  ///
  /// The [cells] argument must not be null.
  const DataRow2(
      {super.key,
      super.selected = false,
      super.onSelectChanged,
      super.color,
      required super.cells,
      this.specificRowHeight,
      this.onTap,
      this.onDoubleTap,
      super.onLongPress,
      this.onSecondaryTap,
      this.onSecondaryTapDown});

  DataRow2.byIndex(
      {int? index,
      super.selected = false,
      super.onSelectChanged,
      super.color,
      required super.cells,
      this.specificRowHeight,
      this.onTap,
      this.onDoubleTap,
      super.onLongPress,
      this.onSecondaryTap,
      this.onSecondaryTapDown})
      : super.byIndex(index: index);

  /// Specific row height, which will be used only if provided.
  /// If not provided, dataRowHeight will be applied.
  final double? specificRowHeight;

  /// Row tap handler, won't be called if tapped cell has any tap event handlers
  final GestureTapCallback? onTap;

  /// Row right click handler, won't be called if tapped cell has any tap event handlers
  final GestureTapCallback? onSecondaryTap;

  /// Row right mouse down handler, won't be called if tapped cell has any tap event handlers
  final GestureTapDownCallback? onSecondaryTapDown;

  /// Row double tap handler, won't be called if tapped cell has any tap event handlers
  final GestureTapCallback? onDoubleTap;

  // /// Row long press handler, won't be called if tapped cell has any tap event handlers
  // final GestureLongPressCallback? onLongPress;
}

/// In-place replacement of standard [DataTable] widget, mimics it API.
/// Has the header row always fixed and core of the table (with data rows)
/// scrollable and stretching to max width/height of it's container.
/// By using [DataColumn2] instead of [DataColumn] it is possible to control
/// relative column sizes (setting them to S, M and L). [DataRow2] provides
/// row-level tap event handlers.
class DataTable2 extends DataTable {
  DataTable2({
    super.key,
    required super.columns,
    super.sortColumnIndex,
    super.sortAscending = true,
    super.onSelectAll,
    super.decoration,
    super.dataRowColor,
    super.dataRowHeight,
    super.dataTextStyle,
    super.headingRowColor,
    this.fixedColumnsColor,
    this.fixedCornerColor,
    super.headingRowHeight,
    super.headingTextStyle,
    super.horizontalMargin,
    super.checkboxHorizontalMargin,
    this.bottomMargin,
    super.columnSpacing,
    super.showCheckboxColumn = true,
    super.showBottomBorder = false,
    super.dividerThickness,
    this.minWidth,
    this.scrollController,
    this.empty,
    this.border,
    this.smRatio = 0.67,
    this.fixedTopRows = 1,
    this.fixedLeftColumns = 0,
    this.lmRatio = 1.2,
    required super.rows,
  })  : _coreVerticalController = scrollController ?? ScrollController(),
        assert(fixedLeftColumns >= 0),
        assert(fixedTopRows >= 0) {
    // no point in removing listeners, evry widget instantiation will have a new scroll controller with no listeners
    // _fixedRowsHorizontalController
    //     .removeListener(_fixedRowsHorizontalControllerListener);
    _fixedRowsHorizontalController
        .addListener(_fixedRowsHorizontalControllerListener);
    if (fixedLeftColumns < columns.length + (showCheckboxColumn ? 1 : 0)) {
      _leftColumnVerticalContoller
          .addListener(_leftColumnVerticalContollerListener);
    }

    _coreHorizontalController
        .addListener(_scrollControllerCoreHorizontalListener);

    // Dirty hack to allow Stateless widget avoid memleaks and growing of number
    // of listeners for _coreVerticalController when it is provided externaly
    // via scrollController. This might brake is there're 2 data tables
    // in the screen at the same time, they have left fixed column and both
    // provide scrollController - look like a very unlikey case. Still that's
    // a tradeoff to keep DataTable2 stateless and inheriting DataTable

    if (scrollController != null) {
      _leftColumnVerticalContollerStatic = _leftColumnVerticalContoller;
      _coreVerticalControllerStatic = _coreVerticalController;
      _coreVerticalController
          .removeListener(_scrollControllerCoreVerticalListenerStatic);
      _coreVerticalController
          .addListener(_scrollControllerCoreVerticalListenerStatic);
    } else {
      _coreVerticalController
          .addListener(_scrollControllerCoreVerticalListener);
    }
  }

  // Check whether the scrollable to which the given controller is attached is currently
  // scrolling/animating it's contents, i.e. active.
  // On touch devices scrolling has intertia. E.g. when swiping up/down
  // on vertical scrollable the contents will shift gradually. During this thim
  // the controller will receive a series of events and push the to listeners.
  // Added this to address bug #106, circular jumpTo(). In a table with
  // one fixed row core controller will ask fixed row controller to jumpTo new potion.
  // In response the listener of fixed row controller will reqeuest the core scrollable to
  // do the jump which will halt intertial scrolling
  // TODO, fix issue when srolling up via core and then trying scroll to down via fixed col, fixed col scrolling is not becoming available until core stops scrolling
  // TODO, add test
  static bool _isControllerActive(ScrollController controller) {
    // Somehow inertial scrolling is not an issue on Desktop platforms, the question is how that approach will work on touch Windows devices
    return !kIsWeb && (Platform.isAndroid || Platform.isIOS)
        ? controller.position.isScrollingNotifier.value
        : true;
  }

  void _fixedRowsHorizontalControllerListener() {
    if (_coreHorizontalController.hasClients &&
        _isControllerActive(_fixedRowsHorizontalController)) {
      _coreHorizontalController.jumpTo(_fixedRowsHorizontalController.offset);
    }
  }

  void _scrollControllerCoreHorizontalListener() {
    if (_fixedRowsHorizontalController.hasClients &&
{'fraction_non_alphanumeric': 0.07420300476364969, 'fraction_numerical': 0.005618663735189935, 'mean_word_length': 3.3806848582129483, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6855146', 'n_tokens_mistral': 4446, 'n_tokens_neox': 4255, 'n_words': 1636}