-
StatelessWidget ์ค์ต
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: Scaffold( appBar: AppBar( title:Text('Hello World'), ), body: Text( 'Hello World', style: TextStyle(fontSize: 40), ), ) ); } }
stless์ ๊ฒฝ์ฐ home์ ๋ฐ๋ก ์์ฑ์ด ๊ฐ๋ฅํ์ง๋ง, ๋ณดํต ๊ฐ๋ ์ฑ์ ์ํด ๋ณ๋์ ํด๋์ค๋ก ๋ถ๋ฆฌํจ.
//๋ณ๋์ ํด๋์ค๋ก ๋ถ๋ฆฌํ ๊ฒฝ์ฐ. ์๋์ ์์ ๋์ผ 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 StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title:Text('Hello World'), ), body: Text( 'Hello World', style: TextStyle(fontSize: 40), ), ); } }
StatefulWidget ์ค์ต
๋ฒํผ์ ๋๋ฅด๋ฉด ๊ธ์๊ฐ ๋ณ๊ฒฝ๋๋ ์์ .
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> { var _text = "Wow"; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Hello world'), ), body: Text( _text, style: TextStyle(fontSize: 40), ), floatingActionButton: FloatingActionButton( onPressed: (){ setState(() { _text = "hello!"; }); }, child: Icon(Icons.wb_sunny), ), ); } }
'๐STUDY > ๐ซDart&Flutter' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[flutter] widget 2 : ํ๋ฉด ๋ฐฐ์น๋ฅผ ์ํ ๋ ์ด์์-2 (0) 2021.02.07 [flutter] widget 1 : ํ๋ฉด ๋ฐฐ์น๋ฅผ ์ํ ๋ ์ด์์ (0) 2021.02.07 [flutter] android studio flutter Widget ์๋์์ฑ (0) 2021.02.06 [flutter] flutter ์์ ์ฝ๋ ๋ถ์ - 1 (0) 2021.02.06 [์ธ์ด] Dart ๋ฌธ๋ฒ ์ ๋ฆฌ (2) 2021.01.27 ๋๊ธ