class Page3 extends StatefulWidget {
const Page3({Key? key}) : super(key: key);
@override
_Page3State createState() => _Page3State();
}
class _Page3State extends State<Page3> {
List<dynamic> imgList = [
'https://images.unsplash.com/photo-1522205408450-add114ad53fe?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=368f45b0888aeb0b7b08e3a1084d3ede&auto=format&fit=crop&w=1950&q=80',
'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80',
'https://images.unsplash.com/photo-1508704019882-f9cf40e475b4?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8c6e5e3aba713b17aa1fe71ab4f0ae5b&auto=format&fit=crop&w=1352&q=80',
'https://images.unsplash.com/photo-1519985176271-adb1088fa94c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a0c8d632e977f94e5d312d9893258f59&auto=format&fit=crop&w=1355&q=80',
];
final CarouselController _controller = CarouselController();
int _current = 0;
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: Scaffold(
body: SafeArea(
child: Column(
children: [
Padding(padding: const EdgeInsets.only(top: 20)),
PanelImage(), // 배너 추가
Decoration_Box // 배너아래 이미지 리스트
],
),
),
),
);
}
Widget Decoration_Box() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: imgList.asMap().entries.map((entry) {
return GestureDetector(
onTap: () => _controller.animateToPage(entry.key),
child: Container(
width: 8.0,
height: 8.0,
margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 4.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context)
.textTheme
.headline1
?.color!
.withOpacity(_current == entry.key ? 0.9 : 0.4)),
),
);
}).toList(),
);
}
Widget PanelImage() {
return Container(
width: MediaQuery.of(context).size.width,
height: 250,
child: CarouselSlider(
carouselController: _controller,
options: CarouselOptions(
autoPlay: true,
viewportFraction: 2.0,
enlargeCenterPage: true,
scrollDirection: Axis.horizontal,
initialPage: 0,
onPageChanged: (index, reason) {
setState(() {
_current = index;
});
}),
items: imgList
.map((item) => Container(
child: Center(
child: OptimizedCacheImage(
imageUrl: item,
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
placeholder: (context, url) => Container(
child: Center(
child: CupertinoActivityIndicator(
radius: 25,
),
),
)))))
.toList(),
),
);
}
}
결과
'study > flutter' 카테고리의 다른 글
플러터(flutter) GestureDetector 이벤트 및 Navigator (0) | 2021.09.24 |
---|---|
플러터(flutter) 버튼 클릭시 진동 (0) | 2021.09.24 |
플러터(flutter) Android FCM 백그라운드, 포그라운드 알림 (0) | 2021.09.17 |
7. 플러터(flutter) Hot Reload (0) | 2021.09.05 |
6. 플러터(flutter) 에뮬레이터로 프로젝트 실행하기 (0) | 2021.09.05 |