[Flutter] flutter_screenutil 패키지 알아보기

2023. 6. 20. 11:12·🐦 플러터

flutter_screenutil

screenutil은 화면 및 글꼴 크기를 조정하기 위한 플러터 플러그인입니다.
표준 화면의 크기를 설정하고 UI를 구성하는 값을 표시하면 다른 크기의 화면에 자동으로 적절한 레이아웃이 됩니다.

이 라이브러리는 앱을 다양한 크기의 기기에 쉽게 적용할 수 있도록 만들었습니다. 

또한, 이 라이브러리는 앱 디자인 번호를 쉽게 신청할 수 있게 해줍니다. -> 디자이너와의 그만 싸우세요.

 

Principle of screenutil

이 function으로 표준 화면 크기와 위젯 크기를 설정하면 앱이 실행되는 단말기 화면 크기 비율에 따라 비율을 계산하고 위젯 크기를 제공합니다. 이것은 MediaQuery와 동일한 빙식입니다. 
또한 main function은 모바일 OS에서 제공하는 글꼴 크기 변경 기능을 무시하고 글꼴 크기를 설정합니다.

 

아래는 flutter_screenutil 패키지를 사용한 예시 코드입니다.

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


void main() {
  runApp(MyApp());
}


class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter_ScreenUtil',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: PracticeScreenUtil(),
    );
  }
}

class PracticeScreenUtil extends StatefulWidget {


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

class _HomePageState extends State<PracticeScreenUtil> {
  @override
  Widget build(BuildContext context) {

	// Set the fit size based on the size of the 360*690(dp)
    ScreenUtil.init(context, designSize: const Size(360, 690));

    return Scaffold(
      appBar: AppBar(
        title:Text('Screen Util')
      ),
        body:Center(
            child:Column(
              children: [
                Container(
                  width: 100,
                  height:100,
                  color: Colors.blue,
                  child:Text(
                      'hello',
                      style:TextStyle(
                          color: Colors.black,
                          fontSize: 15
                      )

                  ),
                ),
                Container(

				// Set width based on width of fit screen size 
                  width: ScreenUtil().setWidth(100),

				// Set height based on height of fit screen size 
                  height:ScreenUtil().setHeight(100),
                  color: Colors.red,
                  child:Text(
                      'hello',
                      style:TextStyle(
                          color: Colors.black,
                          fontSize: 15.sp
                      )

                  ),
                ),
                Container(

				// Set width based on width of fit screen size
                  width: 100.w,

				// Set height based on height of fit screen size
                  height:100.h,
                  color: Colors.yellow,
                  child:Text(
                      'hello',
                      style:TextStyle(
                          color: Colors.black,

						// Set a fontsize based on screen size. 
                          fontSize: ScreenUtil().setSp(15)
                      )

                  ),
                ),

              ],
            )
        ),

    );
  }
}

Code Result

https://pub.dev/packages/flutter_screenutil

 

flutter_screenutil | Flutter Package

A flutter plugin for adapting screen and font size.Guaranteed to look good on different models

pub.dev

 

저작자표시 비영리 동일조건 (새창열림)

'🐦 플러터' 카테고리의 다른 글

[Flutter] Button Style 지정하기  (0) 2023.06.21
[Flutter] Responsive User Interface를 구현해보자  (0) 2023.06.21
[Flutter] LayoutBuilder 위젯 알아보기  (0) 2023.06.20
[Xcode] Target debug_os_bundle_flutter_assets failed: ShaderCompilerException  (0) 2023.04.01
[Xcode] note: Building targets in dependency order  (0) 2023.04.01
'🐦 플러터' 카테고리의 다른 글
  • [Flutter] Button Style 지정하기
  • [Flutter] Responsive User Interface를 구현해보자
  • [Flutter] LayoutBuilder 위젯 알아보기
  • [Xcode] Target debug_os_bundle_flutter_assets failed: ShaderCompilerException
기멘기
기멘기
Handong Global University | Apple Developer Academy @ POSTECH
  • 기멘기
    현기의 비공식문서 🍎
    기멘기
  • 전체
    오늘
    어제

  • 링크

    • Github
    • Instagram

    • 전체 글 (79) N
      • 🍎 iOS (6)
        • 애플 디벨로퍼 아카데미 (6)
      • 🐦 플러터 (32)
      • 🤔 컴공 지식 (10)
        • 알고리즘 (3)
        • 네트워크 (7)
      • 🔥 문해력 상승 (8)
        • 백 준 (8)
        • 프로 그래머 스 (0)
      • 💬 이모저모 (12)
        • CRA 방학 프로젝트 (4)
        • 캡스톤 산학 프로젝트 (5)
        • PARD IT 협업 동아리 (2)
      • 💡 인사이트 (0)
        • 전공 관련 (0)
        • 기타 (0)
      • ✏️ 하루 회고 (TIL) (4) N
      • 🔍 ETC (7)
        • HTML-CSS-JS (4)

  • 인기 글


  • 최근 댓글


  • 최근 글


  • 블로그 메뉴

    • 티스토리 홈
    • 블로그 관리
    • 글 작성하기

  • hELLO· Designed By정상우.v4.10.3
기멘기
[Flutter] flutter_screenutil 패키지 알아보기
상단으로

티스토리툴바