일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- jsp
- 건담베이스
- Spring
- html
- 単語
- メソッド
- ruby
- 인프런
- springboot
- 자바
- rails
- rails7
- javascript
- 연습문제
- 건담
- 日本語
- 일본어
- vscode
- Python
- 一日一つメソッド
- CSS
- 비즈니스일본어
- 디지몬
- DART
- 반다이몰
- Web
- java
- nico
- C로 시작하는 컴퓨터 프로그래밍4판
- Flutter
Archives
- Today
- Total
AR삽질러
Flutter Reusable Cards - (6) 본문
728x90
Flutter Reusable Cards
재사용가능한 위젯
const CurrencyCard(
name: 'Euro',
code: 'EUR',
amount: '6 428',
icon: Icons.euro_rounded,
isInberted: false,
),
Transform.translate(
offset: const Offset(0, -20),
child: const CurrencyCard(
name: 'Bitcoin',
code: 'BTC',
amount: '9 785',
icon: Icons.currency_bitcoin,
isInberted: true,
),
),
Transform.translate(
offset: const Offset(0, -40),
child: const CurrencyCard(
name: 'Dollar',
code: 'USD',
amount: '428',
icon: Icons.attach_money_rounded,
isInberted: false,
),
),
],
),
),
),
),
);
}
}
CurrencyCard Wedget : 화폐 카드를 만들고 이름, 코드, 금액, 아이콘, 테마 등을 디자인한다.
name : 화폐이름
code : 화폐코드
amount : 화폐금액
icon : 화폐이미지
isInberted : 테마 토글로 true인경우 배경화면은 흰색, 글자와 아이콘은 검정색으로 설정하고 false인경우 반대로 설정된다.
Container Wedget
- 카드를 감싸는 컨테이너로 clopBehavior로 경계를 넘어가지 않도록 설정하고 배경색과 모서리를 정의한다.
Padding Wedget
- CurrentCard 내부의 모든 내용에 패딩을 적용한다.
Row Wedget
- 카드내의 요소를 가로로 정렬하여 화폐의 이름, 금액, 코드를 넣는다.
Column Wedget
- 내부의 텍스트요소를 세로로 정렬하여 이름과 금액 코드를 넣는다.
Text Wedget
- 이름, 금액 등 화폐코드를 표시하고 텍스트 스타일은 isInverted 값에 따라 테마를 변경한다.
Transform Wedget
- 아이콘을 배치, 크기와 위치를 조정
전체코드
main
import 'package:flutter/material.dart';
import 'package:toonflix/widgets/Button.dart';
import 'package:toonflix/widgets/currency_card.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: const Color(0xFF181818),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 27),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 60,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
const Text(
"Hey, Arang",
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.w800,
),
),
Text(
"Welcom back",
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 16,
),
),
],
)
],
),
const SizedBox(
height: 45,
),
Text(
"Total balance",
style: TextStyle(
fontSize: 22,
color: Colors.white.withOpacity(0.8),
),
),
const SizedBox(
height: 10,
),
const Text(
'\$5 194 482',
style: TextStyle(
fontSize: 46,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
const SizedBox(
height: 25,
),
const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Button(
text: 'Transfer',
bgColor: Color(0xFFF1B33B),
textColor: Colors.black),
Button(
text: 'Request',
bgColor: Color(0xFF1F2123),
textColor: Colors.white),
],
),
const SizedBox(
height: 50,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Wallets',
style: TextStyle(
color: Colors.white,
fontSize: 36,
fontWeight: FontWeight.w600,
),
),
Text(
'View All',
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 18,
),
),
],
),
const SizedBox(
height: 19,
),
const CurrencyCard(
name: 'Euro',
code: 'EUR',
amount: '6 428',
icon: Icons.euro_rounded,
isInberted: false,
),
Transform.translate(
offset: const Offset(0, -20),
child: const CurrencyCard(
name: 'Bitcoin',
code: 'BTC',
amount: '9 785',
icon: Icons.currency_bitcoin,
isInberted: true,
),
),
Transform.translate(
offset: const Offset(0, -40),
child: const CurrencyCard(
name: 'Dollar',
code: 'USD',
amount: '428',
icon: Icons.attach_money_rounded,
isInberted: false,
),
),
],
),
),
),
),
);
}
}
currency_card
import 'package:flutter/material.dart';
class CurrencyCard extends StatelessWidget {
final String name, code, amount;
final IconData icon;
final bool isInberted;
final _blackColor = const Color(0xFF1F2123);
const CurrencyCard({
super.key,
required this.name,
required this.code,
required this.amount,
required this.icon,
required this.isInberted,
});
@override
Widget build(BuildContext context) {
return Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
color: isInberted ? Colors.white : _blackColor,
borderRadius: BorderRadius.circular(25),
),
child: Padding(
padding: const EdgeInsets.all(28),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
name,
style: TextStyle(
color: isInberted ? _blackColor : Colors.white,
fontSize: 32,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
Row(
children: [
Text(
amount,
style: TextStyle(
color: isInberted ? _blackColor : Colors.white,
fontSize: 20,
),
),
const SizedBox(
width: 5,
),
Text(
code,
style: TextStyle(
color: isInberted ? _blackColor : Colors.white,
fontSize: 20,
),
),
],
),
],
),
Transform.scale(
scale: 2.2,
child: Transform.translate(
offset: const Offset(
-5,
12,
),
child: Icon(
icon,
color: isInberted ? _blackColor : Colors.white,
size: 88,
),
),
)
],
),
),
);
}
}
button
import 'package:flutter/widgets.dart';
class Button extends StatelessWidget {
final String text;
final Color bgColor;
final Color textColor;
const Button({
Key? key,
required this.text,
required this.bgColor,
required this.textColor,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: bgColor, borderRadius: BorderRadius.circular(45)),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 18,
horizontal: 45,
),
child: Text(
text,
style: TextStyle(
color: textColor,
fontSize: 20,
),
),
),
);
}
}
https://github.com/designAR/Flutter_UI_Challenge1
728x90
반응형
LIST
'Dart > Flutter' 카테고리의 다른 글
Flutter 기초 - MaterialApp, Scaffold (10) (0) | 2024.05.16 |
---|---|
Flutter 기초 - Hot restart, Hot reload (9) (1) | 2024.05.15 |
Flutter Cards - (5) (0) | 2023.09.19 |
Flutter Reusable Widgets - (4) (0) | 2023.09.17 |
Flutter VSCode설정 (0) | 2023.09.17 |