색만 지정한 Container 대신 ColoredBox를 쓰세요
색만 지정한 Container 대신 ColoredBox를 쓰세요 (use_colored_box)
color만 설정한 Container를 만들 때 분석기가 권장하는 린트 규칙이에요. 색만 필요하다면 더 가벼운 ColoredBox를 쓰는 게 낫습니다.
출처: use_colored_box
본문
설명
분석기는 color만 설정하는 Container가 만들어질 때 이 진단을 냅니다.
예시
다음 코드는 컨테이너에서 설정된 속성이 color 하나뿐이라 이 진단이 발생해요.
import 'package:flutter/material.dart';
Widget build() {
return Container(color: Colors.red, child: const Text('hello'));
}
일반적인 해결 방법
Container를 ColoredBox로 바꿔 주면 됩니다.
import 'package:flutter/material.dart';
Widget build() {
return ColoredBox(color: Colors.red, child: const Text('hello'));
}