[Flutter] InkWell 물결효과가 동작하지 않는 문제해결법(InkWell not showing ripple effect)

2022. 8. 30. 15:07·Flutter/Error and Tips
반응형

문제 발생

아래와 같이 Container에 InkWell을 붙였는데 InkWell의 물결 효과가 나타나지 않았습니다.

 

찾아보니 해당 이슈는 플러터의 bug report에 등록되어 있었고 Container의 컬러가 InkWell의 ripple effect를 덮어버리기 때문에 이러한 현상이 일어난다고 합니다.

 

Ripple효과를 가진 Container를 만들때마다 이런 버그가 있는지 깜빡하고 맨날 해결법 검색을 해서 해결책을 적어두고 보려고 합니다.

 

https://github.com/flutter/flutter/issues/3782

 

InkWell and FlatButton do not ripple when inside a container with opaque background · Issue #3782 · flutter/flutter

Steps to Reproduce I have only tested this against an android emulator. import 'package:flutter/material.dart'; void main() { runApp( new MaterialApp( title: 'Flutter Demo', theme: ...

github.com

 

 

Container(
  decoration: BoxDecoration(
    color: Colors.blue,
    borderRadius: BorderRadius.circular(24.0),
  ),
  child: InkWell(
    onTap: () {
      print("onTap");
    },
    borderRadius: BorderRadius.circular(24.0),
    child: Container(
      width: 200.0,
      height: 100.0,
    ),
  ),
)

문제 해결

Container(
  decoration: BoxDecoration(
    color: Colors.blue,
    borderRadius: BorderRadius.circular(24.0),
  ),
  child: Material( // 추가
    child: InkWell(
      borderRadius: BorderRadius.circular(24.0),
      onTap: () {
        print("onTap");
      },
      child: Container(
        width: 200.0,
        height: 100.0,
      ),
    ),
    color: Colors.transparent, // 추가
  ),
)

위와 같이 InkWell 상위 위젯으로 Material을 추가하고 color를 transparent로 만들어주면 ripple 효과가 정상적으로 작동하였습니다.

 

 

References

https://api.flutter.dev/flutter/material/InkWell-class.html

 

InkWell class - material library - Dart API

A rectangular area of a Material that responds to touch. For a variant of this widget that does not clip splashes, see InkResponse. The following diagram shows how an InkWell looks when tapped, when using default values. The InkWell widget must have a Mate

api.flutter.dev

반응형
'Flutter/Error and Tips' 카테고리의 다른 글
  • [Flutter/Error] build()안에 variable 넣으면 안되는 이유 (setState does not update UI)
seunghwaan
seunghwaan
공부한 내용을 정리하는 개발 기록 블로그
    반응형
  • seunghwaan
    SH's Devlog
    seunghwaan
  • 전체
    오늘
    어제
    • 분류 전체보기 (150)
      • Android (62)
        • Basic (17)
        • Kotlin(Java) (14)
        • UI & Animation (1)
        • Compose (2)
        • Coroutines (1)
        • Dependency Injection (6)
        • RxJava (8)
        • BLE (3)
        • TDD (2)
        • JetPack (1)
        • NextStep (4)
        • Error Log (3)
      • Flutter (14)
        • Basic (5)
        • Dart (1)
        • State Management (2)
        • Widgets (4)
        • Error and Tips (2)
      • iOS (8)
        • Basic (0)
        • Swift (8)
      • Web Frontend (6)
        • Basic (0)
        • JavaScript (5)
        • TypeScript (0)
        • React (1)
      • CS(Computer Science) (18)
        • Network (4)
        • Database (10)
        • Design Pattern (1)
        • Computer Architecture (3)
        • Operating System (0)
      • Cloud (6)
        • AWS (6)
      • DevOps (25)
        • GIT (4)
        • CI CD (8)
        • Linux (4)
        • Docker (9)
        • Error Log (0)
      • 코딩테스트 (10)
        • DB (6)
        • 알고리즘 (4)
      • Backend (1)
        • Spring (1)
      • Mac Tip (0)
      • Language (0)
        • English (0)
        • Japanese (0)
      • Temporary (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    CICD
    FLUTTER
    Kotlin
    RxJava
    Android
    di
    컴퓨터공학
    Algorithm
    AWS
    error
    Dependency Injection
    Linux
    CI
    MySQL
    database
    docker
    Computer Science
    Dagger
    gradle
    BLE
    Swift
    cs
    시작하세요! 도커
    IOS
    JavaScript
    네트워크
    cognito
    Jenkins
    상태 관리
    Network
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.6
seunghwaan
[Flutter] InkWell 물결효과가 동작하지 않는 문제해결법(InkWell not showing ripple effect)
상단으로

티스토리툴바