[Flutter] BoxShadow으로 심플한 UI 만들기
다음 예제에서는 3개의 Container 위젯이 있는 Flutter 애플리케이션을 만듭니다. 이러한 Container 위젯은 각각 다른 Box 그림자 속성으로 설정됩니다. 두 번째 Container 위젯에 적용한 것처럼 여러 Box 그림자를 적용할 수도 있습니다.
main.dart
import 'package:flutter/material.dart';void main() => runApp(const MyApp());class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); static const String _title = 'Flutter Tutorial'; @override Widget build(BuildContext context) { return MaterialApp( title: _title, home: Scaffold( appBar: AppBar(title: const Text(_title)), body: const MyStatefulWidget(), ), ); }}class MyStatefulWidget extends StatefulWidget { const MyStatefulWidget({Key? key}) : super(key: key); @override State<MyStatefulWidget> createState() => _MyStatefulWidgetState();}class _MyStatefulWidgetState extends State<MyStatefulWidget> { @override Widget build(BuildContext context) { return Center( child: Column( children: <Widget>[ const SizedBox(height: 20,), Container( height: 150, width: 150, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), boxShadow: const [ BoxShadow( color: Colors.grey, blurRadius: 5, spreadRadius: 1, offset: Offset(4, 4) ), ], color: Colors.green[200], ), child: const Text('Container 1'), ), const SizedBox(height: 20,), Container( height: 150, width: 150, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), boxShadow: const [ BoxShadow( color: Colors.blue, blurRadius: 3, spreadRadius: 5, offset: Offset(0, 0) ), BoxShadow( color: Colors.red, blurRadius: 5, spreadRadius: 1, offset: Offset(5, 5) ), ], color: Colors.green[200], ), child: const Text('Container 2'), ), const SizedBox(height: 20,), Container( height: 150, width: 150, alignment: Alignment.center, decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), boxShadow: const [ BoxShadow( color: Colors.deepPurpleAccent, blurRadius: 10, spreadRadius: 0, offset: Offset(0, 0) ), ], color: Colors.green[200], ), child: const Text('Container 3'), ), ] ), ); }} |
스크린샷 [안드로이드 에뮬레이터, ios 시뮬레이터]
![[Flutter] BoxShadow으로 심플한 UI 만들기 [Flutter] BoxShadow으로 심플한 UI 만들기](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-RR6U07W8Glw4fACIJKJ6FNGyfnVgI6GCdq2xOgZI49Ff4MZGZM5SJlCPwTlNzv4EuFZyW2EPtyApRnQLHwG5lR2iRCNW9iq98WRFbGqQrl51xHRIpEYik7hiGErzfz89o4LVlF_I5rIy5Kgls-ENbejwTPURnBtxd2GGLVbRSQnxH9h240vhBpyh/s16000/imgonline-com-ua-twotoone-61C4MZCp5UDmjn.jpg)
댓글
댓글 쓰기