A low-cost Flutter screen adaptation solution(一个极低成本的 Flutter 屏幕适配方案)

Overview

A low-cost Flutter screen adaptation solution(一个极低成本的 Flutter 屏幕适配方案)

100% 还原 UI,只需要按照设计图写的宽高写即可

先看图片,设置的标准宽度是 360

iPhone 8 ------------------------------- iPhone 11 :

iPhone 12 pro max --------------------- ipad air :

android 图

768x1280-320dpi----------10801920-420dpi----------1440x2560-560dpi

web 图

随着拉长屏幕 ,慢慢的 宽度会大于高度,当大于的时候 ,会以 高度 为 基准。

使用

引用

flutter_autosize_screen: ^{LAST_VERSION}

初始化

  1. 在main方法的第一行就初始化,下面的基准一般以宽度为基准,直接写Ui设计图的宽度尺寸,如果是横屏的状态的 下面的 360 就是以高度为基准
void main() {
  // 设置基准 或者以苹果6,375 为标准, isAutoTextSize 表示文字是否随着系统的字体大小更改而更改,默认是 true
  AutoSizeUtil.setStandard(360,isAutoTextSize: true);

  // 使用 runAutoApp 来代替 runApp
  // import 'package:flutter_autosize_screen/binding.dart';
  runAutoApp(const MyApp());

}
  1. 替换根 MaterialApp 的 MediaQuery
MaterialApp(
      title: 'Autosize Demo',
      /// 替换,这样可以在以后 使用 MediaQuery.of(context) 得到 正确的Size
      builder: AutoSizeUtil.appBuilder,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: HomePage(),
      ),
    )
  1. 获取Size
AutoSizeUtil.getScreenSize()
//或者
MediaQuery.of(context).size
  1. 直接按照设计图的尺寸写即可
Container(
    alignment: Alignment.center,
    height: 60,
    width :60,
    color: Colors.redAccent,
    child: Text(
      "直接按照设计图写尺寸",
    ),
  )
  1. 获取真正的大小,比如 kToolbarHeight 是 56
// 一下方法获取到真正的大小,然后设置到 toolbar上
AutoSizeUtil.getRealSize(kToolbarHeight)
  1. 切记 不能使用 window 获取 size 或者是 获取 MediaQuery
    window.physicalSize
    MediaQueryData.fromWindow(window)

下一个目标

因为从根修改了屏幕宽高, 会引起一些系统Widget,有可能比正常的大或者小,比如toorbar的高度默认是 kToolbarHeight = 56.0,这样如果把宽度标准设置成112的话,那这kToolbarHeight就会显得很高, 还有 Text (bodyText2) 默认的是 14,也会非常大,所以 下一个计划是 还原一下默认的系统 widget。大家有好的建议 也可以提给我

原理

掘进

Thank

FlutterTest

You might also like...

Apartment4a - An app which will be a one stop solution to all the problems Students are facing these days

Apartment4a - An app which will be a one stop solution to all the problems Students are facing these days

APARTMENT 4A An app which will be a one stop solution to all the problems Studen

Nov 15, 2022

Meme Network is the creative powerhouse that supercharges your Meme projects with the World's First Layer 1 solution in the Cosmos Ecosystem.

Meme Network is the creative powerhouse that supercharges your Meme projects with the World's First Layer 1 solution in the Cosmos Ecosystem.

MEME Chain How to Join MEME Mainnet Recommended system setup 4 core CPU Memory: 4GB Disk: 100GB Ubuntu 20.04 Meme Validator Node Snapshot & State-Sync

Oct 26, 2022

Immich - High performance self-hosted photo and video backup solution

Immich - High performance self-hosted photo and video backup solution

Self-hosted photo and video backup solution directly from your mobile phone.

Jan 8, 2023

A flutter app face detection and emotion, can detect if you're smiling, big smiley, sad or if there is not face on the screen.

My Emotion A flutter app face detection and emotion, can detect if you're smiling, big smiley, sad or if there is not face on the screen. News feactur

Dec 31, 2022

This Flutter project recreates an electronics store home screen mockup.

