-
Notifications
You must be signed in to change notification settings - Fork 0
feat: custom button #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,123 @@ | ||||||
| import 'package:flutter/material.dart'; | ||||||
|
|
||||||
| void main() { | ||||||
| runApp(const MyApp()); | ||||||
| } | ||||||
|
|
||||||
| const Color lightPrimaryColor = Color(0xFF6C98FF); | ||||||
| const Color lightSecondaryColor = Color(0xFF87A9F7); | ||||||
|
|
||||||
| const Color darkPrimaryColor = Color(0xFF497BEE); | ||||||
| const Color darkSecondaryColor = Color(0xFF6C98FF); | ||||||
|
|
||||||
| const Color disabledColor = Color(0xFF808080); | ||||||
|
Comment on lines
+7
to
+13
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이미 |
||||||
|
|
||||||
| class MyApp extends StatelessWidget { | ||||||
| const MyApp({super.key}); | ||||||
|
|
||||||
| @override | ||||||
| Widget build(BuildContext context) { | ||||||
| return MaterialApp( | ||||||
| title: 'Button Variants Demo', | ||||||
| themeMode: ThemeMode.system, | ||||||
| theme: ThemeData( | ||||||
| useMaterial3: true, | ||||||
| brightness: Brightness.light, | ||||||
| colorScheme: ColorScheme.light( | ||||||
| primary: lightPrimaryColor, | ||||||
| secondary: lightSecondaryColor, | ||||||
| ), | ||||||
| ), | ||||||
| darkTheme: ThemeData( | ||||||
| useMaterial3: true, | ||||||
| brightness: Brightness.dark, | ||||||
| colorScheme: ColorScheme.dark( | ||||||
| primary: darkPrimaryColor, | ||||||
| secondary: darkSecondaryColor, | ||||||
| ), | ||||||
| ), | ||||||
|
Comment on lines
+23
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 또한, 위에서 언급드린 것처럼 |
||||||
| home: const ButtonDemoPage(), | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| class ButtonDemoPage extends StatelessWidget { | ||||||
| const ButtonDemoPage({super.key}); | ||||||
|
|
||||||
| @override | ||||||
| Widget build(BuildContext context) { | ||||||
| return Scaffold( | ||||||
| appBar: AppBar(title: const Text("Button Variants")), | ||||||
| body: Padding( | ||||||
| padding: const EdgeInsets.all(16.0), | ||||||
| child: Column( | ||||||
| children: const [ | ||||||
| CustomButton(variant: 'surface', disabled: false), | ||||||
| SizedBox(height: 10), | ||||||
| CustomButton(variant: 'surface', disabled: true), | ||||||
| SizedBox(height: 10), | ||||||
| CustomButton(variant: 'outline', disabled: false), | ||||||
| SizedBox(height: 10), | ||||||
| CustomButton(variant: 'outline', disabled: true), | ||||||
| ], | ||||||
| ), | ||||||
| ), | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
Comment on lines
+44
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 데모는 지워주세요 |
||||||
|
|
||||||
| class CustomButton extends StatelessWidget { | ||||||
| final String variant; | ||||||
| final bool disabled; | ||||||
|
|
||||||
| const CustomButton({ | ||||||
| super.key, | ||||||
| required this.variant, | ||||||
| required this.disabled, | ||||||
| }); | ||||||
|
|
||||||
| @override | ||||||
| Widget build(BuildContext context) { | ||||||
| final bool isOutline = variant == 'outline'; | ||||||
| final colorScheme = Theme.of(context).colorScheme; | ||||||
| final Color primary = colorScheme.primary; | ||||||
|
Comment on lines
+82
to
+83
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것 또한 별도로 구현해 놓은 |
||||||
|
|
||||||
| return SizedBox( | ||||||
| width: 120, | ||||||
| height: 34, | ||||||
|
Comment on lines
+86
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. text에 따라 위젯의 크기가 동적으로 변할 수 있습니다. SizedBox를 제거해주세요 |
||||||
| child: ElevatedButton( | ||||||
| onPressed: disabled ? null : () {}, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. onTap을 property로 넘길 수 있게 해주세요 |
||||||
| style: ButtonStyle( | ||||||
| backgroundColor: WidgetStateProperty.resolveWith<Color>((states) { | ||||||
| if (states.contains(WidgetState.disabled)) { | ||||||
| return isOutline ? Colors.white : disabledColor; | ||||||
| } | ||||||
| return isOutline ? Colors.white : primary; | ||||||
| }), | ||||||
|
Comment on lines
+89
to
+96
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위젯의 disabled 값과 WidgetState.disabled가 혼용되는 것 같아요 코드 전체에서 |
||||||
| foregroundColor: WidgetStateProperty.resolveWith<Color>((states) { | ||||||
| if (states.contains(WidgetState.disabled)) { | ||||||
| return isOutline ? disabledColor : Colors.white; | ||||||
| } | ||||||
| return isOutline ? primary : Colors.white; | ||||||
| }), | ||||||
| side: WidgetStateProperty.resolveWith<BorderSide>((states) { | ||||||
| if (!isOutline) return BorderSide.none; | ||||||
| return BorderSide( | ||||||
| color: states.contains(WidgetState.disabled) | ||||||
| ? disabledColor | ||||||
| : primary, | ||||||
| ); | ||||||
| }), | ||||||
| padding: WidgetStateProperty.all( | ||||||
| const EdgeInsets.symmetric(vertical: 8, horizontal: 12), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 피그마와 동일하게 |
||||||
| ), | ||||||
| elevation: WidgetStateProperty.all(0), | ||||||
| shape: WidgetStateProperty.all( | ||||||
| RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
피그마와 동일하게 맞춰주세요 |
||||||
| ), | ||||||
| ), | ||||||
| child: const Text('Button', style: TextStyle(fontSize: 12)), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. text를 property로 넘길 수 있게 해주세요 |
||||||
| ), | ||||||
| ); | ||||||
|
Comment on lines
+85
to
+121
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 실행 화면 스크린샷 올려주세요 |
||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preview화면을 요청한 것이 아닌, 컴포넌트만 정의된 파일을 의미했습니다. 작동 확인할 수 있는 화면은 제거해 주시고 본 파일에는 컴포넌트 관련 코드만 남겨주세요.