Skip to content

Commit

Permalink
feat: add rating system for events
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed May 29, 2024
1 parent 2c55643 commit 805f461
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 52 deletions.
2 changes: 1 addition & 1 deletion lib/classes/event_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part 'event_data.g.dart';
class EventData with _$EventData {
const factory EventData({
required String title,
required int stars,
required double stars,
required EventStatus status,
}) = _EventData;

Expand Down
16 changes: 8 additions & 8 deletions lib/classes/event_data.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EventData _$EventDataFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$EventData {
String get title => throw _privateConstructorUsedError;
int get stars => throw _privateConstructorUsedError;
double get stars => throw _privateConstructorUsedError;
EventStatus get status => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
Expand All @@ -35,7 +35,7 @@ abstract class $EventDataCopyWith<$Res> {
factory $EventDataCopyWith(EventData value, $Res Function(EventData) then) =
_$EventDataCopyWithImpl<$Res, EventData>;
@useResult
$Res call({String title, int stars, EventStatus status});
$Res call({String title, double stars, EventStatus status});
}

/// @nodoc
Expand Down Expand Up @@ -63,7 +63,7 @@ class _$EventDataCopyWithImpl<$Res, $Val extends EventData>
stars: null == stars
? _value.stars
: stars // ignore: cast_nullable_to_non_nullable
as int,
as double,
status: null == status
? _value.status
: status // ignore: cast_nullable_to_non_nullable
Expand All @@ -80,7 +80,7 @@ abstract class _$$EventDataImplCopyWith<$Res>
__$$EventDataImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String title, int stars, EventStatus status});
$Res call({String title, double stars, EventStatus status});
}

