[Flutter] MediaQuery

2020. 12. 26. 16:26Flutter Mobile App/Flutter 기초

반응형

MediaQuery : 화면의 크기 확인, 패딩값, 텍스트 사이즈 등의 여러가지 시스템정보를 담고있음.


MediaQuery


main.dart

 

더보기
import 'package:flutter/material.dart';       
        
void main() {       
  runApp(MyApp());        
}       
        
class MyApp extends StatelessWidget {       
  // This widget is the root of your application.       
  @override       
  Widget build(BuildContext context) {        
    return MaterialApp(       
      title: 'Flutter Demo',        
      theme: ThemeData(       
        primarySwatch: Colors.blue,       
        visualDensity: VisualDensity.adaptivePlatformDensity,       
      ),        
      home: MyHomePage(),       
    );        
  }       
}       
        
class MyHomePage extends StatefulWidget {       
  @override       
  _MyHomePageState createState() => _MyHomePageState();       
}       
        
class _MyHomePageState extends State<MyHomePage> {        

  @override       
  Widget build(BuildContext context) {        
    return MaterialApp(
     title: 'Flutter Demo',
     theme: ThemeData(
       primarySwatch: Colors.blue,
       visualDensity: VisualDensity.adaptivePlatformDensity
     ),
     home: HomePage(),
    );        
  }       
}       

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('MINOKUMA - FLUTTER'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('디스플레이 사이즈 : ${MediaQuery.of(context).size}'),
            Text('디스플레이 높이 : ${MediaQuery.of(context).size.height}'),
            Text('디스플레이 너비 : ${MediaQuery.of(context).size.width}'),
            Text('디스플레이 패딩 : ${MediaQuery.of(context).padding}'),
            Text('상태 바 높이 : ${MediaQuery.of(context).padding.top}'),
          ],
        ),
      ),
    );
  }
}

 

반복할 때마다 Divider 위젯을 추가로 삽입

반응형

'Flutter Mobile App > Flutter 기초' 카테고리의 다른 글

[Flutter] Layout  (0) 2020.12.26
[Flutter] Stack  (0) 2020.12.26
[Flutter] ScrollBar  (0) 2020.12.26
[Flutter] ListTile  (0) 2020.12.26
[Flutter] Card + ListTile  (0) 2020.12.26