Transform.translate를 card안에서 설정가능하게 하자!
즉, 투명도를 컴포넌트의 맴버로 만들어라는거다
위젯에서
를 줘서
아래와 같이 만들었다.
import 'package:flutter/material.dart';
class CurrencyCard extends StatelessWidget {
final String name, code, amount;
final IconData icon;
final bool isInverted;
final double gap;
// const : 상수
// 검정색
// _ : private
final _blackColor = const Color(0xFF1F2123);
const CurrencyCard({
super.key,
required this.name,
required this.code,
required this.amount,
required this.icon,
required this.isInverted,
required this.gap,
});
Widget build(BuildContext context) {
return Transform.translate(
offset: Offset(0, gap),
child: Container(
// overflow 됐을때 어떻게 하는지 설정하는 ClipBehavior
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: isInverted ? Colors.white : _blackColor,
borderRadius: BorderRadius.circular(25),
),
child: Padding(
// padding
padding: const EdgeInsets.all(30),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(
name,
style: TextStyle(
color: isInverted ? _blackColor : Colors.white,
fontSize: 32,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 15,
),
Row(
children: [
Text(
amount,
style: TextStyle(
color: isInverted ? _blackColor : Colors.white,
fontSize: 20,
),
),
const SizedBox(
width: 5,
),
Text(code,
style: TextStyle(
color: isInverted
? _blackColor
: Colors.white.withOpacity(0.8),
fontSize: 20,
)),
],
)
]),
Transform.scale(
scale: 2.2,
child: Transform.translate(
offset: const Offset(-5, 12),
child: Icon(
icon,
color: isInverted ? _blackColor : Colors.white,
size: 88,
),
))
],
),
),
),
);
}
}
메인 - 카드 코드
const CurrencyCard(
name: "Euro",
code: "EUR",
amount: "6 428",
icon: Icons.euro_rounded,
isInverted: false,
gap: 0,
),
const CurrencyCard(
name: "Bitcoin",
code: "BTC",
amount: "9 785",
icon: Icons.currency_bitcoin_rounded,
isInverted: true,
gap: -20,
),
const CurrencyCard(
name: "Dollar",
code: "USD",
amount: "428",
icon: Icons.attach_money_outlined,
isInverted: false,
gap: -40,
),