๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Flutter

[ Flutter ] ๊ธธ์ด์— ๋”ฐ๋ผ Text ์ž๋™ ์ค„๋ฐ”๊ฟˆ / Flexible Text

 

 

 

 

 

Flutter์—์„œ ์ž‘์—…์ค‘ Text๋ฅผ ๋‚ด๊ฐ€ ์ •ํ•œ Width ๊ธธ์ด ๋ฐ ์ค„์„ ์„ค์ •ํ•˜์—ฌ ๊ทธ ์ดํ›„์˜ ํ…์ŠคํŠธ๋“ค์€ ๋ณด์ด์ง€ ์•Š๊ฒŒ ํ•˜๋Š” ๋ฐฉ๋ฒ•.๐Ÿฅณ

๋‚˜๋Š” ์ƒ์„ธ ํŽ˜์ด์ง€ ์ด์ „์— ๋ฏธ๋ฆฌ๋ณด๊ธฐ ํŽ˜์ด์ง€์—์„œ ํ…์ŠคํŠธ๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์งˆ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ๋‹ค๐Ÿ˜„ !!

 

 

 

 

 

 

 

์ง€์ •ํ•œ ๋„ˆ๋น„์™€ ์ค„์— ๋”ฐ๋ผ Text๊ฐ€ Flexible ํ•˜๊ฒŒ ๋ณด์—ฌ์ง„๋‹ค. 

์œ„์™€๊ฐ™์ด Container์— width๋ฅผ ์ •ํ•ด์ฃผ๊ณ , maxLines๋ฅผ ์ •ํ•˜๋ฉด, ๋‚ด๊ฐ€ ์ •ํ•ด๋†“์€ ๊ฐ’์„ ๋„˜๊ธฐ์ง€ ์•Š๋Š”๋‹ค.

์•„์ฃผ ๊ต‰์žฅํžˆ ์œ ์šฉ์“ฐ ํ•˜๋‹ค.๐Ÿ‘  * 10000

 

 

 

 

 

 

 

 

 

 

width: 150 / maxLines: 5

Container(
  width: 150,
  child: Row(
    mainAxisAlignment: MainAxisAlignment.start,
    children: [
      Flexible(
          child: RichText(
        overflow: TextOverflow.ellipsis,
        maxLines: 5,
        strutStyle: StrutStyle(fontSize: 16.0),
        text: TextSpan(
            text:
                '์„ธ๊ณ„๋ฌธ์ž ๊ฐ€์šด๋ฐ ํ•œ๊ธ€,์ฆ‰ ํ›ˆ๋ฏผ์ •์Œ์€ ํ”ํžˆ๋“ค ์‹ ๋น„๋กœ์šด ๋ฌธ์ž๋ผ ๋ถ€๋ฅด๊ณค ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์€ ์„ธ๊ณ„ ๋ฌธ์ž ๊ฐ€์šด๋ฐ ์œ ์ผํ•˜๊ฒŒ ํ•œ๊ธ€๋งŒ์ด ๊ทธ๊ฒƒ์„ ๋งŒ๋“  ์‚ฌ๋žŒ๊ณผ ๋ฐ˜ํฌ์ผ์„ ์•Œ๋ฉฐ, ๊ธ€์ž๋ฅผ ๋งŒ๋“  ์›๋ฆฌ๊นŒ์ง€ ์•Œ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์„ธ๊ณ„์— ์ด๋Ÿฐ ๋ฌธ์ž๋Š” ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ํ•œ๊ธ€์€, ์ •ํ™•ํžˆ ๋งํ•ด [ํ›ˆ๋ฏผ์ •์Œ ํ•ด๋ก€๋ณธ](๊ตญ๋ณด 70ํ˜ธ)์€ ์ง„์ฆ‰์— ์œ ๋„ค์Šค์ฝ” ์„ธ๊ณ„๊ธฐ๋ก์œ ์‚ฐ์œผ๋กœ ๋“ฑ์žฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ‘ํ•œ๊ธ€’์ด๋ผ๋Š” ์ด๋ฆ„์€ 1910๋…„๋Œ€ ์ดˆ์— ์ฃผ์‹œ๊ฒฝ ์„ ์ƒ์„ ๋น„๋กฏํ•œ ํ•œ๊ธ€ํ•™์ž๋“ค์ด ์“ฐ๊ธฐ ์‹œ์ž‘ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ‘ํ•œ’์ด๋ž€ ํฌ๋‹ค๋Š” ๊ฒƒ์„ ๋œปํ•˜๋‹ˆ, ํ•œ๊ธ€์€ ‘ํฐ ๊ธ€’์„ ๋งํ•œ๋‹ค๊ณ  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.[๋„ค์ด๋ฒ„ ์ง€์‹๋ฐฑ๊ณผ] ํ•œ๊ธ€ - ์„ธ์ƒ์—์„œ ๊ฐ€์žฅ ์‹ ๋น„ํ•œ ๋ฌธ์ž (์œ„๋Œ€ํ•œ ๋ฌธํ™”์œ ์‚ฐ, ์ตœ์ค€์‹)',
            style: TextStyle(
                color: Colors.black,
                height: 1.4,
                fontSize: 16.0,
                fontFamily: 'NanumSquareRegular')),
      )),
    ],
  ));

๋ถ€๋ชจ์˜ ๋„ˆ๋น„๋ฅผ ์ง€์ •ํ•ด์ฃผ๊ณ , Flexible์•ˆ์— RichText๋กœ maxLines๋ฅผ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

