HIDI Flutter Challenge (3) Image Widget

hello_hidiΒ·2021λ…„ 8μ›” 29일
0

HIDI's Flutter Challenge

λͺ©λ‘ 보기
3/12
post-thumbnail

Image Widget

> Image Widget

  • 이미지λ₯Ό ν‘œμ‹œν•˜λŠ” μœ„μ ―
  • μ§€μ›λ˜λŠ” 이미지 ν˜•μ‹ : JPEG, PNG, GIF, μ• λ‹ˆλ©”μ΄μ…˜ GIF, WebP, μ• λ‹ˆλ©”μ΄μ…˜ WebP, BMP 및 WBMP

const Image({
  Key? key,
  required this.image,
  this.frameBuilder,
  this.loadingBuilder,
  this.errorBuilder,
  this.semanticLabel,
  this.excludeFromSemantics = false,
  this.width,
  this.height,
  this.color,
  this.colorBlendMode,
  this.fit,
  this.alignment = Alignment.center,
  this.repeat = ImageRepeat.noRepeat,
  this.centerSlice,
  this.matchTextDirection = false,
  this.gaplessPlayback = false,
  this.isAntiAlias = false,
  this.filterQuality = FilterQuality.low,
}) : assert(image != null),
     assert(alignment != null),
     assert(repeat != null),
     assert(filterQuality != null),
     assert(matchTextDirection != null),
     assert(isAntiAlias != null),
     super(key: key);

>> Image μœ„μ ―μ˜ μ£Όμš” 속성

  • width, height : μ΄λ―Έμ§€μ˜ κ°€λ‘œ, μ„Έλ‘œ 크기
  • fit : μ›ν•˜λŠ” 곡간에 이미지가 λ“€μ–΄λ§žλ„λ‘ ν•˜λŠ” 속성
  • alignment : 이미지 μ •λ ¬
  • semanticLabel : 이미지λ₯Ό μ„€λͺ…ν•˜λŠ” μ†Œκ°œκΈ€

>> Image 등둝 방법

  1. Image.asset() : 앱에 μ €μž₯된 λŒ€μƒμ„ λŒμ–΄μ™€ 이미지λ₯Ό 띄움 => λ‹€λ₯Έ 버젼듀을 μ €μž₯ν•΄ pubspec.yaml μ•ˆμ— λ‚˜μ—΄ν•˜λ©΄ 됨
  2. Image.file() : μ‚¬μš©μž μž₯μΉ˜μ—μ„œ 이미지λ₯Ό κ°€μ Έμ™€μ„œ 띄움
  3. Image. memory() : λ©”λͺ¨λ¦¬μ— μ €μž₯된 이미지λ₯Ό λ°”μ΄νŠΈ λ°°μ—΄λ‘œ λ‚˜νƒ€λ‚Ό λ•Œ
  4. Image.network() : URLμ—μ„œ 이미지λ₯Ό 가져와 띄움 => Flutterκ°€ 이미지 νŒŒμΌμ„ λ‹€μš΄λ‘œλ“œν•΄μ„œ μΊμ‹œλ₯Ό μ €μž₯ν•˜κ³  화면에 띄움

>> μ˜ˆμ‹œ μ½”λ“œ

  
 import 'package:flutter/material.dart';
 import 'package:file/file.dart';

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

  /// This is the main application widget.
  class MyApp extends StatelessWidget {
    static String _title = 'Flutter Code Sample';

    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: _title,
        debugShowCheckedModeBanner: false,
        home: ImageWidget(),
      );
    }
  }

  class ImageWidget extends StatefulWidget {
    _ImageWidgetState createState() => _ImageWidgetState();
  }

  class _ImageWidgetState extends State {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(),
        body: SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(25.0),
            child: ListView(
              children: [
                Text(
                  "image asset 이용",
                  style: TextStyle(fontSize: 25),
                ),
                Image.asset(
                  'assets/IMG_0239.jpeg',
                  fit: BoxFit.cover,
                ),
                SizedBox(height: 2),
                Text(
                  "image network 이용",
                  style: TextStyle(fontSize: 25),
                ),
                Image.network(
                  'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg',
                  fit: BoxFit.cover,
                ),
                SizedBox(height: 2),
                Text(
                  "image file 이용 - μΆ”ν›„ μˆ˜μ • μ˜ˆμ •",
                  style: TextStyle(fontSize: 25),
                ),
                SizedBox(height: 2),
                Text(
                  "image memory 이용 - μΆ”ν›„ μˆ˜μ • μ˜ˆμ •",
                  style: TextStyle(fontSize: 25),
                ),
                SizedBox(height: 2),
              ],
            ),
          ),
        ),
      );
    }
  }
  
  

>> μ‹€ν–‰κ²°κ³Ό

image

profile
μ•ˆλ‡½ν¬λ””

0개의 λŒ“κΈ€