๐Ÿฆ‹Flutter - ์œ„์ ฏ ๊ถŒํ•œ ๊ด€๋ฆฌ

4084 ๋‹จ์–ด flutterdartproductivityopensource
Flutter์—์„œ๋Š” ํ•ญ์ƒ ๊ฐ™์€ ์œ„์ ฏ์„ ํ‘œ์‹œํ•˜๊ณ  ์‹ถ์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ํ‘œ์‹œํ•  ์œ„์ ฏ์€ ํ˜„์žฌ ์‚ฌ์šฉ์ž์— ๋”ฐ๋ผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.

Stay tuned to learn how you can easily display widgets depending on the current user role.
use the widget ->



๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ์œ„์ ฏ



์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ์ž์˜ ํ˜„์žฌ ์—ญํ• ๊ณผ ์Šน์ธ์„ ๋ฐ›๋Š” ์œ„์ ฏ์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ถŒํ•œ ๋ถ€์—ฌ์—๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๋ชจ๋“  ์œ ํšจํ•œ ์—ญํ• ์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค. ์ „๋‹ฌ๋œ ์—ญํ• ์ด ์ง€์ •๋œ ํ•˜๋‚˜์˜ ์œ„์ ฏ์— ์œ ํšจํ•˜๋ฉด ์˜ˆ์ƒ ์œ„์ ฏ์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ๊ถŒํ•œ ๋ถ€์—ฌ์— ์—ญํ• ์„ ํ• ๋‹นํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ ์•„๋ฌด ๊ฒƒ๋„ ํ‘œ์‹œ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค(๋˜๋Š” ๋น„์–ด ์žˆ๋Š” SizedBox ์œ„์ ฏ).
์ค‘์•™ ๊ถŒํ•œ ๋ถ€์—ฌ ์œ„์ ฏ์€ AnimatedSwitcher๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ญํ• ์ด ๋ณ€๊ฒฝ๋  ๋•Œ ๋ถ€๋“œ๋Ÿฌ์šด ์˜ค๋ฒ„ํ”Œ๋กœ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ƒํƒœ ๋น„์ €์žฅ ์œ„์ ฏ์ž…๋‹ˆ๋‹ค.

์ตœ์ข… ์œ„์ ฏ์—๋Š” ๋‹ค์Œ ์†์„ฑ์ด ํฌํ•จ๋ฉ๋‹ˆ๋‹ค...

  final List<Tuple2<Authorization, Widget>> children;
  final String role;
  ... and all attributes for an AnimatedSwitcher-Widget


์ƒ์„ฑ์ž ...

 AuthorizationWidget(
      {this.key,
      this.children,
      this.role,
      [...]
      })
      : assert(role != null),
        super(key: key);


๋นŒ๋“œ ๋ฐฉ๋ฒ•์—์„œ Animated Switcher๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

@override
  Widget build(BuildContext context) {
    return AnimatedSwitcher(
      key: key ?? GlobalKey(),
      [...]
      child: _getWidget(),
    );
  }


children ์†์„ฑ์—๋Š” ๋‘ ๊ฐœ์˜ ํŠœํ”Œ(Tuple2) ๋ชฉ๋ก์ด ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํŠœํ”Œ์€ ํ‚ค ๊ฐ’ ์›์น™์— ๋”ฐ๋ผ ์œ„์ ฏ์— ์ธ์ฆ ๊ฐœ์ฒด๋ฅผ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. ๊ถŒํ•œ ๊ฐœ์ฒด์—์„œ ํ˜„์žฌ ์—ญํ• ์ด ๋ฐœ๊ฒฌ๋˜๋ฉด ํ•ด๋‹น ์œ„์ ฏ์ด ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. (๊ธฐ์ค€์— ์ผ์น˜ํ•˜๋Š” ์ฒซ ๋ฒˆ์งธ ์œ„์ ฏ๋งŒ ํ‘œ์‹œ๋˜๋Š” ์  ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.)

๊ฒฐ๊ณผ





๊ฒฐ๊ณผ ์œ„์ ฏ์€ Github ๋ฐ pub.dev์—์„œ ์˜จ๋ผ์ธ์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋ชจ๋“  Flutter ํ”„๋กœ์ ํŠธ์— ํ†ตํ•ฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Github์˜ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.
pub.dev์„ ์‚ฌ์šฉํ•˜์—ฌ Flutter ํ”„๋กœ์ ํŠธ์— ํ†ตํ•ฉ

ํ”ผ๋“œ๋ฐฑ



์œ„์ ฏ์„ ๋” ์ž˜ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์•„์ด๋””์–ด๋‚˜ ์ œ์•ˆ์ด ์žˆ์œผ๋ฉด ์ด ๊ฒŒ์‹œ๋ฌผ์— ์ž์œ ๋กญ๊ฒŒ ๋Œ“๊ธ€์„ ๋‹ฌ์•„์ฃผ์„ธ์š”.
ํ–ฅํ›„ Flutter์™€ ๊ทธ ๋ฉ”์ปค๋‹ˆ์ฆ˜์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด Github์—์„œ ๋‚ด ํ”„๋กœํ•„์„ ํŒ”๋กœ์šฐํ•˜์„ธ์š”.

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