mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Improve notifications list UX with auto-refresh and friendly timestamps
- Show "Just now" for notifications 2 minutes old or less - Auto-refresh the list every minute, preserving the active filter Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
f34dfe8386
commit
4f5a228aec
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||||
|
|
||||||
@@ -14,6 +16,16 @@ class NotificationList extends StatefulWidget {
|
|||||||
|
|
||||||
class _NotificationListState extends State<NotificationList> {
|
class _NotificationListState extends State<NotificationList> {
|
||||||
int _filterChoice = 1; // 1 => Only new, 2=> Only old, 3=> All
|
int _filterChoice = 1; // 1 => Only new, 2=> Only old, 3=> All
|
||||||
|
Timer? _refreshTimer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_refreshTimer = Timer.periodic(
|
||||||
|
const Duration(minutes: 1),
|
||||||
|
(_) => _pagingController.refresh(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
late final _pagingController = PagingController<int, oott_model.Notification>(
|
late final _pagingController = PagingController<int, oott_model.Notification>(
|
||||||
getNextPageKey: (state) => state.lastPageIsEmpty
|
getNextPageKey: (state) => state.lastPageIsEmpty
|
||||||
@@ -262,6 +274,7 @@ class _NotificationListState extends State<NotificationList> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_refreshTimer?.cancel();
|
||||||
_pagingController.dispose();
|
_pagingController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class FriendlyDateFormatter {
|
|||||||
dateTime.day,
|
dateTime.day,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (timeSince.inMinutes <= 2) return 'Just now';
|
||||||
if (timeSince.inMinutes < 60) return '${timeSince.inMinutes} minutes ago';
|
if (timeSince.inMinutes < 60) return '${timeSince.inMinutes} minutes ago';
|
||||||
if (dateTimeWithoutTime == today) {
|
if (dateTimeWithoutTime == today) {
|
||||||
return 'Today at ${DateFormat.Hm().format(dateTime)}';
|
return 'Today at ${DateFormat.Hm().format(dateTime)}';
|
||||||
|
|||||||
Reference in New Issue
Block a user