Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Scale the entire UI design proportionally, useful when your UI design is fixed-width.

License

NotificationsYou must be signed in to change notification settings

LastMonopoly/scaled_app

Repository files navigation

Scale the entire UI design proportionally.

Button, image, font, every widget is scaled simultaneously.

Before:

  • 250x250 square is the same size across devices

Screenshots of the same design before scaling

After:

  • 250x250 square is two thirds the screen width across devices

Screenshots of the same design after scaling

  • if we resize the screenshots above to be the same width
  • then everything appears the same size as below

Resized screenshots of the same design after scaling

Live demo

https://lastmonopoly.github.io/flutter_web_app/scaled_app_demo/

Features

Use this package in your Flutter app when:

  • your UI design is fixed-width
  • you want to scale the entire UI, not just part of it

Usage

Firstly, replacerunApp withrunAppScaled

voidmain() {// 1st way to use this packagerunAppScaled(constMyApp(), scaleFactor: (deviceSize) {// screen width used in your UI designconstdouble widthOfDesign=375;return deviceSize.width/ widthOfDesign;  });}

Or, replaceWidgetsFlutterBinding withScaledWidgetsFlutterBinding

voidmain() {// 2nd way to use this package// Scaling will be applied based on [scaleFactor] callback.ScaledWidgetsFlutterBinding.ensureInitialized(    scaleFactor: (deviceSize) {// screen width used in your UI designconstdouble widthOfDesign=375;return deviceSize.width/ widthOfDesign;    },  );runApp(constMyApp());}

Then, useMediaQueryData.scale to scale size, viewInsets, viewPadding, etc.

classPageRouteextendsStatelessWidget {constPageRoute({Key? key}):super(key: key);@overrideWidgetbuild(BuildContext context) {returnMediaQuery(      data:MediaQuery.of(context).scale(),      child:constScaffold(...),    );  }}

Optionally, updateScaledWidgetsFlutterBinding.instance.scaleFactor to enable / disable scaling on demand.

Reference

https://juejin.cn/post/7078816723666731021


[8]ページ先頭

©2009-2025 Movatter.jp