simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -123,19 +123,14 @@ class PmImageView extends StatelessWidget {
|
||||
|
||||
double? _resolveWidth(String? width, double available) {
|
||||
if (width == null) return null;
|
||||
final match = RegExp(r'^(\d+(?:\.\d+)?)(px|%|em|rem)$').firstMatch(width);
|
||||
if (match == null) return null;
|
||||
final value = double.parse(match.group(1)!);
|
||||
final double resolved;
|
||||
switch (match.group(2)) {
|
||||
case '%':
|
||||
resolved = available * value / 100;
|
||||
case 'em':
|
||||
case 'rem':
|
||||
resolved = value * 16;
|
||||
default:
|
||||
resolved = value;
|
||||
}
|
||||
final length = parsePmCssLength(width);
|
||||
if (length == null) return null;
|
||||
final value = length.value;
|
||||
final resolved = switch (length.unit) {
|
||||
'%' => available * value / 100,
|
||||
'em' || 'rem' => value * 16,
|
||||
_ => value,
|
||||
};
|
||||
return resolved.clamp(1, available);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user