All Projects → OpenFlutter → Flutter_screenutil

OpenFlutter / Flutter_screenutil

Licence: apache-2.0
Flutter screen adaptation, font adaptation, get screen information

Programming Languages

dart
5743 projects
C++
36643 projects - #6 most used programming language
CMake
9771 projects
HTML
75241 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to Flutter screenutil

flutter scale aware
🎗 Scale-based layouts with a bit more ease, powered by extensions.
Stars: ✭ 26 (-99.09%)
Mutual labels:  scale, screen
BetterDummy
Unlock your displays on your Mac! Smooth scaling, HiDPI unlock, XDR/HDR extra brightness upscale, DDC, brightness and dimming, dummy displays, PIP and lots more!
Stars: ✭ 9,601 (+237.71%)
Mutual labels:  scale, screen
Gimage
A PHP library for easy image handling. 🖼
Stars: ✭ 148 (-94.79%)
Mutual labels:  scale
Nocturnal
A Dimness and Night Shift menu bar app for macOS 🌙
Stars: ✭ 199 (-93%)
Mutual labels:  screen
Docker Compose Demo
A short demo on how to use Docker Compose to create a Web Service connected to a load balancer and a Redis Database.
Stars: ✭ 168 (-94.09%)
Mutual labels:  scale
Tidyheatmap
Draw heatmap simply using a tidy data frame
Stars: ✭ 151 (-94.69%)
Mutual labels:  scale
Springy facebook rebound
Springy makes Android Property animation easy to use.
Stars: ✭ 176 (-93.81%)
Mutual labels:  scale
Middleware
TrueNAS CORE/Enterprise/SCALE Middleware Git Repository
Stars: ✭ 1,851 (-34.89%)
Mutual labels:  scale
.tmux
🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
Stars: ✭ 15,594 (+448.51%)
Mutual labels:  screen
Kes
KES is a simple, stateless and distributed key-management system
Stars: ✭ 168 (-94.09%)
Mutual labels:  scale
Androidresizer
Java Desktop app to resize XXXHDPI (or lower) images and sort them into folders automatically.
Stars: ✭ 194 (-93.18%)
Mutual labels:  scale
Tonal
A functional music theory library for Javascript
Stars: ✭ 2,156 (-24.16%)
Mutual labels:  scale
React Native Easy Gestures
React Native Gestures. Support: Drag, Scale and Rotate a Component.
Stars: ✭ 153 (-94.62%)
Mutual labels:  scale
Swiftyfitsize
📱 Swifty screen adaptation solution (Support Objective-C and Swift)
Stars: ✭ 184 (-93.53%)
Mutual labels:  screen
Neural Tools
Tools made for usage alongside artistic style transfer projects
Stars: ✭ 150 (-94.72%)
Mutual labels:  scale
H5editor
仿易企秀类h5页面编辑工具(不再维护)
Stars: ✭ 200 (-92.97%)
Mutual labels:  screen
Heimdall
An enhanced HTTP client for Go
Stars: ✭ 2,132 (-25.01%)
Mutual labels:  scale
Undermoon
Mordern Redis Cluster solution for easy operation.
Stars: ✭ 166 (-94.16%)
Mutual labels:  scale
Teascreenpopupwindow
多类型筛选弹框、多数据筛选、多样化diy、单选or多选、必藏 (Multiple Type Screening Boxes, Multiple Data Screening, Diversified Diy, Single or Multiple Selection, Must Star)
Stars: ✭ 170 (-94.02%)
Mutual labels:  screen
Igrphototweaks
Drag, Rotate, Scale and Crop
Stars: ✭ 212 (-92.54%)
Mutual labels:  scale

flutter_screenutil

pub package pub points popularity

A flutter plugin for adapting screen and font size.Let your UI display a reasonable layout on different screen sizes!

Note: This plugin is still under development, and some APIs might not be available yet.

中文文档

README em Português

github

Update log

Usage:

Add dependency:

Please check the latest version before installation. If there is any problem with the new version, please use the previous version

dependencies:
  flutter:
    sdk: flutter
  # add flutter_screenutil
  flutter_screenutil: ^{latest version}

Add the following imports to your Dart code:

import 'package:flutter_screenutil/flutter_screenutil.dart';

Property

Property Type Default Value Description
designSize Size Size(360, 690) The size of the device screen in the design draft, in dp
builder Widget Function() Container() Generally returning a Function of MaterialApp type
orientation Orientation portrait screen orientation
splitScreenMode bool true support for split screen

Initialize and set the fit size and font size to scale according to the system's "font size" accessibility option

Please set the size of the design draft before use, the width and height of the design draft.

