31 lines
1.1 KiB
Dart
31 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'dart:math' as math;
|
|
|
|
extension SizeExtension on BuildContext {
|
|
double get sf {
|
|
final Size size = MediaQuery.of(this).size;
|
|
|
|
// 1. Definimos os valores base do design (geralmente feitos no Figma/Adobe XD)
|
|
const double baseWidth = 375;
|
|
const double baseHeight = 812;
|
|
|
|
// 2. Calculamos o rácio de largura e altura
|
|
double scaleW = size.width / baseWidth;
|
|
double scaleH = size.height / baseHeight;
|
|
|
|
// 3. Usamos a média ou o menor valor para manter a proporção
|
|
// O 'min' evita que o texto estique demasiado se o ecrã for muito alto ou largo
|
|
double scale = math.min(scaleW, scaleH);
|
|
|
|
// 4. Segurança (Clamping): Não deixa as coisas ficarem minúsculas
|
|
// nem exageradamente grandes em tablets.
|
|
return scale.clamp(0.8, 1.4);
|
|
}
|
|
|
|
// Atalhos úteis para facilitar o código
|
|
double get screenWidth => MediaQuery.of(this).size.width;
|
|
double get screenHeight => MediaQuery.of(this).size.height;
|
|
|
|
// Verifica se é Tablet (opcional)
|
|
bool get isTablet => screenWidth > 600;
|
|
} |