• [flutter] flutter ์˜ˆ์ œ ์ฝ”๋“œ ๋ถ„์„ - 1

    2021. 2. 6.

    by. ํ•ด๋Š”์„ 

    android studio์—์„œ flutter project๋ฅผ ์ฒ˜์Œ ๋งŒ๋“ค์—ˆ์„ ๋•Œ ๋ณด์ด๋Š” ๊ธฐ๋ณธ ์•ฑ์˜ ์ฝ”๋“œ ๋ถ„์„.

     

    ์ „์ฒด ์ฝ”๋“œ

    //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(
            // This is the theme of your application.
            //
            // Try running your application with "flutter run". You'll see the
            // application has a blue toolbar. Then, without quitting the app, try
            // changing the primarySwatch below to Colors.green and then invoke
            // "hot reload" (press "r" in the console where you ran "flutter run",
            // or simply save your changes to "hot reload" in a Flutter IDE).
            // Notice that the counter didn't reset back to zero; the application
            // is not restarted.
            primarySwatch: Colors.blue,
            // This makes the visual density adapt to the platform that you run
            // the app on. For desktop platforms, the controls will be smaller and
            // closer together (more dense) than on mobile platforms.
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'), //ํ‘œ์‹œํ•  ํ™”๋ฉด์˜ ์ธ์Šคํ„ด์Šค
        );
      }
    }
    
    //์‹œ์ž‘ ํด๋ž˜์Šค๊ฐ€ ์‹ค์ œ๋กœ ํ‘œ์‹œํ•˜๋Š” ํด๋ž˜์Šค. ์นด์šดํ„ฐ ์•ฑ ํ™”๋ฉด
    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      // This widget is the home page of your application. It is stateful, meaning
      // that it has a State object (defined below) that contains fields that affect
      // how it looks.
    
      // This class is the configuration for the state. It holds the values (in this
      // case the title) provided by the parent (in this case the App widget) and
      // used by the build method of the State. Fields in a Widget subclass are
      // always marked "final".
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    
    //์œ„ ํด๋ž˜์Šค์˜ ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” state ํด๋ž˜์Šค
    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0; //ํ™”๋ฉด์— ํ‘œ์‹œํ•  ์ƒํƒœ๊ฐ’. ์นด์šดํ„ฐ ์ˆซ์ž
    
      //์นด์šดํ„ฐ ๋ณ€์ˆ˜๋ฅผ 1 ์ฆ๊ฐ€์‹œํ‚ค๊ณ  ํ™”๋ฉด์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ๋ฉ”์„œ๋“œ
      void _incrementCounter() {
        setState(() { //ํ™”๋ฉด์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๋„๋ก ํ•˜๋Š” ํ•จ์ˆ˜. statefulWidget๋งŒ ๊ฐ€๋Šฅ?
          // This call to setState tells the Flutter framework that something has
          // changed in this State, which causes it to rerun the build method below
          // so that the display can reflect the updated values. If we changed
          // _counter without calling setState(), then the build method would not be
          // called again, and so nothing would appear to happen.
          _counter++;
        });
      }
    
      //ํ™”๋ฉด์— UI๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฉ”์„œ๋“œ. ๊ทธ๋ ค์งˆ ์œ„์ ฏ์„ ๋ฐ˜ํ™˜
      @override
      Widget build(BuildContext context) {
        // This method is rerun every time setState is called, for instance as done
        // by the _incrementCounter method above.
        //
        // The Flutter framework has been optimized to make rerunning build methods
        // fast, so that you can just rebuild anything that needs updating rather
        // than having to individually change instances of widgets.
        return Scaffold( //๋จธํ‹ฐ๋ฆฌ์–ผ ๋””์ž์ธ ๊ธฐ๋ณธ ๋ผˆ๋Œ€ ์œ„์ ฏ
          appBar: AppBar( //์ƒ๋‹จ ์•ฑ๋ฐ”
            // Here we take the value from the MyHomePage object that was created by
            // the App.build method, and use it to set our appbar title.
            title: Text(widget.title),
          ),
          body: Center( //ํ‘œ์‹œํ•  ๋‚ด์šฉ
            // Center is a layout widget. It takes a single child and positions it
            // in the middle of the parent.
            child: Column(
              // Column is also a layout widget. It takes a list of children and
              // arranges them vertically. By default, it sizes itself to fit its
              // children horizontally, and tries to be as tall as its parent.
              //
              // Invoke "debug painting" (press "p" in the console, choose the
              // "Toggle Debug Paint" action from the Flutter Inspector in Android
              // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
              // to see the wireframe for each widget.
              //
              // Column has various properties to control how it sizes itself and
              // how it positions its children. Here we use mainAxisAlignment to
              // center the children vertically; the main axis here is the vertical
              // axis because Columns are vertical (the cross axis would be
              // horizontal).
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'You have pushed the button this many times:',
                ),
                Text(
                  '$_counter', //๋ณ€์ˆ˜๋ฅผ ํ‘œ์‹œ
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _incrementCounter, //ํด๋ฆญ์‹œ ์ € ๋ฉ”์„œ๋“œ ์‹คํ–‰
            tooltip: 'Increment',
            child: Icon(Icons.add), //์ƒ๋‹จ ์•ฑ๋ฐ”
          ), // This trailing comma makes auto-formatting nicer for build methods.
        );
      }
    }
    

     

    ์ „์ฒด ์ฝ”๋“œ๋ฅผ ๋ฉ์–ด๋ฆฌ๋กœ ํŒŒ์•…ํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    import 'package:flutter/material.dart';
    
    void main() {}
    
    class MyApp extends StatelessWidget {}
    
    class MyHomePage extends StatefulWidget {}
    
    class _MyHomePageState extends State<MyHomePage> {}
    

    ์œ„์˜ ์„ธ ๋ฉ์–ด๋ฆฌ๋Š” ์‚ฌ์‹ค์ƒ ์ˆ˜์ • ํ•˜์ง€ ์•Š๋Š” ๋ถ€๋ถ„. ์ฃผ์š” ์ฝ”๋“œ๋Š” ์•„๋ž˜ ๋‘ ๋ฉ์–ด๋ฆฌ์— ์žˆ๊ณ , ์ƒ˜ํ”Œ ์•ฑ์˜ ํ™”๋ฉด์„ ๋‚˜ํƒ€๋‚ด๋Š” ์ฝ”๋“œ๋“ค์ž„. ์‚ฌ์‹ค์ƒ ๋งˆ์ง€๋ง‰ ๋ฉ์–ด๋ฆฌ์— ๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ.

     

     

    ์ด์ œ๋ถ€ํ„ฐ ํ•œ ์ค„์”ฉ ์‚ดํŽด๋ณด๊ฒ ์Œ.

    import 'package:flutter/material.dart';

    flutter์—์„œ๋Š” ํ™”๋ฉด์„ ๊ทธ๋ฆฌ๋Š” ๋ชจ๋“  ๋””์ž์ธ ์š”์†Œ๋ฅผ widget์ด๋ผ๊ณ  ํ•จ.

    importํ•˜๋Š” 'package:flutter/material.dart' ํŒจํ‚ค์ง€์—๋Š” ๋จธํ‹ฐ๋ฆฌ์–ผ ๋””์ž์ธ ์œ„์ œ๋“ค์ด ํฌํ•จ๋˜์–ด ์žˆ์Œ.

    ๋จธํ‹ฐ๋ฆฌ์–ผ ๋””์ž์ธ : ํ”Œ๋žซ ๋””์ž์ธ์˜ ์žฅ์ ์„ ์‚ด๋ฆฌ๋ฉด์„œ๋„ ๋น›์— ๋”ฐ๋ฅธ ์ข…์ด์˜ ๊ทธ๋ฆผ์ž ํšจ๊ณผ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ž…์ฒด๊ฐ์„ ์‚ด๋ฆฌ๋Š” ๋””์ž์ธ ๋ฐฉ์‹์„ ๋งํ•œ๋‹ค. 2014๋…„ ๊ตฌ๊ธ€์ด ์•ˆ๋“œ๋กœ์ด๋“œ ์Šค๋งˆํŠธํฐ์— ์ ์šฉํ•˜๋ฉด์„œ ๋„๋ฆฌ ํผ์ง€๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค
     

    Material Design

    Build beautiful, usable products faster. Material Design is an adaptable system—backed by open-source code—that helps teams build high quality digital experiences.

    material.io

     

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

    main() ์€ ์•ฑ์˜ ์‹œ์ž‘์ . runApp()์— ์ธ์ž๋กœ MyApp()์„ ์ „๋‹ฌํ•œ๋‹ค.

     

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(...์ƒ๋žต...);
      }
    }

    StatelessWidget ํด๋ž˜์Šค. ์ƒํƒœ๊ฐ€ ์—†๋Š” ์œ„์ ฏ์„ ์ •์˜ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ. => ํ•œ ๋ฒˆ๋งŒ ๊ทธ๋ ค์ง„๋‹ค! (๋‹ค์‹œ ๊ทธ๋ ค์ง€์ง€ ์•Š์Œ)

    ์ด๋Ÿฐ ํด๋ž˜์Šค๋Š” property๋กœ ๋ณ€์ˆ˜๋ฅผ ๊ฐ€์ง€์ง€ ์•Š์Œ. (๋‹ค์‹œ ๊ทธ๋ ค์ง€์ง€ ์•Š์œผ๋‹ˆ๊นŒ)

    MyApp ํด๋ž˜์Šค๋Š” StatelessWidget ํด๋ž˜์Šค์˜ ์„œ๋ธŒํด๋ž˜์Šค.

    ์ด MyApp()์€ runApp()์— ์ „๋‹ฌ๋œ๋‹ค.

     

    StatelessWidget๋Š” build() ๋ฉ”์„œ๋“œ๋ฅผ ๊ฐ€์ง€๋Š”๋ฐ, ์ด ๋ฉ”์„œ๋“œ๋Š” ์œ„์ ฏ์„ ์ƒ์„ฑํ•  ๋•Œ ํ˜ธ์ถœ๋˜์–ด ์‹ค์ œ๋กœ ํ™”๋ฉด์— ๊ทธ๋ฆด ์œ„์ ฏ์„ ๋ฐ˜ํ™˜.

    ์ฆ‰, MyApp์ด build๊ฐ€ ๋ฆฌํ„ดํ•˜๋Š” MaterialApp() ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

     

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

    build๊ฐ€ ๋ฐ˜ํ™˜ํ•˜๋Š” MaterialApp class. ์—ฌ๊ธฐ๊นŒ์ง€๋Š” ๊ฑฐ์˜ ๋ชจ๋“  ํ”„๋กœ์ ํŠธ๊ฐ€ ๋™์ผํ•จ.

    title, theme, home ์„ธ๊ฐ€์ง€ ์ด๋ฆ„ ์žˆ๋Š” ์ธ์ˆ˜๋ฅผ ์„ค์ •ํ•ด ์œ„์ ฏ์˜ ์†์„ฑ์„ ํ‘œํ˜„. 

    title : ์ œ๋ชฉ

    theme : ํ…Œ๋งˆ. ์—ฌ๊ธฐ์„œ๋Š” blueํ…Œ๋งˆ.

    home : ์—ฌ๊ธฐ์— ์ž‘์„ฑํ•˜๋Š” ์œ„์ ฏ์ด ์‹ค์ œ ์ด ์•ฑ์ด ํ‘œ์‹œํ•˜๋Š” ์œ„์ ฏ์ด ๋จ.

     

    class MyHomePage extends StatefulWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      _MyHomePageState createState() => _MyHomePageState();
    }
    

    ์œ„์˜ home ์ธ์ž์— ๋“ค์–ด๊ฐ€๋Š” MyHomePage class. 

    ์ƒํƒœ๊ฐ€ ์žˆ๋Š” ์œ„์ ฏ์„ ์ •์˜ํ•  ๋•Œ๋Š” StatefulWidget class๋ฅผ ์‚ฌ์šฉ. 

     

    MyHomePage class์˜ ์ƒ์„ฑ์ž๋Š” key, title์„ ์˜ต์…˜์œผ๋กœ ๋ฐ›์•„์„œ super๋ฅผ ์ด์šฉํ•ด ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž์— key๋ฅผ ์ „๋‹ฌ.

    MyHomePage class๋Š” ์ƒ์†๋ฐ›์€ createState()๋ฅผ ์žฌ์ •์˜ํ•ด์„œ _MyHomePageState class์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋ฐ˜ํ™˜. ์ด ๋ฉ”์„œ๋“œ๋Š” StatefulWidget์ด ์ƒ์„ฑ๋  ๋•Œ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰๋จ.

     

    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0; //ํ™”๋ฉด์— ํ‘œ์‹œํ•  ์ƒํƒœ๊ฐ’. ์นด์šดํ„ฐ ์ˆซ์ž
    	...์ƒ๋žต...
    
      //ํ™”๋ฉด์— UI๋ฅผ ๊ทธ๋ฆฌ๋Š” ๋ฉ”์„œ๋“œ. ๊ทธ๋ ค์งˆ ์œ„์ ฏ์„ ๋ฐ˜ํ™˜
      @override
      Widget build(BuildContext context) {
        return Scaffold(...์ƒ๋žต...);
      }
    }
    

    ์ƒํƒœ ํด๋ž˜์Šค : State class๋ฅผ ์ƒ์†๋ฐ›์€ ํด๋ž˜์Šค. ์ƒํƒœ ํด๋ž˜์Šค๋Š” ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๋ฅผ ํ”„๋กœํผํ‹ฐ ๋ณ€์ˆ˜๋กœ ํ‘œํ˜„.

    Widget build๋Š” _MyHomePageState ํด๋ž˜์Šค์˜ ์ƒํƒœ์— ๋”ฐ๋ผ ํ™”๋ฉด์— ๊ทธ๋ ค์งˆ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ. ๋ชจ์–‘์€ ์•„๊นŒ build์™€ ๋™์ผ.

     

    ์œ„์ ฏ์—์„œ ์œ„์ ฏ์œผ๋กœ ๊ฐ’ ์ „๋‹ฌ?
    ์ƒ์„ฑ์ž๋ฅผ ์ด์šฉ. (ex/ MyHomePage({Key key, this.title}) : super(key: key)'
    ์ƒํƒœ ํด๋ž˜์Šค์—์„œ StatefulWidget ์— ์ ‘๊ทผํ•˜๋ ค๋ฉด widget property๋ฅผ ์‚ฌ์šฉ. (ex/ title:Text(widget.title))

     

    state ํด๋ž˜์Šค์—์„œ๋Š” ์ฃผ๋กœ ์ƒํƒœ๋ฅผ ์ €์žฅํ•  ๋ณ€์ˆ˜๋“ค, ๊ทธ ๋ณ€์ˆ˜๋ฅผ ์กฐ์ž‘ํ•  ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑ.

    ์œ„ ์˜ˆ์ œ์˜ State class๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

    class _MyHomePageState extends State<MyHomePage> {
      int _counter = 0; //ํ™”๋ฉด์— ํ‘œ์‹œํ•  ์ƒํƒœ๊ฐ’. ์นด์šดํ„ฐ ์ˆซ์ž
    
      void _incrementCounter() {
        setState(() {
          _counter++;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(...์ƒ๋žต...);
      }
    }
    

    ์ •์ˆ˜ํ˜• _counter๋Š” 0์œผ๋กœ ์ดˆ๊ธฐํ™”.

    _incrementCounter() method๋Š” setState()๋ฅผ ์‹คํ–‰. setState์˜ ์ธ์ˆ˜๋Š” _counter++์ธ ์ต๋ช… ํ•จ์ˆ˜.

    setState() : ํ™”๋ฉด์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ์—ญํ• ! =>  build()๋ฅผ ๋‹ค์‹œ ์‹คํ–‰ ํ•œ๋‹ค. (State class๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๋ฉ”์„œ๋“œ)

     

    ์ฆ‰, MyHomePage๋Š” StatefulWidget์˜ ์„œ๋ธŒ ํด๋ž˜์Šค์ด๋ฉฐ, ์ƒํƒœ๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ. 

    ์ƒํƒœ๋Š” State ํด๋ž˜์Šค์˜ ์„œ๋ธŒ ํด๋ž˜์Šค๋กœ ์ •์˜. (๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๋Š” _counter)

     

     

    ์ด์ œ _MyHomePage์˜ build๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ๋ถˆ๋ฆฌ๋Š” Scaffold class๋ฅผ ์‚ดํŽด๋ณด์ž.

    Scaffold class๋Š” ๋จธํ‹ฐ๋ฆฌ์–ผ ๋””์ž์ธ ์•ฑ์˜ ๋ผˆ๋Œ€๊ฐ€ ๋˜๋Š” ์œ„์ ฏ. MaterialApp -> Scaffold๊ฐ€ ๊ธฐ๋ณธ ํ˜•ํƒœ.

    ์‰ฝ๊ฒŒ ๋งํ•˜๋ฉด material design์˜ ๋Œ€๋žต์ ์ธ ์œ„์น˜? ๋ฅผ ์ง€์ •ํ•ด ๋‘๋Š” Widget.

    dalgonakit.tistory.com/103

     

    Flutter Scaffold? ์Šค์บํด๋“œ?

    ํ”Œ๋Ÿฌํ„ฐ๋ฅผ ์‹œ์ž‘ํ•˜๊ณ  ์€๊ทผํžˆ Scaffold๋ผ๋Š” ๋ง์„ ๋งŽ์ด ๋ดค์Šต๋‹ˆ๋‹ค. ์ €์—๊ฒ ๊ฐœ๋ฐœํ•˜๋ฉด์„œ ์ž˜ ๋ชป ๋ดค๋˜ ์ƒ์†Œํ•œ ๋‹จ์–ด ์ด๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค 0. ๋‹จ์–ด ์ผ๋‹จ ๋‹จ์–ด๋ถ€ํ„ฐ ์งš๊ณ  ๋„˜์–ด๊ฐ€ ๋ด…์‹œ๋‹ค ๊ตฌ๊ธ€์— ๊ฒ€์ƒ‰ํ•ด๋ณด๋‹ˆ ๋ฐœํŒ, ๊ณจ๊ฒฉ,

    dalgonakit.tistory.com

    origogi.github.io/flutter/Scafold/

     

    [Flutter] Widget ์†Œ๊ฐœ - Scaffold

     

    origogi.github.io

    Scaffold(
          appBar: AppBar( //์ƒ๋‹จ ์•ฑ๋ฐ”
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'You have pushed the button this many times:',
                ),
                Text(
                  '$_counter', //๋ณ€์ˆ˜๋ฅผ ํ‘œ์‹œ
                  style: Theme.of(context).textTheme.headline4,
                ),
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: _incrementCounter, //ํด๋ฆญ์‹œ ์ € ๋ฉ”์„œ๋“œ ์‹คํ–‰
            tooltip: 'Increment',
            child: Icon(Icons.add), //์ƒ๋‹จ ์•ฑ๋ฐ”
          ), 
        );

     

    ์ด ์˜ˆ์ œ์—์„œ๋Š” ์ธ์ž๋กœ appBar, body, floatingActionButtion์„ ์ •์˜.

     

    appBar

    ์—ฌ๊ธฐ์— AppBar class์˜ ๊ฐ์ฒด ์ „๋‹ฌ. ์ƒ๋‹จ์˜ ์ œ๋ชฉ, ๋ฉ”๋‰ด๋ฅผ ํ‘œ์‹œํ•˜๋Š” ์˜์—ญ.

    AppBar class๋Š” title์— Text widget์„ ์ •์˜. Text widget์€ ๊ธ€์ž๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์œ„์ ฏ์ด๋ฉฐ ์ธ์ˆ˜๋กœ widget.title๋ฅผ ๋ฐ›์Œ. widget์€ 

    StatefulWidget class (MyHomePage)์˜ ํ”„๋กœํผํ‹ฐ๋ฅผ ์ฐธ์กฐํ•  ๋•Œ ์‚ฌ์šฉ.

     

    body

    _counter๋Š” ์ •์ˆ˜ํ˜• ๋ณ€์ˆ˜๋ผ Text ์œ„์ ฏ์— ํ‘œ์‹œํ•˜๋ ค๋ฉด ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝํ•ด์•ผ ํ•จ. ๊ทธ๋ž˜์„œ ๋ณ€์ˆ˜์˜ ๊ฐ’์„ ๋ฌธ์ž์—ด ํ˜•ํƒœ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ ์ž ํ• ๋• ๋ณ€์ˆ˜ ์•ž์— $๋ฅผ ๋ถ™์ž„.

     

    floatingActionButtion

    ์‚ฌ์šฉ์ž๊ฐ€ +๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ _increamentCounter() ๋ฉ”์„œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋จ.

    ํ˜ธ์ถœ๋˜๋ฉด setState()์— ์˜ํ•ด _counter++๋ฅผ ํ•œ ๋’ค, build๊ฐ€ ๋‹ค์‹œ ํ˜ธ์ถœ => ํ™”๋ฉด์ด ๋‹ค์‹œ ๊ทธ๋ ค์ง

     

    onPressed : ๋ฒ„ํŠผ์ด ๋ˆŒ๋Ÿฌ์ง€๋ฉด ์‹คํ–‰๋˜๋Š” ๋ถ€๋ถ„. ์—ฌ๊ธฐ์— ๋™์ž‘์‹œํ‚ฌ ์ฝ”๋“œ๋ฅผ ํ•จ์ˆ˜ ํ˜•ํƒœ๋กœ ์ž‘์„ฑ. Dart์—์„œ๋Š” ํ•จ์ˆ˜๋„ ๊ฐ’์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ!

    tooltip : ์‚ฌ์šฉ์ž๊ฐ€ +๋ฅผ ๊ธธ๊ฒŒ ํ„ฐ์ง€ํ•  ๋•Œ ํ‘œ์‹œํ•  ๊ธ€์ž๋ฅผ ์ง€์ •.

    child : ์•„์ด์ฝ˜ instance๋ฅผ ์ •์˜ํ•ด์„œ +๋ชจ์–‘ ๋ฒ„ํŠผ์„ ํ‘œํ˜„.

     

     


    ์ฐธ์กฐ : ์˜ค์ค€์„์˜ ํ”Œ๋Ÿฌํ„ฐ ์ƒ์กด์ฝ”๋”ฉ

    ๋Œ“๊ธ€