This Flutter project recreates an electronics store home screen mockup.

E-Store Mobile App Home Screen This Flutter project recreates an electronics store home screen mockup. The mockup was created by @nasyiya.design on in

Jul 2, 2022

Flutter Web application having splash screen and providing Web view Using web view packege.

Flutter Web application having splash screen and providing Web view Using web view packege.

Webview with Splash Screen in Flutter Flutter Web View With Splash Screen. Subscribe Our YouTube Channel. Visit Website Demo OutPut 🔗 Links Getting S

Dec 7, 2021

Flutter Package for Easier Creation of Home Screen Widgets

Flutter Package for Easier Creation of Home Screen Widgets

Home Widget HomeWidget is a Plugin to make it easier to create HomeScreen Widgets on Android and iOS. HomeWidget does not allow writing Widgets with F

Dec 31, 2022

A Beautiful Onboarding UI Screen For Flutter

onboarding_ui Untitled.design.mp4

Apr 7, 2022

A flutter package which contains a collection of Splash Screen example for your app to display logo and different text style.

A flutter package which contains a collection of Splash Screen example for your app to display logo and different text style.

splash_screen_view They say, first impression is the last! Yep, truly for any amazingly crafted application, it's easier to start impressing your audi

Nov 25, 2022
Comments
Owner
聂志洋
Read The Fucking Source Code
聂志洋
WeCare is a logistics management platform that can manage everything like delivering goods in time and in a preferable cost.

wecare_logistics A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

Shaurya kajiwala 5 Nov 10, 2022
P2P payment solution using Stream's Flutter SDK and Rapyd's Wallet API

Peer-to-peer payment integration to a messaging app using Flutter ?? This project shows how to integrate a peer-to-peer payment solution to your Strea

Souvik Biswas 15 Dec 8, 2022
An Advanced Logging Framework develop in flutter that provides quick & simple logging solution.

FLogs Advance Logging Framework FLog is an Advanced Logging Framework develop in flutter that provides quick & simple logging solution. All logs are s

Zubair Rehman 170 Dec 30, 2022
A super-fast and efficient state management solution for Flutter...

turbo A super-fast, efficient state management solution for Flutter. Turbo does not use streams, which are extremely inefficient, or use complex abstr

Aldrin's Art Factory 4 Oct 16, 2022
Plaso Connect is an application which acts as a one-stop solution where the people requiring blood plasma/oxygen can directly find and contact the donors and healthcare units as per their requirements

PLASO CONNECT - The Lifeline A one-stop platform for COVID relief resources -- Connecting patients with Plasma donors and oxygen suppliers. Built for

Niloy Sikdar 11 Oct 28, 2022
Sharik is an open-source, cross-platform solution for sharing files via Wi-Fi or Mobile Hotspot

Share files across devices with Sharik! It works with Wi-Fi connection or Tethering (Wi-Fi Hotspot). No internet connection needed. Contributing Feel

Mark Motliuk 844 Jan 1, 2023
a software to connect you and your friends and others, are you guys also just tensed over the overuse of social media so we have a solution, appx (name not decided yet)

appx a software to connect you and your friends and others, are you guys also just tensed over the overuse of social media so we have a solution, appx

null 8 Jun 9, 2022
a software to connect you and your friends and others, are you guys also just tensed over the overuse of social media so we have a solution, sociio

APPX A software that will allow you to connect with your friends and family ! Are you guys also tensed over the over-use of social media ?? We have a

null 8 Jun 9, 2022
Bayer App : Solution Of multipurpose needs

Bayer App : Solution Of multipurpose needs APK FILE: https://drive.google.com/file/d/1u-2NABekwEIk3Q0sYBgrHWPUCLlXEkOp/view?usp=sharing #DATASET LINK

DEVA VENKATA SAI RITHISH PUNNA 1 Jan 20, 2022
A Dart library with a solution to use smart enums

Smart Enums Author: Jop Middelkamp A package that can help you create 'smarter' enums that could be extended with some domain logic. Usage final bestF

Jop Middelkamp 2 Oct 1, 2022