์žฌ๋ฐŒ๋Š”๊ฑฐ๐ŸŒˆ

Flutter_12. Package, Gesture, List, Image, Swipe, Button ๋ณธ๋ฌธ

๊ฐœ๋ฐœํ•˜๊ธฐ/Flutter Start

Flutter_12. Package, Gesture, List, Image, Swipe, Button

uraon 2023. 5. 6. 00:17
728x90
๋ฐ˜์‘ํ˜•

์ง€๋‚œ ๋ฒˆ ๋ณ„๋„ ํŒŒ์ผ๋กœ body๋ฅผ ๋ถ„๋ฆฌํ•˜์˜€๋‹ค. ์ด์–ด์„œ ํ™ˆํ™”๋ฉด์„ ๋งŒ๋“ค์–ด ๋ณด๊ฒ ๋‹ค.

ํŒŒ์ผ์€ img_swipe.dart ์— ์ด์–ด์„œ ์ž‘์—… ํ•  ์˜ˆ์ •์ด๋‹ค.

 

2023.05.05 - [๊ฐœ๋ฐœํ•˜๊ธฐ] - Flutter_11. Drawer, ListTitle, Navigator, body, class, Stateful

 

Flutter_11. Drawer, ListTitle, Navigator, body, class, Stateful

์˜ค๋Š˜์€ ์ง€๋‚œ๋ฒˆ ํฌ์ŠคํŒ…์— ์ด์–ด์„œ Drawer์— ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ํŽ˜์ด์ง€ ์ด๋™์„ ์‹œ์ผœ๋ณด๋„๋ก ํ•˜๊ฒ ๋‹ค. 2023.05.04 - [๊ฐœ๋ฐœํ•˜๊ธฐ] - Flutter_10. Drawer, AppBar IconButton Flutter_10. Drawer, AppBar IconButton ์˜ค๋Š˜์€ AppBar์— IconBut

uraon.tistory.com

 

 

 

 

Packages, Gesture

 

1) pub.dev ์—์„œ gesture ๊ฒ€์ƒ‰

https://pub.dev/packages/simple_gesture_detector

 

simple_gesture_detector | Flutter Package

Easy to use, reliable and lightweight gesture detector for Flutter apps. Exposes simple API to react to basic gestures.

pub.dev

 

2) ๋ณต์‚ฌ

 

3) pubspec.yaml ํŒŒ์ผ์— ๋„ฃ๊ณ  ์ €์žฅ

 

 

 

 

 

 

Image, List, SimpleGestureDetector, Swipe

 

 

1)  ๋ฆฌ์ŠคํŠธ ๋งŒ๋“ค๊ธฐ

 

 

2) body์— ์‚ฌ์šฉํ•˜๊ณ  ์ถœ๋ ฅ ํ™•์ธ

 

 

3) SimpleGestureDetector๋กœ Wrap

- Center ํด๋ฆญํ•˜๊ณ  ์ „๊ตฌ(๐Ÿ’ก) ํด๋ฆญ
- Wrap with Widget ์„ ํƒํ•˜๊ณ , "SimpleGestureDetector"๋กœ ์ด๋ฆ„ ๋ณ€๊ฒฝ
- SimpleGestureDetector์— ๋นจ๊ฐ„ ์ค„ ๋œจ๋ฉด, ์ „๊ตฌ(๐Ÿ’ก) ํด๋ฆญํ•˜์—ฌ Import Library

 

 

4) onHorizontalSwipe:, onVerticalSwipe: ์— ํ•จ์ˆ˜ ์‚ฌ์šฉ

 

 

 

5) ์ขŒ์šฐ ์Šค์™€์ดํ”„ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ : _onHorizontalSwipe(SwipeDirection direction)

  // --- ์ขŒ์šฐ ์Šค์™€์ดํ”„ Func
  _onHorizontalSwipe(SwipeDirection direction){
    if(direction == SwipeDirection.left){
      setState(() {
        currentImage+=1;
        if(currentImage >= imageName.length){
          currentImage = 0;
        }
      });
    }else{
      setState(() {
        currentImage-=1;
        if(currentImage < 0){
          currentImage = imageName.length - 1;
        }
      });
    }
  }

 

 

 

6) ์œ„์•„๋ž˜ ์Šค์™€์ดํ”„ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ : _onVerticalSwipe(SwipeDirection direction)

  // --- ์œ„์•„๋ž˜ ์Šค์™€์ดํ”„ Func
  _onVerticalSwipe(SwipeDirection direction){
    if(direction == SwipeDirection.up){
      setState(() {
        currentImage+=1;
        if(currentImage >= imageName.length){
          currentImage = 0;
        }
      });
    }else{
      setState(() {
        currentImage-=1;
        if(currentImage < 0){
          currentImage = imageName.length - 1;
        }
      });
    }
  }

 

 

 

 

7) ์ €์žฅํ•˜๊ณ  ํ™”๋ฉด ํ™•์ธํ•ด๋ณด๋‹ˆ, ์ข€ ์ด์ƒํ•ด์„œ padding๊ณผ SizedBox๋กœ ์ด๋ฏธ์ง€ ๋‹ด๊ธฐ ์ถ”๊ฐ€ ์ง„ํ–‰!

 

 

 

8) ์ €์žฅํ•˜๊ณ  ํ™”๋ฉด ํ™•์ธ ๋ฐ ์ด๋ฏธ์ง€ ์Šค์™€์ดํ”„ ํ…Œ์ŠคํŠธ

 

 

 

 

 

 

 

Image, List, SimpleGestureDetector, Button

 

 

 

 

1) ๋ฒ„ํŠผ์— setState๋กœ ์ด๋ฒคํŠธ : ๋ฒ„ํŠผ [์ด์ „์œผ๋กœ] ํด๋ฆญ ์‹œ ํ˜„์žฌ ์ด๋ฏธ์ง€์—์„œ -1

 

 

2) ๋ฒ„ํŠผ์— setState๋กœ ์ด๋ฒคํŠธ : ๋ฒ„ํŠผ [๋‹ค์Œ์œผ๋กœ] ํด๋ฆญ ์‹œ ํ˜„์žฌ ์ด๋ฏธ์ง€์—์„œ +1

 

 

 

3) ์ €์žฅํ•˜๊ณ  ํ™”๋ฉด ํ™•์ธ ๋ฐ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ ์ด๋ฏธ์ง€ ๋ณ€๊ฒฝ ํ™•์ธ 

 

 

 

๋ฐ˜์‘ํ˜•

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•