/// @nodoc
Expand All @@ -106,7 +106,7 @@ class __$$EventDataImplCopyWithImpl<$Res>
stars: null == stars
? _value.stars
: stars // ignore: cast_nullable_to_non_nullable
as int,
as double,
status: null == status
? _value.status
: status // ignore: cast_nullable_to_non_nullable
Expand All @@ -127,7 +127,7 @@ class _$EventDataImpl implements _EventData {
@override
final String title;
@override
final int stars;
final double stars;
@override
final EventStatus status;

Expand Down Expand Up @@ -167,7 +167,7 @@ class _$EventDataImpl implements _EventData {
abstract class _EventData implements EventData {
const factory _EventData(
{required final String title,
required final int stars,
required final double stars,
required final EventStatus status}) = _$EventDataImpl;

factory _EventData.fromJson(Map<String, dynamic> json) =
Expand All @@ -176,7 +176,7 @@ abstract class _EventData implements EventData {
@override
String get title;
@override
int get stars;
double get stars;
@override
EventStatus get status;
@override
Expand Down
2 changes: 1 addition & 1 deletion lib/classes/event_data.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions lib/features/journal/state/entry_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ class EntryController extends _$EntryController {
await HapticFeedback.heavyImpact();
}

Future<void> updateRating(double stars) async {
final event = state.value?.entry;
if (event != null && event is JournalEvent) {
await _persistenceLogic.updateEvent(
entryText: entryTextFromController(controller),
journalEntityId: entryId,
data: event.data.copyWith(
stars: stars,
),
);
}
}

Future<bool> delete({
required bool beamBack,
}) async {
Expand Down
2 changes: 1 addition & 1 deletion lib/features/journal/state/entry_controller.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/logic/persistence_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,13 @@ class PersistenceLogic {
vectorClock: vc,
);

final newTask = event.copyWith(
final newEvent = event.copyWith(
meta: newMeta,
entryText: entryText,
data: data,
);

await updateDbEntity(newTask, enqueueSync: true);
await updateDbEntity(newEvent, enqueueSync: true);
},
orElse: () async => _loggingDb.captureException(
'not an event',
Expand Down
26 changes: 25 additions & 1 deletion lib/widgets/events/event_form.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_rating/flutter_rating.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lotti/classes/event_status.dart';
import 'package:lotti/classes/journal_entities.dart';
Expand All @@ -24,6 +25,14 @@ class EventForm extends ConsumerStatefulWidget {
}

class _EventFormState extends ConsumerState<EventForm> {
double stars = 0;

@override
void initState() {
super.initState();
stars = widget.event?.data.stars ?? stars;
}

@override
Widget build(BuildContext context) {
final data = widget.event?.data;
Expand Down Expand Up @@ -67,8 +76,23 @@ class _EventFormState extends ConsumerState<EventForm> {
inputSpacer,
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 190),
child: StarRating(
rating: stars,
allowHalfRating: true,
size: 32,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
onRatingChanged: (rating) {
setState(() {
stars = rating;
});
notifier.updateRating(rating);
},
),
),
const SizedBox(width: 10),
SizedBox(
width: 180,
child: FormBuilderDropdown<EventStatus>(
Expand Down
10 changes: 2 additions & 8 deletions lib/widgets/events/event_status.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:lotti/classes/event_status.dart';
import 'package:lotti/themes/theme.dart';
import 'package:tinycolor2/tinycolor2.dart';

class EventStatusWidget extends StatelessWidget {
const EventStatusWidget(
Expand All @@ -13,17 +12,12 @@ class EventStatusWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final backgroundColor = status.color;

return Chip(
label: Text(
status.label,
style: TextStyle(
fontSize: fontSizeSmall,
color: backgroundColor.isLight ? Colors.black : Colors.white,
),
style: const TextStyle(fontSize: fontSizeSmall),
),
backgroundColor: status.color,
backgroundColor: status.color.withOpacity(0.6),
visualDensity: VisualDensity.compact,
);
}
Expand Down
17 changes: 9 additions & 8 deletions lib/widgets/journal/entry_details/entry_detail_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ class _EntryDetailHeaderState extends ConsumerState<EntryDetailHeader> {
scrollDirection: Axis.horizontal,
child: Row(
children: [
SwitchIconWidget(
tooltip: context.messages.journalFavoriteTooltip,
onPressed: notifier.toggleStarred,
value: entry?.meta.starred ?? false,
icon: Icons.star_outline_rounded,
activeIcon: Icons.star_rounded,
activeColor: starredGold,
),
if (entry is! JournalEvent)
SwitchIconWidget(
tooltip: context.messages.journalFavoriteTooltip,
onPressed: notifier.toggleStarred,
value: entry?.meta.starred ?? false,
icon: Icons.star_outline_rounded,
activeIcon: Icons.star_rounded,
activeColor: starredGold,
),
SwitchIconWidget(
tooltip: context.messages.journalFlaggedTooltip,
onPressed: notifier.toggleFlagged,
Expand Down
1 change: 1 addition & 0 deletions lib/widgets/journal/entry_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bool fromNullableBool(bool? value) {

DateFormat df = DateFormat('yyyy-MM-dd HH:mm:ss');
DateFormat dfShorter = DateFormat('yyyy-MM-dd HH:mm');
DateFormat dfShort = DateFormat('yyyy-MM-dd');
DateFormat dfYmd = DateFormat('yyyy-MM-dd');
DateFormat hhMmFormat = DateFormat('HH:mm');

Expand Down
57 changes: 36 additions & 21 deletions lib/widgets/journal/journal_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_rating/flutter_rating.dart';
import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/database/database.dart';
import 'package:lotti/get_it.dart';
Expand Down Expand Up @@ -52,12 +53,12 @@ class JournalCardTitle extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
dfShorter.format(item.meta.dateFrom),
item is JournalEvent
? dfShort.format(item.meta.dateFrom)
: dfShorter.format(item.meta.dateFrom),
style: monospaceTextStyle,
),
if (item is Task) TaskStatusWidget(item as Task),
if (item is JournalEvent)
EventStatusWidget((item as JournalEvent).data.status),
Row(
children: [
Visibility(
Expand All @@ -68,30 +69,44 @@ class JournalCardTitle extends StatelessWidget {
size: iconSize,
),
),
Visibility(
visible: fromNullableBool(item.meta.starred),
child: Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(
MdiIcons.star,
color: starredGold,
size: iconSize,
if (item is! JournalEvent)
Visibility(
visible: fromNullableBool(item.meta.starred),
child: Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(
MdiIcons.star,
color: starredGold,
size: iconSize,
),
),
),
),
Visibility(
visible: item.meta.flag == EntryFlag.import,
child: Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(
MdiIcons.flag,
color: Theme.of(context).colorScheme.error,
size: iconSize,
if (item is! JournalEvent)
Visibility(
visible: item.meta.flag == EntryFlag.import,
child: Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(
MdiIcons.flag,
color: Theme.of(context).colorScheme.error,
size: iconSize,
),
),
),
),
],
),
if (item is JournalEvent) ...[
const SizedBox(width: 10),
EventStatusWidget(
(item as JournalEvent).data.status,
),
const SizedBox(width: 10),
StarRating(
rating: (item as JournalEvent).data.stars,
size: 18,
allowHalfRating: true,
),
],
],
),
TagsViewWidget(item: item),
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "9.3.21"
flutter_rating:
dependency: "direct main"
description:
name: flutter_rating
sha256: "207bcd4a276585b8a0771a5ac03c0f3cdb27490e79a609f9a483d9794fe630b7"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
flutter_riverpod:
dependency: "direct main"
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.469+2538
version: 0.9.469+2539

msix_config:
display_name: LottiApp
Expand Down Expand Up @@ -75,6 +75,7 @@ dependencies:
flutter_olm: ^1.4.1
flutter_openssl_crypto: ^0.3.0
flutter_quill: ^9.2.1
flutter_rating: ^2.0.2
flutter_riverpod: ^2.4.9
flutter_secure_storage: ^9.0.0
flutter_sliding_tutorial: ^2.0.0
Expand Down

0 comments on commit 805f461

Please sign in to comment.