๋ณดํ†ต์€ text ์— ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ€๊ธฐ ๋•Œ๋ฌธ์— ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๋Œ€๋กœ text ๋ชจ์–‘์„ ๋ณด์—ฌ์ฃผ๊ณ  ์‹ถ์„ ๋•Œ ์œ ์šฉํ•˜๋‹ค.

 

 

 

 

 

 

 

 

 

width: 350 / maxLines: 2

Container(
    width: 350,
    child: Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        Flexible(
            child: RichText(
          overflow: TextOverflow.ellipsis,
          maxLines: 2,
          strutStyle: StrutStyle(fontSize: 16.0),
          text: TextSpan(
              text:
                  '์„ธ๊ณ„๋ฌธ์ž ๊ฐ€์šด๋ฐ ํ•œ๊ธ€,์ฆ‰ ํ›ˆ๋ฏผ์ •์Œ์€ ํ”ํžˆ๋“ค ์‹ ๋น„๋กœ์šด ๋ฌธ์ž๋ผ ๋ถ€๋ฅด๊ณค ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์€ ์„ธ๊ณ„ ๋ฌธ์ž ๊ฐ€์šด๋ฐ ์œ ์ผํ•˜๊ฒŒ ํ•œ๊ธ€๋งŒ์ด ๊ทธ๊ฒƒ์„ ๋งŒ๋“  ์‚ฌ๋žŒ๊ณผ ๋ฐ˜ํฌ์ผ์„ ์•Œ๋ฉฐ, ๊ธ€์ž๋ฅผ ๋งŒ๋“  ์›๋ฆฌ๊นŒ์ง€ ์•Œ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์„ธ๊ณ„์— ์ด๋Ÿฐ ๋ฌธ์ž๋Š” ์—†์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ํ•œ๊ธ€์€, ์ •ํ™•ํžˆ ๋งํ•ด [ํ›ˆ๋ฏผ์ •์Œ ํ•ด๋ก€๋ณธ](๊ตญ๋ณด 70ํ˜ธ)์€ ์ง„์ฆ‰์— ์œ ๋„ค์Šค์ฝ” ์„ธ๊ณ„๊ธฐ๋ก์œ ์‚ฐ์œผ๋กœ ๋“ฑ์žฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ‘ํ•œ๊ธ€’์ด๋ผ๋Š” ์ด๋ฆ„์€ 1910๋…„๋Œ€ ์ดˆ์— ์ฃผ์‹œ๊ฒฝ ์„ ์ƒ์„ ๋น„๋กฏํ•œ ํ•œ๊ธ€ํ•™์ž๋“ค์ด ์“ฐ๊ธฐ ์‹œ์ž‘ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ‘ํ•œ’์ด๋ž€ ํฌ๋‹ค๋Š” ๊ฒƒ์„ ๋œปํ•˜๋‹ˆ, ํ•œ๊ธ€์€ ‘ํฐ ๊ธ€’์„ ๋งํ•œ๋‹ค๊ณ  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.[๋„ค์ด๋ฒ„ ์ง€์‹๋ฐฑ๊ณผ] ํ•œ๊ธ€ - ์„ธ์ƒ์—์„œ ๊ฐ€์žฅ ์‹ ๋น„ํ•œ ๋ฌธ์ž (์œ„๋Œ€ํ•œ ๋ฌธํ™”์œ ์‚ฐ, ์ตœ์ค€์‹)',
              style: TextStyle(
                  color: Colors.black,
                  height: 1.4,
                  fontSize: 16.0,
                  fontFamily: 'NanumSquareRegular')),
        )),
      ],
    ));

 

 

 

 

 

 

 

 

 

 

์ƒ๋žต์ด "..." ์œผ๋กœ ๋‚˜์˜ค๋Š”๋ฐ ์ด๊ฑด RichText ์˜ overflow ์„ค์ •์— ๋”ฐ๋ผ ๋‹ค๋ฅด๊ฒŒ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ๋‹ค.

 

TextOverflow {
  /// Clip the overflowing text to fix its container.
  clip,

  /// Fade the overflowing text to transparent.
  fade,

  /// Use an ellipsis to indicate that the text has overflowed.
  ellipsis,

  /// Render overflowing text outside of its container.
  visible,
}

 

overflow: TextOverflow.clip

ํ…์ŠคํŠธ๋ฅผ ํด๋ฆฌํ•‘ํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ณ ์ •.

 

 

 

overflow: TextOverflow.fade

ํ…์ŠคํŠธ๋ฅผ ํˆฌ๋ช…ํ•˜๊ฒŒ Fade ํ•จ.

 

 

 

overflow: TextOverflow.ellipsis

์ค„์ž„ํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…์ŠคํŠธ๊ฐ€ ์˜ค๋ฒ„ํ”Œ๋กœ๋˜์—ˆ์Œ์„ ๋‚˜ํƒ€๋ƒ„.

 

 

 

overflow: TextOverflow.visible

์ปจํ…Œ์ด๋„ˆ ์™ธ๋ถ€์— ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ ํ…์ŠคํŠธ๋ฅผ ๋ Œ๋”๋ง ํ•จ.

 

 

 

 

 

 

์ง  - ! ๐Ÿคฉ 

 

 

 

 

 

๐Ÿ‘‰  ์ฐธ๊ณ 

Flutter - RichText Class

Flutter - Flexible class