[Flutter] AppBar의 "모든 것"
다음 Flutter 애플리케이션에서는 제목만 AppBar Tutorial로 설정하여 Scaffold에 간단한 AppBar를 표시합니다.
main.dart
import 'package:flutter/material.dart' ; void main() => runApp( const MyApp()); /// main application widget class MyApp extends StatelessWidget { const MyApp({Key? key}) : super (key: key); static const String _title = 'Flutter Tutorial' ; @override Widget build(BuildContext context) { return const MaterialApp( title: _title, home: MyStatelessWidget(), ); } } /// stateless widget that the main application instantiates class MyStatelessWidget extends StatelessWidget { const MyStatelessWidget({Key? key}) : super (key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text( 'AppBar Tutorial' ), ), body: const Center( child: Text( 'Hello World!' , style: TextStyle(fontSize: 24 ), ), ), ); } } |
스크린샷 [안드로이드 에뮬레이터, ios 시뮬레이터]
AppBar에 IconButton 추가하기
main.dart
import 'package:flutter/material.dart' ; void main() => runApp( const MyApp()); /// main application widget class MyApp extends StatelessWidget { const MyApp({Key? key}) : super (key: key); static const String _title = 'Flutter Tutorial' ; @override Widget build(BuildContext context) { return const MaterialApp( title: _title, home: MyStatelessWidget(), ); } } /// stateless widget that the main application instantiates class MyStatelessWidget extends StatelessWidget { const MyStatelessWidget({Key? key}) : super (key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text( 'AppBar Tutorial' ), actions: <Widget>[ IconButton( icon: const Icon(Icons.add_alert), onPressed: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text( 'You pressed bell icon.' ))); }, ), ], ), body: const Center( child: Text( 'Hello World!' , style: TextStyle(fontSize: 24 ), ), ), ); } } |
스크린샷 [안드로이드 에뮬레이터, ios 시뮬레이터]
댓글
댓글 쓰기