■ Image 클래스의 width/height/fit 속성을 사용하는 방법을 보여준다.
▶ 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 |
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 |
▶ 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 |
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, ), ], ), ) ), ); } } |
▶ MainPage.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(), ); } } |