The first way:

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //Set the fit size (Find your UI design, look at the dimensions of the device screen and fill it in,unit in dp)
    return ScreenUtilInit(
      designSize: Size(360, 690),
      builder: () => MaterialApp(
        ...
        theme: ThemeData(
                          primarySwatch: Colors.blue,
                          textTheme: TextTheme(
                          //To support the following, you need to use the first initialization method
                            button: TextStyle(fontSize: 45.sp)
                          ),
                        ),
      ),
    );
  }
}

The second way:Does not support font adaptation in the textTheme of MaterialApp's theme.

(If it is not necessary, it is recommended to use the second)

not support this:

MaterialApp(
  ...
  theme: ThemeData(
           textTheme: TextTheme(
             //To support the following, you need to use the first initialization method
             button: TextStyle(fontSize: 45.sp)
             ),
           ),
)
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter_ScreenUtil',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(title: 'FlutterScreenUtil Demo'),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    //Set the fit size (fill in the screen size of the device in the design) If the design is based on the size of the 360*690(dp)
    ScreenUtil.init(
        BoxConstraints(
            maxWidth: MediaQuery.of(context).size.width,
            maxHeight: MediaQuery.of(context).size.height),
        designSize: Size(360, 690),
        orientation: Orientation.portrait);
    return Scaffold();
  }
}

Use:

API

Pass the dp size of the design draft

    ScreenUtil().setWidth(540)  (dart sdk>=2.6 : 540.w) //Adapted to screen width
    ScreenUtil().setHeight(200) (dart sdk>=2.6 : 200.h) //Adapted to screen height , under normal circumstances, the height still uses x.w
    ScreenUtil().radius(200)    (dart sdk>=2.6 : 200.r)    //Adapt according to the smaller of width or height
    ScreenUtil().setSp(24)      (dart sdk>=2.6 : 24.sp) //Adapter font
    12.sm   //return min(12,12.sp)

    ScreenUtil().pixelRatio       //Device pixel density
    ScreenUtil().screenWidth   (dart sdk>=2.6 : 1.sw)    //Device width
    ScreenUtil().screenHeight  (dart sdk>=2.6 : 1.sh)    //Device height
    ScreenUtil().bottomBarHeight  //Bottom safe zone distance, suitable for buttons with full screen
    ScreenUtil().statusBarHeight  //Status bar height , Notch will be higher
    ScreenUtil().textScaleFactor  //System font scaling factor

    ScreenUtil().scaleWidth //The ratio of actual width to UI design
    ScreenUtil().scaleHeight //The ratio of actual height to UI design

    ScreenUtil().orientation  //Screen orientation
    0.2.sw  //0.2 times the screen width
    0.5.sh  //50% of screen height

Adapt screen size:

Pass the dp size of the design draft((The unit is the same as the unit at initialization)):

Adapted to screen width: ScreenUtil().setWidth(540),

Adapted to screen height: ScreenUtil().setHeight(200), In general, the height is best to adapt to the width

If your dart sdk>=2.6, you can use extension functions:

example:

instead of :

Container(
width: ScreenUtil().setWidth(50),
height:ScreenUtil().setHeight(200),
)

you can use it like this:

Container(
width: 50.w,
height:200.h
)

Note

The height can also use setWidth to ensure that it is not deformed(when you want a square)

The setHeight method is mainly to adapt to the height, which is used when you want to control the height of a screen on the UI to be the same as the actual display.

Generally speaking, 50.w!=50.h.

//for example:

///If you want to display a square:
///The UI may show a rectangle:
Container(
           width: 375.w,
           height: 375.h,
            ),
            
////If you want to display a square:
Container(
           width: 300.w,
           height: 300.w,
            ),

or

Container(
           width: 300.r,
           height: 300.r,
            ),

Adapter font:

//Incoming font size(The unit is the same as the unit at initialization)
ScreenUtil().setSp(28) 
28.sp

//for example:
Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  '16sp, will not change with the system.',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 16.sp,
                  ),
                  textScaleFactor: 1.0,
                ),
                Text(
                  '16sp,if data is not set in MediaQuery,my font size will change with the system.',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 16.sp,
                  ),
                ),
              ],
            )

Setting font does not change with system font size

APP global:

 MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter_ScreenUtil',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        builder: (context, widget) {
          return MediaQuery(
            ///Setting font does not change with system font size
            data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
            child: widget,
          );
        },
        home: HomePage(title: 'FlutterScreenUtil Demo'),
      ),

Separate Text:

Text("text", textScaleFactor: 1.0)

widget test

Example:

example demo

Effect:

effect tablet effect

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].