diff --git a/lib/model/entity/attend_status.dart b/lib/model/entity/attend_status.dart new file mode 100644 index 0000000..56f9347 --- /dev/null +++ b/lib/model/entity/attend_status.dart @@ -0,0 +1,11 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +// {ファイル名}.freezed.dart と書く +part 'generated/attend_status.freezed.dart'; + +//Freezed特有の書き方なので、スニペットを用意するのが良い +@freezed +class AttendStatus with _$AttendStatus { + const factory AttendStatus({ + required bool attend, + }) = _AttendStatus; +} \ No newline at end of file diff --git a/lib/model/entity/generated/attend_status.freezed.dart b/lib/model/entity/generated/attend_status.freezed.dart new file mode 100644 index 0000000..bc84368 --- /dev/null +++ b/lib/model/entity/generated/attend_status.freezed.dart @@ -0,0 +1,129 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of '../attend_status.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$AttendStatus { + bool get attend => throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $AttendStatusCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $AttendStatusCopyWith<$Res> { + factory $AttendStatusCopyWith( + AttendStatus value, $Res Function(AttendStatus) then) = + _$AttendStatusCopyWithImpl<$Res>; + $Res call({bool attend}); +} + +/// @nodoc +class _$AttendStatusCopyWithImpl<$Res> implements $AttendStatusCopyWith<$Res> { + _$AttendStatusCopyWithImpl(this._value, this._then); + + final AttendStatus _value; + // ignore: unused_field + final $Res Function(AttendStatus) _then; + + @override + $Res call({ + Object? attend = freezed, + }) { + return _then(_value.copyWith( + attend: attend == freezed + ? _value.attend + : attend // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +abstract class _$$_AttendStatusCopyWith<$Res> + implements $AttendStatusCopyWith<$Res> { + factory _$$_AttendStatusCopyWith( + _$_AttendStatus value, $Res Function(_$_AttendStatus) then) = + __$$_AttendStatusCopyWithImpl<$Res>; + @override + $Res call({bool attend}); +} + +/// @nodoc +class __$$_AttendStatusCopyWithImpl<$Res> + extends _$AttendStatusCopyWithImpl<$Res> + implements _$$_AttendStatusCopyWith<$Res> { + __$$_AttendStatusCopyWithImpl( + _$_AttendStatus _value, $Res Function(_$_AttendStatus) _then) + : super(_value, (v) => _then(v as _$_AttendStatus)); + + @override + _$_AttendStatus get _value => super._value as _$_AttendStatus; + + @override + $Res call({ + Object? attend = freezed, + }) { + return _then(_$_AttendStatus( + attend: attend == freezed + ? _value.attend + : attend // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc + +class _$_AttendStatus implements _AttendStatus { + const _$_AttendStatus({required this.attend}); + + @override + final bool attend; + + @override + String toString() { + return 'AttendStatus(attend: $attend)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_AttendStatus && + const DeepCollectionEquality().equals(other.attend, attend)); + } + + @override + int get hashCode => + Object.hash(runtimeType, const DeepCollectionEquality().hash(attend)); + + @JsonKey(ignore: true) + @override + _$$_AttendStatusCopyWith<_$_AttendStatus> get copyWith => + __$$_AttendStatusCopyWithImpl<_$_AttendStatus>(this, _$identity); +} + +abstract class _AttendStatus implements AttendStatus { + const factory _AttendStatus({required final bool attend}) = _$_AttendStatus; + + @override + bool get attend; + @override + @JsonKey(ignore: true) + _$$_AttendStatusCopyWith<_$_AttendStatus> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/model/entity/schedule_list.dart b/lib/model/entity/schedule_list.dart index bebf249..8232d4c 100644 --- a/lib/model/entity/schedule_list.dart +++ b/lib/model/entity/schedule_list.dart @@ -1,6 +1,5 @@ import 'package:schetify/model/entity/schedule.dart'; -import 'test_weather.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; // {ファイル名}.freezed.dart と書く part 'generated/schedule_list.freezed.dart'; diff --git a/lib/model/entity/schedule_update_page_util.dart b/lib/model/entity/schedule_update_page_util.dart index 1df6c4c..e3cc7d5 100644 --- a/lib/model/entity/schedule_update_page_util.dart +++ b/lib/model/entity/schedule_update_page_util.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; class ScheduleUpdatePageUtil { final String tileName; final String routeName; final Icon? iconName; + final Consumer toggleConsumer; - ScheduleUpdatePageUtil(this.tileName, this.routeName, this.iconName); + ScheduleUpdatePageUtil(this.tileName, this.routeName, this.iconName, + this.toggleConsumer); } \ No newline at end of file diff --git a/lib/provider/attend_provider.dart b/lib/provider/attend_provider.dart new file mode 100644 index 0000000..660b255 --- /dev/null +++ b/lib/provider/attend_provider.dart @@ -0,0 +1,17 @@ +import 'package:hooks_riverpod/hooks_riverpod.dart'; + +import '../model/entity/attend_status.dart'; + + +class AttendNotifier extends StateNotifier { + AttendNotifier() : super(const AttendStatus(attend: false)); + + changeAttend(bool flag){ + state = state.copyWith(attend: flag); + } +} + +final attendProvider = StateNotifierProvider((ref) { + return AttendNotifier(); +}); \ No newline at end of file diff --git a/lib/widget/components/schedule/sub_list_item.dart b/lib/widget/components/schedule/sub_list_item.dart index f15b1a6..1e8db73 100644 --- a/lib/widget/components/schedule/sub_list_item.dart +++ b/lib/widget/components/schedule/sub_list_item.dart @@ -1,17 +1,19 @@ import 'package:flutter/material.dart'; +import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:schetify/widget/dialog/event_detail_dialog.dart'; -class SubListItem extends StatelessWidget { +class SubListItem extends HookConsumerWidget { final String title; final Widget leading; final String route; - final String toggle; + final Consumer toggleConsumer; final String address; - SubListItem({required this.title, required this.leading, required this.route, required this.toggle, required this.address}); + SubListItem({required this.title, required this.leading, required this.route, + required this.toggleConsumer, required this.address}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { return ListTile( title: Row( mainAxisSize: MainAxisSize.min, @@ -41,19 +43,13 @@ class SubListItem extends StatelessWidget { ) ) }else{ - Navigator.of(context).pushNamed(route) + Navigator.pushNamed(context,route) } }, - // onLongPress: () => {}, trailing: Row( mainAxisSize: MainAxisSize.min, children: [ - Text( - toggle, - style: const TextStyle( - fontSize: 20, - ), - ), + toggleConsumer, const SizedBox( width: 50, ), diff --git a/lib/widget/page/schedule/common/schedule_update_page.dart b/lib/widget/page/schedule/common/schedule_update_page.dart index 8f977f9..9552142 100644 --- a/lib/widget/page/schedule/common/schedule_update_page.dart +++ b/lib/widget/page/schedule/common/schedule_update_page.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:schetify/provider/attend_provider.dart'; +import 'package:schetify/provider/settings_label_provider.dart'; +import 'package:schetify/provider/splitting_the_cost_provider.dart'; import '../../../../model/entity/schedule_update_page_util.dart'; import '../../../components/schedule/sub_list_item.dart'; @@ -7,23 +10,65 @@ class ScheduleUpdatePage extends HookConsumerWidget { ScheduleUpdatePage({Key? key}) : super(key: key); final List util = [ - ScheduleUpdatePageUtil("予定詳細", "detail", const Icon(Icons.details)), - ScheduleUpdatePageUtil("日にち設定", "/schedule/new/day", const Icon(Icons.calendar_today)), - ScheduleUpdatePageUtil("席分け設定", "/schedule/new/seat", const Icon(Icons.table_bar)), - ScheduleUpdatePageUtil("ラベル設定", "/schedule/new/label", const Icon(Icons.label)), - ScheduleUpdatePageUtil("割り勘設定", "/schedule/new/cost", const Icon(Icons.money)), - ScheduleUpdatePageUtil("目的地:", "/schedule/new/destination", const Icon(Icons.room),), - ScheduleUpdatePageUtil("アンケート設定", "/schedule/new/questionnaire", const Icon(Icons.feed)), - ScheduleUpdatePageUtil("出席", "", const Icon(Icons.confirmation_num)), - ScheduleUpdatePageUtil("シェア(URL)", "", const Icon(Icons.add_link)), + ScheduleUpdatePageUtil("予定詳細", "", const Icon(Icons.details), + Consumer(builder: (context, ref, _) { + return const Text(""); + })), + ScheduleUpdatePageUtil("日にち設定", "/schedule/new/day", const Icon(Icons.calendar_today), + Consumer(builder: (context, ref, _) { + return const Text(""); + })), + ScheduleUpdatePageUtil("席分け設定", "/schedule/new/seat", const Icon(Icons.table_bar), + Consumer(builder: (context, ref, _) { + return const Text(""); + })), + ScheduleUpdatePageUtil("ラベル設定", "/schedule/new/label", const Icon(Icons.label), + Consumer(builder: (context, ref, _) { + var flag = ref.read(settingsLabelProvider); + if(flag.flag){ + return const Text("ON"); + }else{ + return const Text("OFF"); + } + })), + ScheduleUpdatePageUtil("割り勘設定", "/schedule/new/cost", const Icon(Icons.money), + Consumer(builder: (context, ref, _) { + var flag = ref.read(splittingTheCostProvider); + if(flag.flag){ + return const Text("ON"); + }else{ + return const Text("OFF"); + } + })), + ScheduleUpdatePageUtil("目的地:", "/schedule/new/destination", const Icon(Icons.room), + Consumer(builder: (context, ref, _) { + return const Text(""); + })), + ScheduleUpdatePageUtil("アンケート設定", "/schedule/new/questionnaire", const Icon(Icons.feed), + Consumer(builder: (context, ref, _) { + return const Text(""); + })), + ScheduleUpdatePageUtil("出席", "", const Icon(Icons.confirmation_num), + Consumer(builder: (context, ref, _) { + var flag = ref.read(attendProvider); + if(flag.attend){ + return const Text("ON"); + }else{ + return const Text("OFF"); + } + })), + ScheduleUpdatePageUtil("シェア(URL)", "", const Icon(Icons.add_link), + Consumer(builder: (context, ref, _) { + return const Text(""); + })), ]; // tentative variable - String toggleState = "ON"; String address = "東京都世田谷区北沢3丁目23−14"; @override Widget build(BuildContext context, WidgetRef ref) { + return Scaffold( appBar: AppBar( title: const Text("予定作成&編集"), @@ -71,7 +116,7 @@ class ScheduleUpdatePage extends HookConsumerWidget { child: util[index].iconName, ), route: util[index].routeName, - toggle: util[index].tileName == '出席' ? toggleState : '', + toggleConsumer: util[index].toggleConsumer, address: util[index].tileName == '目的地:' ? address : '', ); },