-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
notification_list_tile.dart
147 lines (138 loc) · 5.08 KB
/
notification_list_tile.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:genshindb/application/bloc.dart';
import 'package:genshindb/application/notifications/notifications_bloc.dart';
import 'package:genshindb/domain/enums/enums.dart';
import 'package:genshindb/domain/extensions/duration_extensions.dart';
import 'package:genshindb/domain/models/models.dart' as models;
import 'package:genshindb/generated/l10n.dart';
import 'package:genshindb/presentation/shared/circle_item.dart';
import 'package:genshindb/presentation/shared/number_picker_dialog.dart';
import 'package:genshindb/presentation/shared/styles.dart';
import '../add_edit_notification_bottom_sheet.dart';
class NotificationListTitle extends StatelessWidget {
final int itemKey;
final AppNotificationType type;
final String image;
final Duration remaining;
final DateTime createdAt;
final DateTime completesAt;
final String note;
final bool showNotification;
final Widget subtitle;
NotificationListTitle({
Key key,
@required models.NotificationItem item,
@required this.subtitle,
}) : itemKey = item.key,
type = item.type,
image = item.image,
remaining = item.remaining,
createdAt = item.createdAt,
completesAt = item.completesAt,
note = item.note,
showNotification = item.showNotification,
super(key: key);
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final s = S.of(context);
return Slidable(
actionPane: const SlidableDrawerActionPane(),
actions: [
IconSlideAction(
caption: s.stop,
color: Colors.deepOrange,
icon: Icons.stop,
foregroundColor: Colors.white,
onTap: () => context.read<NotificationsBloc>().add(NotificationsEvent.stop(id: itemKey, type: type)),
),
IconSlideAction(
caption: s.delete,
color: Colors.red,
icon: Icons.delete,
onTap: () => context.read<NotificationsBloc>().add(NotificationsEvent.delete(id: itemKey, type: type)),
),
],
secondaryActions: [
IconSlideAction(
caption: s.edit,
color: Colors.orange,
icon: Icons.edit,
foregroundColor: Colors.white,
onTap: () => _showEditModal(context),
),
if (type != AppNotificationType.custom)
IconSlideAction(
caption: s.reset,
color: Colors.green,
icon: Icons.restore,
foregroundColor: Colors.white,
onTap: () => context.read<NotificationsBloc>().add(NotificationsEvent.reset(id: itemKey, type: type)),
),
if (remaining.inHours > 1 && type != AppNotificationType.resin && type != AppNotificationType.realmCurrency)
IconSlideAction(
caption: s.reduceTime,
color: Colors.purpleAccent,
icon: Icons.timelapse,
foregroundColor: Colors.white,
onTap: () => _showReduceTimeModal(context),
),
],
child: ListTile(
contentPadding: Styles.edgeInsetAll5,
minVerticalPadding: 10,
horizontalTitleGap: 10,
onTap: () => _showEditModal(context),
leading: Container(
constraints: BoxConstraints.tight(const Size.fromRadius(30)),
child: Stack(
children: [
CircleItem(image: image, forDrag: true),
if (showNotification)
Positioned(
top: 0,
right: 0,
child: Icon(Icons.notifications_active, color: theme.accentColor),
),
],
),
),
title: Text(remaining.formatDuration(negativeText: s.completed), style: theme.textTheme.subtitle1),
subtitle: subtitle,
),
);
}
Future<void> _showEditModal(BuildContext context) async {
context.read<NotificationsBloc>().cancelTimer();
context.read<NotificationBloc>().add(NotificationEvent.edit(key: itemKey, type: type));
await showModalBottomSheet(
context: context,
shape: Styles.modalBottomSheetShape,
isDismissible: true,
isScrollControlled: true,
builder: (_) => const AddEditNotificationBottomSheet(isInEditMode: true),
);
context.read<NotificationsBloc>().add(const NotificationsEvent.init());
}
Future<void> _showReduceTimeModal(BuildContext context) async {
final s = S.of(context);
context.read<NotificationsBloc>().cancelTimer();
final hoursToReduce = await showDialog<int>(
context: context,
builder: (_) => NumberPickerDialog(
title: s.reduceTime,
minItemLevel: 1,
maxItemLevel: remaining.inHours,
value: 1,
itemBuilder: (value) => s.inXHours(value),
),
);
context.read<NotificationsBloc>().add(const NotificationsEvent.init());
if (hoursToReduce == null) {
return;
}
context.read<NotificationsBloc>().add(NotificationsEvent.reduceHours(id: itemKey, type: type, hoursToReduce: hoursToReduce));
}
}