-
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.
[adaptive_style] add DeviceSize and mostSimilarTo
- Loading branch information
Francesco Iapicca
committed
Apr 20, 2024
1 parent
8b4dd23
commit a5a48dc
Showing
9 changed files
with
161 additions
and
0 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,29 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
build/ |
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,3 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. |
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 @@ | ||
TODO: Add your license here. |
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,39 @@ | ||
<!-- | ||
This README describes the package. If you publish this package to pub.dev, | ||
this README's contents appear on the landing page for your package. | ||
For information about how to write a good package README, see the guide for | ||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages). | ||
For general information about developing packages, see the Dart guide for | ||
[creating packages](https://dart.dev/guides/libraries/create-library-packages) | ||
and the Flutter guide for | ||
[developing packages and plugins](https://flutter.dev/developing-packages). | ||
--> | ||
|
||
TODO: Put a short description of the package here that helps potential users | ||
know whether this package might be useful for them. | ||
|
||
## Features | ||
|
||
TODO: List what your package can do. Maybe include images, gifs, or videos. | ||
|
||
## Getting started | ||
|
||
TODO: List prerequisites and provide or point to information on how to | ||
start using the package. | ||
|
||
## Usage | ||
|
||
TODO: Include short and useful examples for package users. Add longer examples | ||
to `/example` folder. | ||
|
||
```dart | ||
const like = 'sample'; | ||
``` | ||
|
||
## Additional information | ||
|
||
TODO: Tell users more about the package: where to find more information, how to | ||
contribute to the package, how to file issues, what response they can expect | ||
from the package authors, and more. |
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,4 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
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 @@ | ||
library adaptive_style; |
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,27 @@ | ||
import 'dart:ui'; | ||
|
||
/// a collection of well known screen dimesions | ||
/// as offered by [chrome device toolbar] | ||
enum DeviceSize { | ||
iphoneSE(Size(375, 667)), | ||
iphoneXR(Size(414, 896)), | ||
iphone12PRO(Size(390, 844)), | ||
iphone14PRO(Size(430, 932)), | ||
pixel7(Size(412, 915)), | ||
galaxyS8Plus(Size(360, 740)), | ||
galaxyS20Ultra(Size(412, 915)), | ||
iPadMini(Size(768, 1024)), | ||
iPadAir(Size(820, 1180)), | ||
iPadPro(Size(1024, 1366)), | ||
surfacePro7(Size(912, 1368)), | ||
surfaceDuo(Size(540, 720)), | ||
galaxyFold(Size(280, 653)), | ||
galaxyA51(Size(412, 914)), | ||
galaxyA71(Size(412, 914)), | ||
nestHub(Size(1024, 600)), | ||
nestHubMax(Size(1280, 800)); | ||
|
||
const DeviceSize(this.size); | ||
|
||
final Size size; | ||
} |
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,42 @@ | ||
import 'dart:math' as math show min, sqrt; | ||
import 'dart:ui'; | ||
|
||
import 'device_size.dart'; | ||
|
||
extension DeviceSizeSizesX on List<DeviceSize> { | ||
List<Size> get sizes => [for (final value in this) value.size]; | ||
} | ||
|
||
extension FixedRatioSizeScaleX<T extends Size> on T { | ||
double fixedRatioScale(T size) => math.min( | ||
width / size.width, | ||
height / size.height, | ||
); | ||
} | ||
|
||
extension ReverseScaleX<T extends double> on T { | ||
double get reversedRatio => 1 / this; | ||
} | ||
|
||
extension SizeAreaX<T extends Size> on T { | ||
double get area => width * height; | ||
} | ||
|
||
extension MostSimilarSizeX<T extends Size> on Iterable<T> { | ||
T mostSimilarTo(T size) { | ||
final sizes = [ | ||
for (final element in this) | ||
( | ||
element, | ||
|
||
/// this is arbitrary but seems to work | ||
(size.aspectRatio - element.aspectRatio).abs() * | ||
math.sqrt((size.area - element.area).abs()) | ||
) | ||
]..sort( | ||
(a, b) => a.$2.compareTo(b.$2), | ||
); | ||
|
||
return sizes.first.$1; | ||
} | ||
} |
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,15 @@ | ||
name: adaptive_style | ||
description: Make you Flutter UI both responsive and adaptive | ||
version: 0.0.1 | ||
homepage: https://github.com/yakforward-ou/yak_packages | ||
|
||
environment: | ||
sdk: '>=3.3.3 <4.0.0' | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
dev_dependencies: | ||
flutter_test: | ||
sdk: flutter | ||
flutter_lints: ^3.0.2 |