728x90
커스텀 위젯 만들 때 warning이 뜨는데
그것을 해결하기 위해 정리해본다
1. 생성자함수를 만들어줘야 한다
2. 메모리 할당할 때 재사용성을 위해서 const로 선언해준다
3. 커스텀 위젯이 const이기 때문에 사용할 때 제일 바깥쪽에도 const를 선언해준다
import 'package:flutter/material.dart';
void main() {
runApp(
const MaterialApp(
home: Scaffold(
backgroundColor: Colors.red,
body: GradientContainer(),
),
),
);
}
class GradientContainer extends StatelessWidget {
const GradientContainer({super.key});
@override
Widget build(context) {
return Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.red],
begin: Alignment.topLeft,
end: Alignment.bottomRight)),
child: const Center(
child: Text(
'Hello World!',
style: TextStyle(fontSize: 28, color: Colors.white),
),
),
);
}
}
'Flutter' 카테고리의 다른 글
flutter) 변수 할당하여 사용해보기 (0) | 2024.02.11 |
---|---|
flutter) 커스텀 위젯을 파일로 분리해서 import하기 (1) | 2024.02.11 |
flutter) 위젯을 분리해보자 (0) | 2024.02.10 |
flutter) graident 원하는 방향으로 효과주기 (0) | 2024.02.10 |
flutter) Container 사용하여 gradient 먹이기 (0) | 2024.02.10 |