Add todos admin and 30s refresh
This commit is contained in:
@@ -13,7 +13,8 @@ class AnnouncementWidget extends StatefulWidget {
|
||||
|
||||
class _AnnouncementWidgetState extends State<AnnouncementWidget> {
|
||||
final PageController _pageController = PageController();
|
||||
Timer? _timer;
|
||||
Timer? _scrollTimer;
|
||||
Timer? _refreshTimer;
|
||||
int _currentPage = 0;
|
||||
List<Announcement> _announcements = [];
|
||||
|
||||
@@ -21,6 +22,13 @@ class _AnnouncementWidgetState extends State<AnnouncementWidget> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchAnnouncements();
|
||||
_startAutoRefresh();
|
||||
}
|
||||
|
||||
void _startAutoRefresh() {
|
||||
_refreshTimer = Timer.periodic(const Duration(seconds: 30), (timer) {
|
||||
_fetchAnnouncements();
|
||||
});
|
||||
}
|
||||
|
||||
void _fetchAnnouncements() async {
|
||||
@@ -41,9 +49,9 @@ class _AnnouncementWidgetState extends State<AnnouncementWidget> {
|
||||
}
|
||||
|
||||
void _startAutoScroll() {
|
||||
_timer?.cancel();
|
||||
_scrollTimer?.cancel();
|
||||
if (_announcements.length > 1) {
|
||||
_timer = Timer.periodic(const Duration(seconds: 10), (timer) {
|
||||
_scrollTimer = Timer.periodic(const Duration(seconds: 10), (timer) {
|
||||
if (_pageController.hasClients) {
|
||||
_currentPage++;
|
||||
if (_currentPage >= _announcements.length) {
|
||||
@@ -61,7 +69,8 @@ class _AnnouncementWidgetState extends State<AnnouncementWidget> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
_scrollTimer?.cancel();
|
||||
_refreshTimer?.cancel();
|
||||
_pageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user