개요
플러터 개발 시 LinearGradient 위젯을 사용하는 예제, 반투명하게 사용하는 예제 코드입니다.
소스 코드
Container(
height: 200,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
ColorStyle.black,
ColorStyle.white,
])),
),
아래와 같이 일부를 투명하게 만들 수도 있습니다.
Container(
height: 200,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
ColorStyle.black.withOpacity(0.6),
ColorStyle.black50.withOpacity(0),
])),
),
세 개 이상으로도 설정 가능합니다.
Container(
height: 200,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
ColorStyle.black50.withOpacity(0.8),
ColorStyle.black50.withOpacity(0.4),
ColorStyle.black.withOpacity(0.6),
ColorStyle.black50.withOpacity(0),
])),
),
참고 자료
https://copyprogramming.com/howto/apply-opacity-to-gradient-colors-in-flutter
'크로스 플랫폼 > Flutter <Dart>' 카테고리의 다른 글
[flutter] BuildContext 그리고 ScaffoldState.of() 에 대한 이해 (1) | 2024.01.06 |
---|---|
[flutter] android minSdkVersion 변경하기 (flutter sdk 3.13) (1) | 2024.01.03 |
[Flutter] URI.https type 'int' is not a subtype of type 'Iterable<dynamic>' 에러 해결 (1) | 2023.12.17 |
[Flutter] bottomNavigationBar svg 커스텀 아이콘 selectedIconTheme 적용하기 (0) | 2023.12.16 |
[Dart] Effective Dart 스타일 가이드 요약 (0) | 2023.10.12 |