개발/Flutter

[플러터] Container에 배경 이미지 넣는 방법 2가지

밍(Ming) 🐈‍⬛ 2023. 5. 25. 14:44
728x90
반응형

 

 

container를 색으로 채우는 것이 아니라 이미지로 넣어야 할 경우도 있다.

이때, 간단하게~ 두 가지 정도의 방법이 있다!

 

 

1. src 이미지 주소를 쓸 때

   Container(
        width: 155.0.w,
        decoration: BoxDecoration(
            image: DecorationImage(
                image: NetworkImage( src ),
                fit: BoxFit.cover
              ),
           ),
    )

 

 

 

 

2. image assets 을 쓸 때

   Container(
        width: 155.0.w,
        decoration: BoxDecoration(
            image: DecorationImage(
                image: AssetImage('/assets/image.png'),
                fit: BoxFit.cover
              ),
           ),
    )

 

 

 

이미지 주소를 어떻게 가져오냐에 따라서 위의 방법으로 사용하면 된다. 

 

 

 

 

 

 

 

 

728x90