🐛 Bug fixes on notifications
This commit is contained in:
parent
ebeffbe1aa
commit
aa17a5d52a
@ -53,6 +53,7 @@ class NotificationProvider extends GetxController {
|
|||||||
List<int> markList = List.empty(growable: true);
|
List<int> markList = List.empty(growable: true);
|
||||||
for (final element in nty.notifications) {
|
for (final element in nty.notifications) {
|
||||||
if (element.id <= 0) continue;
|
if (element.id <= 0) continue;
|
||||||
|
if (element.readAt != null) continue;
|
||||||
markList.add(element.id);
|
markList.add(element.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +76,8 @@ class NotificationProvider extends GetxController {
|
|||||||
if (element.id <= 0) {
|
if (element.id <= 0) {
|
||||||
nty.notifications.removeAt(index);
|
nty.notifications.removeAt(index);
|
||||||
return;
|
return;
|
||||||
|
} else if (element.readAt != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isBusy.value = true;
|
isBusy.value = true;
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:solian/providers/notifications.dart';
|
import 'package:solian/providers/notifications.dart';
|
||||||
import 'package:solian/providers/auth.dart';
|
|
||||||
import 'package:solian/models/notification.dart' as notify;
|
|
||||||
import 'package:solian/widgets/loading_indicator.dart';
|
import 'package:solian/widgets/loading_indicator.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
@ -14,54 +12,6 @@ class NotificationScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _NotificationScreenState extends State<NotificationScreen> {
|
class _NotificationScreenState extends State<NotificationScreen> {
|
||||||
bool _isBusy = false;
|
|
||||||
|
|
||||||
Future<void> _markAllRead() async {
|
|
||||||
final AuthProvider auth = Get.find();
|
|
||||||
if (auth.isAuthorized.isFalse) return;
|
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
|
||||||
|
|
||||||
final NotificationProvider nty = Get.find();
|
|
||||||
|
|
||||||
List<int> markList = List.empty(growable: true);
|
|
||||||
for (final element in nty.notifications) {
|
|
||||||
if (element.id <= 0) continue;
|
|
||||||
markList.add(element.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (markList.isNotEmpty) {
|
|
||||||
final client = await auth.configureClient('auth');
|
|
||||||
await client.put('/notifications/read', {'messages': markList});
|
|
||||||
}
|
|
||||||
|
|
||||||
nty.notifications.clear();
|
|
||||||
|
|
||||||
setState(() => _isBusy = false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _markOneRead(notify.Notification element, int index) async {
|
|
||||||
final AuthProvider auth = Get.find();
|
|
||||||
if (auth.isAuthorized.isFalse) return;
|
|
||||||
|
|
||||||
final NotificationProvider nty = Get.find();
|
|
||||||
|
|
||||||
if (element.id <= 0) {
|
|
||||||
nty.notifications.removeAt(index);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(() => _isBusy = true);
|
|
||||||
|
|
||||||
final client = await auth.configureClient('auth');
|
|
||||||
|
|
||||||
await client.put('/notifications/read/${element.id}', {});
|
|
||||||
|
|
||||||
nty.notifications.removeAt(index);
|
|
||||||
|
|
||||||
setState(() => _isBusy = false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final NotificationProvider nty = Get.find();
|
final NotificationProvider nty = Get.find();
|
||||||
@ -81,11 +31,9 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
onRefresh: () => nty.fetchNotification(),
|
onRefresh: () => nty.fetchNotification(),
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: [
|
slivers: [
|
||||||
Obx(
|
SliverToBoxAdapter(
|
||||||
() => SliverToBoxAdapter(
|
|
||||||
child: LoadingIndicator(
|
child: LoadingIndicator(
|
||||||
isActive: _isBusy || nty.isBusy.value,
|
isActive: nty.isBusy.value,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (nty.notifications
|
if (nty.notifications
|
||||||
@ -115,7 +63,9 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
child: ListTile(
|
child: ListTile(
|
||||||
leading: const Icon(Icons.checklist),
|
leading: const Icon(Icons.checklist),
|
||||||
title: Text('notifyAllRead'.tr),
|
title: Text('notifyAllRead'.tr),
|
||||||
onTap: _isBusy ? null : () => _markAllRead(),
|
onTap: nty.isBusy.value
|
||||||
|
? null
|
||||||
|
: () => nty.markAllRead(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -125,6 +75,9 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
var element = nty.notifications[index];
|
var element = nty.notifications[index];
|
||||||
return ClipRect(
|
return ClipRect(
|
||||||
child: Dismissible(
|
child: Dismissible(
|
||||||
|
direction: element.readAt == null
|
||||||
|
? DismissDirection.vertical
|
||||||
|
: DismissDirection.none,
|
||||||
key: Key(const Uuid().v4()),
|
key: Key(const Uuid().v4()),
|
||||||
background: Container(
|
background: Container(
|
||||||
color: Colors.lightBlue,
|
color: Colors.lightBlue,
|
||||||
@ -134,6 +87,14 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
child:
|
child:
|
||||||
const Icon(Icons.check, color: Colors.white),
|
const Icon(Icons.check, color: Colors.white),
|
||||||
),
|
),
|
||||||
|
secondaryBackground: Container(
|
||||||
|
color: Colors.lightBlue,
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 20),
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child:
|
||||||
|
const Icon(Icons.check, color: Colors.white),
|
||||||
|
),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
contentPadding: const EdgeInsets.symmetric(
|
contentPadding: const EdgeInsets.symmetric(
|
||||||
horizontal: 24,
|
horizontal: 24,
|
||||||
@ -149,7 +110,7 @@ class _NotificationScreenState extends State<NotificationScreen> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onDismissed: (_) => _markOneRead(element, index),
|
onDismissed: (_) => nty.markOneRead(element, index),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user