mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
761 B
32 lines
761 B
// Copyright 2023 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class UiScaler extends StatelessWidget {
|
|
const UiScaler({
|
|
super.key,
|
|
required this.child,
|
|
required this.alignment,
|
|
this.referenceHeight = 1080,
|
|
});
|
|
|
|
final int referenceHeight;
|
|
final Widget child;
|
|
final Alignment alignment;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final screenSize = MediaQuery.of(context).size;
|
|
final double scale = min(screenSize.height / referenceHeight, 1.0);
|
|
return Transform.scale(
|
|
scale: scale,
|
|
alignment: alignment,
|
|
child: child,
|
|
);
|
|
}
|
|
}
|