forked from fossasia/badgemagic-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update the code structure to maintain a aspect ratio of the ba…
…dge.
- Loading branch information
1 parent
af99bed
commit e888ba4
Showing
7 changed files
with
546 additions
and
395 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class BadgeUtils { | ||
MapEntry<double, double> getBadgeOffsetBackground(Size size) { | ||
var paddingPercentage = 5.0; | ||
var offsetHeightBadgeBackground = (paddingPercentage / 100) * size.height; | ||
var offsetWidthBadgeBackground = (paddingPercentage / 100) * size.width; | ||
return MapEntry(offsetHeightBadgeBackground, offsetWidthBadgeBackground); | ||
} | ||
|
||
MapEntry<double, double> getBadgeSize(double offsetHeightBadgeBackground, | ||
double offsetWidthBadgeBackground, Size size) { | ||
var badgeHeight = size.height - (2 * offsetHeightBadgeBackground); | ||
var badgeWidth = size.width - (2 * offsetWidthBadgeBackground); | ||
return MapEntry(badgeHeight, badgeWidth); | ||
} | ||
|
||
MapEntry<double, double> getCellStartCoordinate( | ||
double offsetWidthBadgeBackground, | ||
double offsetHeightBadgeBackground, | ||
double badgeWidth, | ||
double badgeHeight) { | ||
{ | ||
var cellSize = badgeWidth / 44; | ||
|
||
// Calculate offsets to center the cells within the rectangle | ||
double totalCellsWidth = (cellSize * 0.92) * 44; | ||
double totalCellsHeight = cellSize * 11; | ||
|
||
var cellStartX = | ||
offsetWidthBadgeBackground + (badgeWidth - totalCellsWidth) / 2; | ||
var cellStartY = | ||
offsetHeightBadgeBackground + (badgeHeight - totalCellsHeight) / 2; | ||
|
||
return MapEntry(cellStartX, cellStartY); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.