Open skykkm0810 opened 2 years ago
필수요소가 텍스트, 함수 / 불필요 요소 색 (배경 +글 )
class NormalBtn extends StatelessWidget {
const NormalBtn({Key? key, required this.texts,required this.callback, this.background = Colors.lightBlue, this.color = Colors.white }) : super(key: key);
final String texts;
final VoidCallback callback;
final Color background;
final Color color;
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: callback,
style: ElevatedButton.styleFrom(
primary: background,
onPrimary: color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
minimumSize: const Size.fromHeight(40),
textStyle: const TextStyle(fontSize: 20 ,fontWeight: FontWeight.bold),
),
child: Text(texts));
}
}
필수요소는 required , 불필요는 final 선언 후 , required 없이 적고 기본값 적용.
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key);
void _testFunction() => print('test'); static const String _title = 'Flutter Code Sample';
@override Widget build(BuildContext context) { return MaterialApp( title: _title, home: Scaffold( appBar: AppBar(title: const Text(_title)), body: Center( child: StickyBtn(texts: '로그인하기', callback: _testFunction ), ), )); } }
import 'package:flutter/material.dart';
class StickyBtn extends StatelessWidget {
const StickyBtn({Key? key, required this.texts,required this.callback}) : super(key: key); final String texts; final VoidCallback callback;
testFunction() => print('test');
@override Widget build(BuildContext context) { return ElevatedButton(onPressed: callback, child: Text(texts)); } }