■ 폰트 파일을 추가하는 방법을 보여준다.
▶ pubspec.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
name: test_app description: A new Flutter application. publish_to: 'none' version: 1.0.0+1 environment: sdk: ">=2.7.0 <3.0.0" dependencies: flutter: sdk: flutter cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: sdk: flutter flutter: uses-material-design: true assets: - image/flutter.png fonts: - family: Pacifico fonts: - asset: font/Pacifico-Regular.ttf weight: 400 |
▶ imagePage.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import 'package:flutter/material.dart'; class ImagePage extends StatefulWidget { @override State<StatefulWidget> createState() { return _ImagePageState(); } } class _ImagePageState extends State<ImagePage> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Test Application'), ), body: Container( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Image.asset( 'image/flutter.png', width: 200, height: 200, fit: BoxFit.fill, ), Text( 'Hello Flutter', style: TextStyle( fontFamily: 'Pacifico', fontSize: 30, color: Colors.blue, ), ) ], ), ) ), ); } } |
▶ main.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import 'package:flutter/material.dart'; import 'imagePage.dart'; void main() { runApp(TestApplication()); } class TestApplication extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Test Application', theme: ThemeData( primarySwatch: Colors.blue, ), home: ImagePage(), ); } } |