전자 액자
Last updated
Last updated
import 'package:flutter/material.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageView(
children: [1, 2, 3, 4, 5]
.map((e) => Image.asset('asset/img/img_$e.jpg', fit: BoxFit.cover))
.toList(),
),
);
}
}
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
Timer? timer;
PageController controller = PageController(
initialPage: 0,
);
@override
void initState() {
super.initState();
timer = Timer.periodic(Duration(seconds: 4), (timer) {
int currentPage = controller.page!.toInt();
int nextPage = currentPage + 1;
if (nextPage > 4) {
nextPage = 0;
}
controller.animateToPage(
nextPage,
duration: Duration(microseconds: 400),
curve: Curves.linear,
);
});
}
@override
void dispose() {
controller.dispose();
if (timer != null) {
timer!.cancel();
}
super.dispose();
}
@override
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
return Scaffold(
body: PageView(
controller: controller,
children: [1, 2, 3, 4, 5]
.map((e) => Image.asset('asset/img/img_$e.jpg', fit: BoxFit.cover))
.toList(),
),
);
}
}