LCOV - code coverage report
Current view: top level - src/styles - layout_settings.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 13 7.7 %
Date: 2022-02-12 14:49:12 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:math' as math;
       2             : 
       3             : import 'package:flutter/rendering.dart';
       4             : import 'package:flutter/widgets.dart';
       5             : import '../day_picker.dart';
       6             : import '../month_picker.dart';
       7             : import '../range_picker.dart';
       8             : import '../week_picker.dart';
       9             : 
      10             : // layout defaults
      11             : const Duration _kPageScrollDuration = Duration(milliseconds: 200);
      12             : const double _kDayPickerRowHeight = 42.0;
      13             : const int _kMaxDayPickerRowCount = 6; // A 31 day month that starts on Saturday.
      14             : const double _kMonthPickerPortraitWidth = 330.0;
      15             : const EdgeInsetsGeometry _kContentPadding =
      16             :     EdgeInsets.symmetric(horizontal: 8.0);
      17             : 
      18             : /// Settings for the layout of the [DayPicker], [WeekPicker], [RangePicker]
      19             : /// and [MonthPicker].
      20             : class DatePickerLayoutSettings {
      21             :   /// Duration for scroll to previous or next page.
      22             :   final Duration pagesScrollDuration;
      23             : 
      24             :   /// Determines the scroll physics of a date picker widget.
      25             :   ///
      26             :   /// Can be null. In this case default physics for [ScrollView] will be used.
      27             :   final ScrollPhysics? scrollPhysics;
      28             : 
      29             :   /// Height of the one row in picker including headers.
      30             :   ///
      31             :   /// Default is [_kDayPickerRowHeight].
      32             :   final double dayPickerRowHeight;
      33             : 
      34             :   /// Width of the day based pickers.
      35             :   final double monthPickerPortraitWidth;
      36             : 
      37             :   ///
      38             :   final int maxDayPickerRowCount;
      39             : 
      40             :   /// Padding for the entire picker.
      41             :   final EdgeInsetsGeometry contentPadding;
      42             : 
      43             :   /// If the first dates from the next month should be shown
      44             :   /// to complete last week of the selected month.
      45             :   ///
      46             :   /// false by default.
      47             :   final bool showNextMonthStart;
      48             : 
      49             :   /// If the last dates from the previous month should be shown
      50             :   /// to complete first week of the selected month.
      51             :   ///
      52             :   /// false by default.
      53             :   final bool showPrevMonthEnd;
      54             :     
      55             :   /// Hide Month navigation row
      56             :   /// false by default.
      57             :   final bool hideMonthNavigationRow;
      58             : 
      59             :   /// Grid delegate for the picker according to [dayPickerRowHeight] and
      60             :   /// [maxDayPickerRowCount].
      61           0 :   SliverGridDelegate get dayPickerGridDelegate =>
      62           0 :       _DayPickerGridDelegate(dayPickerRowHeight, maxDayPickerRowCount);
      63             : 
      64             :   /// Maximum height of the day based picker according to [dayPickerRowHeight]
      65             :   /// and [maxDayPickerRowCount].
      66             :   ///
      67             :   /// Two extra rows:
      68             :   /// one for the day-of-week header and one for the month header.
      69           0 :   double get maxDayPickerHeight =>
      70           0 :       dayPickerRowHeight * (maxDayPickerRowCount + 2);
      71             : 
      72             :   /// Creates layout settings for the date picker.
      73             :   ///
      74             :   /// Usually used in [DayPicker], [WeekPicker], [RangePicker]
      75             :   /// and [MonthPicker].
      76          20 :   const DatePickerLayoutSettings({
      77             :     this.pagesScrollDuration = _kPageScrollDuration,
      78             :     this.dayPickerRowHeight = _kDayPickerRowHeight,
      79             :     this.monthPickerPortraitWidth = _kMonthPickerPortraitWidth,
      80             :     this.maxDayPickerRowCount = _kMaxDayPickerRowCount,
      81             :     this.contentPadding = _kContentPadding,
      82             :     this.showNextMonthStart = false,
      83             :     this.showPrevMonthEnd = false,
      84             :     this.hideMonthNavigationRow = false,
      85             :     this.scrollPhysics
      86             :   });
      87             : }
      88             : 
      89             : 
      90             : class _DayPickerGridDelegate extends SliverGridDelegate {
      91             :   final double _dayPickerRowHeight;
      92             :   final int _maxDayPickerRowCount;
      93             : 
      94           0 :   const _DayPickerGridDelegate(
      95             :       this._dayPickerRowHeight, this._maxDayPickerRowCount);
      96             : 
      97           0 :   @override
      98             :   SliverGridLayout getLayout(SliverConstraints constraints) {
      99             :     const int columnCount = DateTime.daysPerWeek;
     100           0 :     final double tileWidth = constraints.crossAxisExtent / columnCount;
     101           0 :     final double tileHeight = math.min(_dayPickerRowHeight,
     102           0 :         constraints.viewportMainAxisExtent / (_maxDayPickerRowCount + 1));
     103           0 :     return SliverGridRegularTileLayout(
     104             :       crossAxisCount: columnCount,
     105             :       mainAxisStride: tileHeight,
     106             :       crossAxisStride: tileWidth,
     107             :       childMainAxisExtent: tileHeight,
     108             :       childCrossAxisExtent: tileWidth,
     109           0 :       reverseCrossAxis: axisDirectionIsReversed(constraints.crossAxisDirection),
     110             :     );
     111             :   }
     112             : 
     113           0 :   @override
     114             :   bool shouldRelayout(SliverGridDelegate oldDelegate) => false;
     115             : }

Generated by: LCOV version 1.15