• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icapps / flutter-custom-image-crop / 6545506866

17 Oct 2023 09:53AM UTC coverage: 0.0%. Remained the same
6545506866

Pull #45

github

web-flow
Merge bff8ba3a1 into 75def6bbd
Pull Request #45: optimize fillcropscpace imagefit

130 of 130 new or added lines in 3 files covered. (100.0%)

0 of 485 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/src/calculators/calculate_crop_fit_params.dart
1
import 'dart:math';
2

3
import 'package:custom_image_crop/src/models/params_model.dart';
4
import 'package:custom_image_crop/src/widgets/custom_image_crop_widget.dart';
5

6
/// Returns params to use for displaying crop screen.
7
CropFitParams calculateCropFitParams({
×
8
  required double screenWidth,
9
  required double screenHeight,
10
  required double cropPercentage,
11
  required int imageWidth,
12
  required int imageHeight,
13
  required CustomImageFit imageFit,
14
  required double aspectRatio,
15
}) {
16
  /// the width of the area to crop
17
  final double cropSizeWidth;
18

19
  /// the height of the area to crop
20
  final double cropSizeHeight;
21

22
  /// used to adjust image scale
23
  final double defaultScale;
24

25
  switch (imageFit) {
26
    case CustomImageFit.fillCropSpace:
×
27
      if (screenWidth <= screenHeight * aspectRatio) {
×
28
        cropSizeWidth = screenWidth * cropPercentage;
×
29
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
30
        defaultScale =
31
            cropSizeWidth * max(imageWidth / imageHeight, 1.0) / imageWidth;
×
32
      } else {
33
        cropSizeHeight = screenHeight * cropPercentage;
×
34
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
35
        defaultScale =
36
            cropSizeHeight * max(imageHeight / imageWidth, 1.0) / imageHeight;
×
37
      }
38
      break;
39

40
    case CustomImageFit.fitCropSpace:
×
41
      if (screenWidth <= screenHeight * aspectRatio) {
×
42
        cropSizeWidth = screenWidth * cropPercentage;
×
43
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
44
        defaultScale = cropSizeHeight / imageHeight;
×
45
      } else {
46
        cropSizeHeight = screenHeight * cropPercentage;
×
47
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
48
        defaultScale = cropSizeWidth / imageWidth;
×
49
      }
50
      break;
51

52
    case CustomImageFit.fillCropWidth:
×
53
      if (screenWidth <= screenHeight * aspectRatio) {
×
54
        cropSizeWidth = screenWidth * cropPercentage;
×
55
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
56
      } else {
57
        cropSizeHeight = screenHeight * cropPercentage;
×
58
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
59
      }
60
      defaultScale = cropSizeWidth / imageWidth;
×
61
      break;
62

63
    case CustomImageFit.fillCropHeight:
×
64
      if (screenWidth <= screenHeight * aspectRatio) {
×
65
        cropSizeWidth = screenWidth * cropPercentage;
×
66
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
67
      } else {
68
        cropSizeHeight = screenHeight * cropPercentage;
×
69
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
70
      }
71
      defaultScale = cropSizeHeight / imageHeight;
×
72
      break;
73

74
    case CustomImageFit.fitVisibleSpace:
×
75
      if (screenWidth <= screenHeight * aspectRatio) {
×
76
        cropSizeWidth = screenWidth * cropPercentage;
×
77
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
78
        defaultScale = screenWidth / imageWidth;
×
79
      } else {
80
        cropSizeHeight = screenHeight * cropPercentage;
×
81
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
82
        defaultScale = screenHeight / imageHeight;
×
83
      }
84
      break;
85

86
    case CustomImageFit.fillVisibleSpace:
×
87
      if (screenWidth <= screenHeight * aspectRatio) {
×
88
        cropSizeWidth = screenWidth * cropPercentage;
×
89
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
90
        defaultScale = screenHeight / imageHeight;
×
91
      } else {
92
        cropSizeHeight = screenHeight * cropPercentage;
×
93
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
94
        defaultScale = screenWidth / imageWidth;
×
95
      }
96
      break;
97

98
    case CustomImageFit.fillVisibleHeight:
×
99
      if (screenWidth <= screenHeight * aspectRatio) {
×
100
        cropSizeWidth = screenWidth * cropPercentage;
×
101
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
102
      } else {
103
        cropSizeHeight = screenHeight * cropPercentage;
×
104
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
105
      }
106
      defaultScale = screenHeight / imageHeight;
×
107
      break;
108

109
    case CustomImageFit.fillVisibleWidth:
×
110
      if (screenWidth <= screenHeight * aspectRatio) {
×
111
        cropSizeWidth = screenWidth * cropPercentage;
×
112
        cropSizeHeight = cropSizeWidth / aspectRatio;
×
113
      } else {
114
        cropSizeHeight = screenHeight * cropPercentage;
×
115
        cropSizeWidth = cropSizeHeight * aspectRatio;
×
116
      }
117
      defaultScale = screenWidth / imageWidth;
×
118
      break;
119
  }
120

121
  return CropFitParams(
×
122
    cropSizeWidth: cropSizeWidth,
123
    cropSizeHeight: cropSizeHeight,
124
    additionalScale: defaultScale,
125
  );
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc