Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diary #1061

Merged
merged 6 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/components/organisms/calendar/week/week_calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:pilll/features/schedule_post/schedule_post_page.dart';
import 'package:pilll/entity/diary.codegen.dart';
import 'package:pilll/entity/schedule.codegen.dart';
import 'package:pilll/entity/weekday.dart';
import 'package:pilll/features/diary_post/confirm_diary_sheet.dart';
import 'package:pilll/features/diary_post/diary_confirmation_sheet.dart';
import 'package:pilll/utils/datetime/date_compare.dart';
import 'package:pilll/utils/datetime/day.dart';

Expand Down Expand Up @@ -172,7 +172,7 @@ void transitionWhenCalendarDayTapped(
void _showConfirmDiarySheet(BuildContext context, Diary diary) {
showModalBottomSheet(
context: context,
builder: (context) => ConfirmDiarySheet(diary: diary),
builder: (context) => DiaryConfirmationSheet(date: diary.date),
backgroundColor: Colors.transparent,
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:pilll/components/atoms/button.dart';
import 'package:pilll/components/molecules/indicator.dart';
import 'package:pilll/components/page/discard_dialog.dart';
import 'package:pilll/features/diary_post/diary_post_page.dart';
import 'package:pilll/entity/diary.codegen.dart';
Expand All @@ -11,17 +12,22 @@ import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_svg/svg.dart';

class ConfirmDiarySheet extends HookConsumerWidget {
final Diary diary;
class DiaryConfirmationSheet extends HookConsumerWidget {
final DateTime date;

const ConfirmDiarySheet({
const DiaryConfirmationSheet({
Key? key,
required this.diary,
required this.date,
}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
final diary = ref.watch(diaryProvider(date));
final deleteDiary = ref.watch(deleteDiaryProvider);
if (diary == null) {
return const Indicator();
}

return Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
Expand All @@ -32,12 +38,12 @@ class ConfirmDiarySheet extends HookConsumerWidget {
),
padding: const EdgeInsets.fromLTRB(16, 20, 16, 20),
child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
_title(context, deleteDiary),
_title(context, deleteDiary, diary),
...[
if (diary.hasPhysicalConditionStatus) _physicalCondition(),
_physicalConditionDetails(),
if (diary.hasSex) _sex(),
_memo(),
if (diary.hasPhysicalConditionStatus) _physicalCondition(diary),
_physicalConditionDetails(diary),
if (diary.hasSex) _sex(diary),
_memo(diary),
].map((e) => _withContentSpacer(e)),
]),
);
Expand All @@ -50,7 +56,7 @@ class ConfirmDiarySheet extends HookConsumerWidget {
);
}

Widget _title(BuildContext context, DeleteDiary deleteDiary) {
Widget _title(BuildContext context, DeleteDiary deleteDiary, Diary diary) {
return Row(
mainAxisSize: MainAxisSize.max,
children: [
Expand Down Expand Up @@ -113,7 +119,7 @@ class ConfirmDiarySheet extends HookConsumerWidget {
}
}

Widget _physicalCondition() {
Widget _physicalCondition(Diary diary) {
return Row(
children: [
const Text("体調",
Expand All @@ -129,7 +135,7 @@ class ConfirmDiarySheet extends HookConsumerWidget {
);
}

Widget _physicalConditionDetails() {
Widget _physicalConditionDetails(Diary diary) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expand All @@ -154,7 +160,7 @@ class ConfirmDiarySheet extends HookConsumerWidget {
);
}

Widget _sex() {
Widget _sex(Diary diary) {
return Container(
padding: const EdgeInsets.all(4),
width: 32,
Expand All @@ -164,7 +170,7 @@ class ConfirmDiarySheet extends HookConsumerWidget {
);
}

Widget _memo() {
Widget _memo(Diary diary) {
return Text(
diary.memo,
maxLines: 2,
Expand Down
8 changes: 4 additions & 4 deletions lib/features/diary_post/diary_post_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ class DiaryPostPageBody extends HookConsumerWidget {
required this.user,
required this.diarySetting,
}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
final textEditingController = useTextEditingController(text: diary.memo);
final memoTextEditingController = useTextEditingController(text: diary.memo);
final focusNode = useFocusNode();
final scrollController = useScrollController();

final physicalCondition = useState<PhysicalConditionStatus?>(diary.physicalConditionStatus);
final physicalConditionDetails = useState(diary.physicalConditions);
final sex = useState(diary.hasSex);
final memo = useState(diary.memo);

final setDiary = ref.watch(setDiaryProvider);

Expand Down Expand Up @@ -114,7 +114,7 @@ class DiaryPostPageBody extends HookConsumerWidget {
physicalConditionStatus: physicalCondition.value,
physicalConditions: physicalConditionDetails.value,
hasSex: sex.value,
memo: memo.value,
memo: memoTextEditingController.text,
));

navigator.pop();
Expand Down Expand Up @@ -145,7 +145,7 @@ class DiaryPostPageBody extends HookConsumerWidget {
const SizedBox(height: 20),
DiaryPostSex(sex: sex),
const SizedBox(height: 20),
DiaryPostMemo(textEditingController: textEditingController, focusNode: focusNode, memo: memo),
DiaryPostMemo(textEditingController: memoTextEditingController, focusNode: focusNode),
],
),
),
Expand Down
10 changes: 2 additions & 8 deletions lib/features/diary_post/memo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
class DiaryPostMemo extends HookConsumerWidget {
final TextEditingController textEditingController;
final FocusNode focusNode;
final ValueNotifier<String> memo;
const DiaryPostMemo({Key? key, required this.textEditingController, required this.focusNode, required this.memo}) : super(key: key);
const DiaryPostMemo({Key? key, required this.textEditingController, required this.focusNode}) : super(key: key);

@override
Widget build(BuildContext context, WidgetRef ref) {
const textLength = 120;
return ConstrainedBox(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
Expand All @@ -18,17 +16,13 @@ class DiaryPostMemo extends HookConsumerWidget {
maxHeight: 200,
),
child: TextFormField(
onChanged: (text) {
memo.value = text;
},
decoration: const InputDecoration(
hintText: "メモ",
border: OutlineInputBorder(),
),
controller: textEditingController,
maxLines: null,
maxLength: textLength,
keyboardType: TextInputType.multiline,
maxLength: 120,
focusNode: focusNode,
),
);
Expand Down
4 changes: 4 additions & 0 deletions lib/provider/diary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ List<Diary> _sortedDiaries(List<Diary> diaries) {
return diaries;
}

final diaryProvider = Provider.family((ref, DateTime date) {
return ref.watch(diariesForMonthProvider(date)).asData?.value.firstWhereOrNull((element) => element.date == date);
});

final setDiaryProvider = Provider((ref) => SetDiary(ref.watch(databaseProvider)));

class SetDiary {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ packages:
dependency: "direct main"
description:
name: flutter_hooks
sha256: "7c8db779c2d1010aa7f9ea3fbefe8f86524fcb87b69e8b0af31e1a4b55422dec"
sha256: "09f64db63fee3b2ab8b9038a1346be7d8986977fae3fec601275bf32455ccfc0"
url: "https://pub.dev"
source: hosted
version: "0.20.3"
version: "0.20.4"
flutter_lints:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies:
riverpod: ^2.4.4
hooks_riverpod: ^2.4.4
riverpod_annotation: 2.3.0
flutter_hooks: ^0.20.3
flutter_hooks: ^0.20.4
firebase_crashlytics: ^3.0.12
dotted_border: ^2.1.0
in_app_review: ^2.0.8
Expand Down
Loading