Update app scale implementation
This commit is contained in:
parent
f74dc5bd68
commit
1e1cac7c54
@ -6,24 +6,28 @@ import 'package:wonders/common_libs.dart';
|
||||
|
||||
export 'colors.dart';
|
||||
|
||||
AppStyle $styles = AppStyle();
|
||||
|
||||
@immutable
|
||||
class AppStyle {
|
||||
AppStyle({Size? appSize}) {
|
||||
/// Measure the diagonal size of the app window, and slightly adjust the scale value which is
|
||||
/// applied to paddings and font-sizes across the app.
|
||||
if (appSize == null) {
|
||||
AppStyle({Size? screenSize}) {
|
||||
if (screenSize == null) {
|
||||
scale = 1;
|
||||
return;
|
||||
}
|
||||
final screenSize = (appSize.width + appSize.height) / 2;
|
||||
if (screenSize > 1000) {
|
||||
scale = 1.25; // large tablets
|
||||
} else if (screenSize > 800) {
|
||||
scale = 1; // small tablets
|
||||
final shortestSide = screenSize.shortestSide;
|
||||
const tabletXl = 1000;
|
||||
const tabletLg = 800;
|
||||
const tabletSm = 600;
|
||||
const phoneLg = 400;
|
||||
if (shortestSide > tabletXl) {
|
||||
scale = 1.25;
|
||||
} else if (shortestSide > tabletLg) {
|
||||
scale = 1.15;
|
||||
} else if (shortestSide > tabletSm) {
|
||||
scale = 1;
|
||||
} else if (shortestSide > phoneLg) {
|
||||
scale = .9; // phone
|
||||
} else {
|
||||
scale = .9; // phones
|
||||
scale = .85; // small phone
|
||||
}
|
||||
debugPrint('screenSize=$screenSize, scale=$scale');
|
||||
}
|
||||
|
@ -4,13 +4,14 @@ import 'package:wonders/ui/common/app_scroll_behavior.dart';
|
||||
class WondersAppScaffold extends StatelessWidget with GetItMixin {
|
||||
WondersAppScaffold({Key? key, required this.child}) : super(key: key);
|
||||
final Widget child;
|
||||
static AppStyle get style => _style;
|
||||
static AppStyle _style = AppStyle();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Animate.defaultDuration = $styles.times.fast;
|
||||
// Listen to the device size, and update AppStyle when it changes
|
||||
$styles = AppStyle(appSize: Size(context.widthPx, context.heightPx));
|
||||
//$styles = AppStyle(appSize: null); //Size(context.widthPx, context.heightPx));
|
||||
_style = AppStyle(screenSize: context.sizePx);
|
||||
Animate.defaultDuration = $styles.times.fast;
|
||||
return Stack(
|
||||
key: ValueKey($styles.scale),
|
||||
children: [
|
||||
|
Loading…
x
Reference in New Issue
Block a user