diff --git a/README.md b/README.md index 5f3e57e..3dc7817 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,51 @@ A few resources to get you started if this is your first Flutter project: For help getting started with Flutter, view our [online documentation](https://flutter.dev/docs), which offers tutorials, samples, guidance on mobile development, and a full API reference. + + +# ๐Ÿš€ 1๋‹จ๊ณ„ - buildMethod๋ฅผ Widget์œผ๋กœ ๋ถ„๋ฆฌํ•˜๊ธฐ + +### ์š”๊ตฌ์‚ฌํ•ญ +- [ ] buildMethod๋กœ ๊ตฌํ˜„๋œ ์ฝ”๋“œ๋“ค์„ Widget์œผ๋กœ ๊ตฌํ˜„ + - [x] ๊ฐ€๊ฒŒ๋ช… ์œ„์ ฏ + - [x] ์ƒ์„ฑ์ž๋กœ ๊ฐ€๊ฒŒ๋ช…์„ ์ฃผ์ž… ๋ฐ›๋Š”๋‹ค. + - [x] ์ƒํ’ˆ ์œ„์ ฏ + - [x] ์ƒ์„ฑ์ž๋กœ ์ƒํ’ˆ๋ช…(๋ฉ”๋‰ด๋ช…)์„ ์ฃผ์ž… ๋ฐ›๋Š”๋‹ค. + - [x] ์ƒ์„ฑ์ž๋กœ ์ƒํ’ˆ์„ค๋ช…์„ ์ฃผ์ž… ๋ฐ›๋Š”๋‹ค. + - [x] ์ƒ์„ฑ์ž๋กœ ๊ฐ€๊ฒฉ์„ ์ฃผ์ž… ๋ฐ›๋Š”๋‹ค. + - [x] ๋” ๋‹ด์œผ๋Ÿฌ ๊ฐ€๊ธฐ ๋ฒ„ํŠผ + - [x] ๊ฒฐ์ œ ๊ธˆ์•ก ์œ„์ ฏ + - [x] ๊ฒฐ์ œํ•˜๊ธฐ ๋ฒ„ํŠผ +- [x] Stateless Widget์œผ๋กœ ๊ตฌํ˜„ +- [x] ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑ์ž๋กœ ์ „๋‹ฌ ๋ฐ›์•„์„œ ๋‹ค๋ฅธ ์Œ์‹์ , ๋‹ค๋ฅธ ๋ฉ”๋‰ด๋„ ํ‘œ์‹œํ•  ์ˆ˜ ์žˆ๋„๋ก ์ˆ˜์ • +- [x] class ๋„ค์ด๋ฐ์€ ์ž์œ ๋กญ๊ฒŒ ํ•˜๋˜, ์˜๋ฏธ ํŒŒ์•…์ด ๋ช…ํ™•ํ•˜๋„๋ก ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. + + + +### note +- Dart + - DO name libraries, packages, directories, and source files using lowercase_with_underscores. + - ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ, ํŒจํ‚ค์ง€, ๋””๋ ‰ํ† ๋ฆฌ, ์†Œ์ŠคํŒŒ์ผ์€ ์†Œ๋ฌธ์ž์™€ ์–ธ๋”์Šค์ฝ”์–ด๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. [๋งํฌ](https://dart.dev/guides/language/effective-dart/style#do-name-libraries-and-source-files-using-lowercase_with_underscores) + - snake case ๋ผ๋Š” ํ‘œํ˜„์„ ์•ˆ์“ฐ๋„ค..? +- Flutter + - ํ”Œ๋Ÿฌํ„ฐ ์œ„์ ฏ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋ฐ˜๋“œ์‹œ ์ƒ๋‹จ์— ์œ„์ ฏ์„ import๋ฅผ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. `Dart != Flutter` + - `import 'package:flutter/material.dart';` + - `import 'package:flutter/cupertino.dart';` + - meterial, cupertino๋Š” ์œ„์ ฏ์„ ๊ด€๋ฆฌํ•˜๋Š” ํ…Œ๋งˆ? ๊ฐ™์€ ๊ฒƒ ๊ฐ™๋‹ค.. ๋ฉ€ํ‹ฐ ํ”Œ๋žซํผ์„ ์ง€์›ํ•˜๊ธฐ ์œ„ํ•œ. + - ๋งค๋ฒˆ import๋ฅผ ์ง์ ‘ ์ž…๋ ฅํ•ด์ค˜์•ผํ•˜๋Š” ๋ถˆํŽธํ•จ. + - Q. ๋‘ ๊ฐ€์ง€ import ๋ฐฉ์‹์˜ ์ฐจ์ด์ ์€? ๋ฉ€ํ‹ฐ ๋ชจ๋“ˆ์„ ํ™œ์šฉํ•œ ์™ธ๋ถ€ ํ”„๋กœ์ ํŠธ๋„ import ๊ฐ€๋Šฅ? + - `import 'package:cart_sample/component/button_add_more.dart';` + - `import 'component/button_add_more.dart.dart';` + - ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“œ๋‹ˆ key๋ฅผ ์ฃผ์ž…๋ฐ›๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๋ผ๋Š”๋ฐ Key๋Š” ์œ„์ ฏ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’์œผ๋กœ ํ™•์ธ. + - key๋ฅผ ์™œ ์‚ฌ์šฉํ•˜๋Š”์ง€, ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”์ง€ ๊ณต๋ถ€ํ•  ํ•„์š” ์žˆ์Œ! + - ํด๋ž˜์Šค ์ƒ์„ฑ์ž + - ์ž๋ฐ”์™€๋Š” ๋‹ค๋ฅด๊ฒŒ(?) ๋ฉค๋ฒ„ ๋ณ€์ˆ˜์— ํ• ๋‹นํ•˜๋Š” ๋กœ์ง์ด ์—†๋‹ค! + - ์ƒ์„ฑ์ž์—์„œ ์ธ์ž๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐ›๋„๋ก ์ •์˜๋œ ๊ฒฝ์šฐ ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ธ์ž๋ช…์„ ๋ช…์‹œํ•ด์ค˜์•ผ ํ•œ๋‹ค. + +### ํ”ผ๋“œ๋ฐฑ +- [x] ๊ธˆ์•ก, ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ ๋“ฑ ํ•˜๋“œ์ฝ”๋”ฉ์„ ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ์ฃผ์ž… ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ๋ณ€๊ฒฝ + - [x] ๊ฐ€๊ฒŒ๋ช…, ๊ฐ€๊ฒŒ ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ +- [x] ๋ณ€์ˆ˜๋ช… ์•ž์— `_`๋ฅผ ๋ถ™์—ฌ์„œ private ๋ณ€์ˆ˜๋กœ ์ •์˜ + - [x] ๊ฐ€๊ฒŒ๋ช…, ๊ฐ€๊ฒŒ ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ +- [x] ๋ฒ„ํŠผ์„ ์ƒ์†ํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ +- [x] ํŠน์ • ํด๋ž˜์Šค์—๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์ • (part, part of) \ No newline at end of file diff --git a/lib/cart_screen.dart b/lib/cart_screen.dart index 5b6fb25..988f17a 100644 --- a/lib/cart_screen.dart +++ b/lib/cart_screen.dart @@ -1,4 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +part 'component/button_billing.dart'; +part 'component/billing.dart'; +part 'component/button_add_more.dart'; +part 'component/store_name.dart'; +part 'component/menu.dart'; class CartScreen extends StatefulWidget { const CartScreen({Key? key}) : super(key: key); @@ -10,6 +17,8 @@ class CartScreen extends StatefulWidget { class _CartScreenState extends State { @override Widget build(BuildContext context) { + const billing = Billing(18000, 3000); + return Scaffold( backgroundColor: const Color.fromRGBO(246, 246, 246, 1.0), appBar: AppBar( @@ -30,16 +39,20 @@ class _CartScreenState extends State { SizedBox( height: 10, ), - _buildStoreName(), + StoreName('์น˜ํ‚จ ์ž ์‹ค์ ', 'images/chickenCartoonImage.jpg'), SizedBox( height: 1, ), - _buildMenu(), + Menu( + 'ํ›„๋ผ์ด๋“œ ์น˜ํ‚จ', + 'โ€ข ์ฐœ & ๋ฆฌ๋ทฐ ์•ฝ์† : ์ฐธ์—ฌ. ์„œ๋น„์Šค์Œ๋ฃŒ์ œ๊ณต', + '${billing.totalPrice()}์›', + ), SizedBox( height: 1, ), - _buildAddMore(), - _buildBilling(), + ButtonAddMore(), + billing, ], ), bottomNavigationBar: Container( @@ -51,44 +64,8 @@ class _CartScreenState extends State { horizontal: 20, vertical: 10, ), - child: ElevatedButton( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - width: 25, - height: 25, - decoration: BoxDecoration( - color: Colors.white, - shape: BoxShape.circle, - ), - child: Center( - child: Text( - '1', - style: TextStyle( - color: Color.fromRGBO(44, 191, 188, 1.0), - fontWeight: FontWeight.bold, - ), - ), - ), - ), - SizedBox( - width: 7, - ), - Text( - '21,000์› ๋ฐฐ๋‹ฌ ์ฃผ๋ฌธํ•˜๊ธฐ', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - Color.fromRGBO(44, 191, 188, 1.0), - ), - ), + child: ButtonBilling( + billing.totalPrice(), onPressed: () {}, ), ), @@ -96,221 +73,4 @@ class _CartScreenState extends State { ), ); } - - Widget _buildStoreName() { - return Container( - color: Colors.white, - height: 70, - child: Row( - children: [ - SizedBox( - width: 20, - ), - ClipRRect( - borderRadius: BorderRadius.circular(12), - child: Image.asset( - 'images/chickenCartoonImage.jpg', - width: 35, - height: 35, - ), - ), - SizedBox( - width: 10, - ), - Text( - '์น˜ํ‚จ ์ž ์‹ค์ ', - style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16), - ) - ], - ), - ); - } - - Widget _buildMenu() { - return Container( - color: Colors.white, - child: Column( - children: [ - Row( - children: [ - SizedBox( - width: 20, - ), - Text( - 'ํ›„๋ผ์ด๋“œ ์น˜ํ‚จ', - style: TextStyle( - fontSize: 17, - fontWeight: FontWeight.bold, - ), - ), - Spacer(), - IconButton( - icon: Icon( - Icons.close, - color: Colors.grey, - ), - onPressed: () {}, - ), - ], - ), - Row( - children: [ - SizedBox( - width: 20, - ), - Container( - decoration: BoxDecoration( - border: Border.all( - color: Colors.grey.withOpacity(0.3), - width: 1, - ), - borderRadius: BorderRadius.circular(12), - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(12), - child: Image.asset( - 'images/chicken.png', - width: 70, - height: 70, - fit: BoxFit.cover, - ), - ), - ), - SizedBox( - width: 10, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'โ€ข ์ฐœ & ๋ฆฌ๋ทฐ ์•ฝ์† : ์ฐธ์—ฌ. ์„œ๋น„์Šค์Œ๋ฃŒ์ œ๊ณต', - style: TextStyle( - color: Color.fromRGBO(125, 125, 125, 1.0), - ), - ), - Text('18,000์›'), - ], - ), - ], - ), - SizedBox( - height: 20, - ), - ], - ), - ); - } - - Widget _buildAddMore() { - return GestureDetector( - onTap: () {}, - child: Container( - decoration: BoxDecoration( - color: Colors.white, - border: Border( - bottom: BorderSide( - color: Colors.grey.withOpacity(0.3), - width: 2, - ), - ), - ), - height: 50, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon(Icons.add), - Text( - '๋” ๋‹ด์œผ๋Ÿฌ ๊ฐ€๊ธฐ', - style: TextStyle(fontSize: 17), - ), - ], - ), - ), - ); - } - - Widget _buildBilling() { - return Container( - decoration: BoxDecoration( - color: Colors.white, - border: Border( - bottom: BorderSide( - color: Colors.grey.withOpacity(0.3), - width: 2, - ), - ), - ), - child: Column( - children: [ - SizedBox( - height: 20, - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Row( - children: [ - Text('์ด ์ฃผ๋ฌธ๊ธˆ์•ก'), - Spacer(), - Text('18,000์›'), - ], - ), - ), - SizedBox( - height: 10, - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Row( - children: [ - Text( - '๋ฐฐํƒˆํŒ', - style: TextStyle( - fontSize: 16, - ), - ), - Spacer(), - Text( - '3,000์›', - style: TextStyle( - fontSize: 16, - ), - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.all(20), - child: Divider( - color: Colors.grey, - ), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: Row( - children: [ - Text( - '๊ฒฐ์ œ์˜ˆ์ •๊ธˆ์•ก', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - Spacer(), - Text( - '21,000์›', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - ], - ), - ), - SizedBox( - height: 20, - ), - ], - ), - ); - } } diff --git a/lib/component/billing.dart b/lib/component/billing.dart new file mode 100644 index 0000000..49caa9f --- /dev/null +++ b/lib/component/billing.dart @@ -0,0 +1,102 @@ +part of '../cart_screen.dart'; + +class Billing extends StatelessWidget { + static final _commaFormat = NumberFormat('#,###', 'ko_KR'); + + final int _menuPrice; + final int _deliveryPrice; + + const Billing(this._menuPrice, this._deliveryPrice, {Key? key}) + : super(key: key); + + + String totalPrice() { + return _commaFormat.format(_deliveryPrice + _menuPrice); + } + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + color: Colors.white, + border: Border( + bottom: BorderSide( + color: Colors.grey.withOpacity(0.3), + width: 2, + ), + ), + ), + child: Column( + children: [ + SizedBox( + height: 20, + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Row( + children: [ + Text('์ด ์ฃผ๋ฌธ๊ธˆ์•ก'), + Spacer(), + Text('${_commaFormat.format(_menuPrice)}์›'), + ], + ), + ), + SizedBox( + height: 10, + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Row( + children: [ + Text( + '๋ฐฐํƒˆํŒ', + style: TextStyle( + fontSize: 16, + ), + ), + Spacer(), + Text( + '${_commaFormat.format(_deliveryPrice)}์›', + style: TextStyle( + fontSize: 16, + ), + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.all(20), + child: Divider( + color: Colors.grey, + ), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: Row( + children: [ + Text( + '๊ฒฐ์ œ์˜ˆ์ •๊ธˆ์•ก', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Spacer(), + Text( + '${totalPrice()}์›', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + ], + ), + ), + SizedBox( + height: 20, + ), + ], + ), + ); + } +} diff --git a/lib/component/button_add_more.dart b/lib/component/button_add_more.dart new file mode 100644 index 0000000..b706702 --- /dev/null +++ b/lib/component/button_add_more.dart @@ -0,0 +1,34 @@ +part of '../cart_screen.dart'; + +class ButtonAddMore extends StatelessWidget { + const ButtonAddMore({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () {}, + child: Container( + decoration: BoxDecoration( + color: Colors.white, + border: Border( + bottom: BorderSide( + color: Colors.grey.withOpacity(0.3), + width: 2, + ), + ), + ), + height: 50, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon(Icons.add), + Text( + '๋” ๋‹ด์œผ๋Ÿฌ ๊ฐ€๊ธฐ', + style: TextStyle(fontSize: 17), + ), + ], + ), + ), + ); + } +} diff --git a/lib/component/button_billing.dart b/lib/component/button_billing.dart new file mode 100644 index 0000000..8322879 --- /dev/null +++ b/lib/component/button_billing.dart @@ -0,0 +1,61 @@ +part of '../cart_screen.dart'; + +class ButtonBilling extends StatelessWidget { + final String _price; + final VoidCallback? onPressed; + + const ButtonBilling(this._price, {Key? key, required this.onPressed}) + : super(key: key); + + ButtonStyle _buttonStyle() { + return ButtonStyle( + backgroundColor: MaterialStateProperty.all( + Color.fromRGBO(44, 191, 188, 1.0), + ), + ); + } + + Row _children() { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 25, + height: 25, + decoration: BoxDecoration( + color: Colors.white, + shape: BoxShape.circle, + ), + child: Center( + child: Text( + '1', + style: TextStyle( + color: Color.fromRGBO(44, 191, 188, 1.0), + fontWeight: FontWeight.bold, + ), + ), + ), + ), + SizedBox( + width: 7, + ), + Text( + '$_price์› ๋ฐฐ๋‹ฌ ์ฃผ๋ฌธํ•˜๊ธฐ', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + ], + ); + } + + @override + Widget build(BuildContext context) { + return ElevatedButton( + child: _children(), + style: _buttonStyle(), + onPressed: onPressed, + ); + } +} diff --git a/lib/component/menu.dart b/lib/component/menu.dart new file mode 100644 index 0000000..c6b51db --- /dev/null +++ b/lib/component/menu.dart @@ -0,0 +1,86 @@ +part of '../cart_screen.dart'; + +class Menu extends StatelessWidget { + final String _name; + final String _description; + final String _price; + + const Menu(this._name, this._description, this._price, {Key? key}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + child: Column( + children: [ + Row( + children: [ + SizedBox( + width: 20, + ), + Text( + _name, + style: TextStyle( + fontSize: 17, + fontWeight: FontWeight.bold, + ), + ), + Spacer(), + IconButton( + icon: Icon( + Icons.close, + color: Colors.grey, + ), + onPressed: () {}, + ), + ], + ), + Row( + children: [ + SizedBox( + width: 20, + ), + Container( + decoration: BoxDecoration( + border: Border.all( + color: Colors.grey.withOpacity(0.3), + width: 1, + ), + borderRadius: BorderRadius.circular(12), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.asset( + 'images/chicken.png', + width: 70, + height: 70, + fit: BoxFit.cover, + ), + ), + ), + SizedBox( + width: 10, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + _description, + style: TextStyle( + color: Color.fromRGBO(125, 125, 125, 1.0), + ), + ), + Text(_price), + ], + ), + ], + ), + SizedBox( + height: 20, + ), + ], + ), + ); + } +} diff --git a/lib/component/store_name.dart b/lib/component/store_name.dart new file mode 100644 index 0000000..0083b18 --- /dev/null +++ b/lib/component/store_name.dart @@ -0,0 +1,40 @@ +part of '../cart_screen.dart'; + +class StoreName extends StatelessWidget { + + final String _name; + final String _imagePath; + + const StoreName(this._name, this._imagePath, {Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.white, + height: 70, + child: Row( + children: [ + SizedBox( + width: 20, + ), + ClipRRect( + borderRadius: BorderRadius.circular(12), + child: Image.asset( + _imagePath, + width: 35, + height: 35, + ), + ), + SizedBox( + width: 10, + ), + Text( + _name, + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16), + ) + ], + ), + ); + } + +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index c6a0a39..e782a3d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 + intl: ^0.17.0 dev_dependencies: