diff --git a/lib/pages/input_participant_info/input_participant_info_page.dart b/lib/pages/input_participant_info/input_participant_info_page.dart index 8842a8b..e102fa7 100644 --- a/lib/pages/input_participant_info/input_participant_info_page.dart +++ b/lib/pages/input_participant_info/input_participant_info_page.dart @@ -1,19 +1,23 @@ import 'package:flutter/material.dart'; +import 'package:flutter_state_notifier/flutter_state_notifier.dart'; +import 'package:morning_weakers/pages/input_participant_info/input_participant_info_controller.dart'; +import 'package:morning_weakers/pages/input_participant_info/input_participant_info_state.dart'; import 'package:morning_weakers/pages/input_participant_info/widgets/desired_occupation.dart'; import 'package:morning_weakers/pages/input_participant_info/widgets/schedule_candidate.dart'; import 'package:morning_weakers/pages/input_participant_info/widgets/working_days.dart'; -import 'package:firebase_auth/firebase_auth.dart'; +import 'package:morning_weakers/pages/input_participant_info/widgets/submit_btn.dart'; class InputParticipantInfoPage extends StatelessWidget { @override Widget build(BuildContext context) { - FirebaseUser userData; - print('input:$userData'); return Scaffold( appBar: AppBar( title: const Text('参加者情報入力'), ), - body: _inputParticipantInfo, + body: StateNotifierProvider( + create: (_) => InputParticipantInfoController(), + child: _inputParticipantInfo, + ), ); } @@ -29,7 +33,8 @@ class InputParticipantInfoPage extends StatelessWidget { decoration: const InputDecoration( labelText: '備考欄' ), - ) + ), + SubmitBtn(), ], ), ), diff --git a/lib/pages/input_participant_info/input_participant_info_state.dart b/lib/pages/input_participant_info/input_participant_info_state.dart new file mode 100644 index 0000000..40271da --- /dev/null +++ b/lib/pages/input_participant_info/input_participant_info_state.dart @@ -0,0 +1,19 @@ +import 'package:flutter/foundation.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:morning_weakers/models/models.dart'; +part 'input_participant_info_state.freezed.dart'; +part 'input_participant_info_state.g.dart'; + +@freezed +abstract class InputParticipantInfoState with _$InputParticipantInfoState { + const factory InputParticipantInfoState({ + // Participant Model + @JsonKey(name: 'desired_occupations') List desiredOccupations, + @JsonKey(name: 'working_days') int workingDays, + String note, + // Questionnaire Model + @required @JsonKey(name: 'schedule_candidate') List scheduleCandidates, + }) = _InputParticipantInfoState; + + factory InputParticipantInfoState.fromJson(Map json) => _$InputParticipantInfoStateFromJson(json); +} diff --git a/lib/pages/input_participant_info/input_participant_info_state.freezed.dart b/lib/pages/input_participant_info/input_participant_info_state.freezed.dart new file mode 100644 index 0000000..882af81 --- /dev/null +++ b/lib/pages/input_participant_info/input_participant_info_state.freezed.dart @@ -0,0 +1,251 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named + +part of 'input_participant_info_state.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; +InputParticipantInfoState _$InputParticipantInfoStateFromJson( + Map json) { + return _InputParticipantInfoState.fromJson(json); +} + +class _$InputParticipantInfoStateTearOff { + const _$InputParticipantInfoStateTearOff(); + + _InputParticipantInfoState call( + {@JsonKey(name: 'desired_occupations') + List desiredOccupations, + @JsonKey(name: 'working_days') + int workingDays, + String note, + @required + @JsonKey(name: 'schedule_candidate') + List scheduleCandidates}) { + return _InputParticipantInfoState( + desiredOccupations: desiredOccupations, + workingDays: workingDays, + note: note, + scheduleCandidates: scheduleCandidates, + ); + } +} + +// ignore: unused_element +const $InputParticipantInfoState = _$InputParticipantInfoStateTearOff(); + +mixin _$InputParticipantInfoState { + @JsonKey(name: 'desired_occupations') + List get desiredOccupations; + @JsonKey(name: 'working_days') + int get workingDays; + String get note; + @JsonKey(name: 'schedule_candidate') + List get scheduleCandidates; + + Map toJson(); + $InputParticipantInfoStateCopyWith get copyWith; +} + +abstract class $InputParticipantInfoStateCopyWith<$Res> { + factory $InputParticipantInfoStateCopyWith(InputParticipantInfoState value, + $Res Function(InputParticipantInfoState) then) = + _$InputParticipantInfoStateCopyWithImpl<$Res>; + $Res call( + {@JsonKey(name: 'desired_occupations') + List desiredOccupations, + @JsonKey(name: 'working_days') + int workingDays, + String note, + @JsonKey(name: 'schedule_candidate') + List scheduleCandidates}); +} + +class _$InputParticipantInfoStateCopyWithImpl<$Res> + implements $InputParticipantInfoStateCopyWith<$Res> { + _$InputParticipantInfoStateCopyWithImpl(this._value, this._then); + + final InputParticipantInfoState _value; + // ignore: unused_field + final $Res Function(InputParticipantInfoState) _then; + + @override + $Res call({ + Object desiredOccupations = freezed, + Object workingDays = freezed, + Object note = freezed, + Object scheduleCandidates = freezed, + }) { + return _then(_value.copyWith( + desiredOccupations: desiredOccupations == freezed + ? _value.desiredOccupations + : desiredOccupations as List, + workingDays: + workingDays == freezed ? _value.workingDays : workingDays as int, + note: note == freezed ? _value.note : note as String, + scheduleCandidates: scheduleCandidates == freezed + ? _value.scheduleCandidates + : scheduleCandidates as List, + )); + } +} + +abstract class _$InputParticipantInfoStateCopyWith<$Res> + implements $InputParticipantInfoStateCopyWith<$Res> { + factory _$InputParticipantInfoStateCopyWith(_InputParticipantInfoState value, + $Res Function(_InputParticipantInfoState) then) = + __$InputParticipantInfoStateCopyWithImpl<$Res>; + @override + $Res call( + {@JsonKey(name: 'desired_occupations') + List desiredOccupations, + @JsonKey(name: 'working_days') + int workingDays, + String note, + @JsonKey(name: 'schedule_candidate') + List scheduleCandidates}); +} + +class __$InputParticipantInfoStateCopyWithImpl<$Res> + extends _$InputParticipantInfoStateCopyWithImpl<$Res> + implements _$InputParticipantInfoStateCopyWith<$Res> { + __$InputParticipantInfoStateCopyWithImpl(_InputParticipantInfoState _value, + $Res Function(_InputParticipantInfoState) _then) + : super(_value, (v) => _then(v as _InputParticipantInfoState)); + + @override + _InputParticipantInfoState get _value => + super._value as _InputParticipantInfoState; + + @override + $Res call({ + Object desiredOccupations = freezed, + Object workingDays = freezed, + Object note = freezed, + Object scheduleCandidates = freezed, + }) { + return _then(_InputParticipantInfoState( + desiredOccupations: desiredOccupations == freezed + ? _value.desiredOccupations + : desiredOccupations as List, + workingDays: + workingDays == freezed ? _value.workingDays : workingDays as int, + note: note == freezed ? _value.note : note as String, + scheduleCandidates: scheduleCandidates == freezed + ? _value.scheduleCandidates + : scheduleCandidates as List, + )); + } +} + +@JsonSerializable() +class _$_InputParticipantInfoState + with DiagnosticableTreeMixin + implements _InputParticipantInfoState { + const _$_InputParticipantInfoState( + {@JsonKey(name: 'desired_occupations') this.desiredOccupations, + @JsonKey(name: 'working_days') this.workingDays, + this.note, + @required @JsonKey(name: 'schedule_candidate') this.scheduleCandidates}) + : assert(scheduleCandidates != null); + + factory _$_InputParticipantInfoState.fromJson(Map json) => + _$_$_InputParticipantInfoStateFromJson(json); + + @override + @JsonKey(name: 'desired_occupations') + final List desiredOccupations; + @override + @JsonKey(name: 'working_days') + final int workingDays; + @override + final String note; + @override + @JsonKey(name: 'schedule_candidate') + final List scheduleCandidates; + + @override + String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) { + return 'InputParticipantInfoState(desiredOccupations: $desiredOccupations, workingDays: $workingDays, note: $note, scheduleCandidates: $scheduleCandidates)'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(DiagnosticsProperty('type', 'InputParticipantInfoState')) + ..add(DiagnosticsProperty('desiredOccupations', desiredOccupations)) + ..add(DiagnosticsProperty('workingDays', workingDays)) + ..add(DiagnosticsProperty('note', note)) + ..add(DiagnosticsProperty('scheduleCandidates', scheduleCandidates)); + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other is _InputParticipantInfoState && + (identical(other.desiredOccupations, desiredOccupations) || + const DeepCollectionEquality() + .equals(other.desiredOccupations, desiredOccupations)) && + (identical(other.workingDays, workingDays) || + const DeepCollectionEquality() + .equals(other.workingDays, workingDays)) && + (identical(other.note, note) || + const DeepCollectionEquality().equals(other.note, note)) && + (identical(other.scheduleCandidates, scheduleCandidates) || + const DeepCollectionEquality() + .equals(other.scheduleCandidates, scheduleCandidates))); + } + + @override + int get hashCode => + runtimeType.hashCode ^ + const DeepCollectionEquality().hash(desiredOccupations) ^ + const DeepCollectionEquality().hash(workingDays) ^ + const DeepCollectionEquality().hash(note) ^ + const DeepCollectionEquality().hash(scheduleCandidates); + + @override + _$InputParticipantInfoStateCopyWith<_InputParticipantInfoState> + get copyWith => + __$InputParticipantInfoStateCopyWithImpl<_InputParticipantInfoState>( + this, _$identity); + + @override + Map toJson() { + return _$_$_InputParticipantInfoStateToJson(this); + } +} + +abstract class _InputParticipantInfoState implements InputParticipantInfoState { + const factory _InputParticipantInfoState( + {@JsonKey(name: 'desired_occupations') + List desiredOccupations, + @JsonKey(name: 'working_days') + int workingDays, + String note, + @required + @JsonKey(name: 'schedule_candidate') + List scheduleCandidates}) = + _$_InputParticipantInfoState; + + factory _InputParticipantInfoState.fromJson(Map json) = + _$_InputParticipantInfoState.fromJson; + + @override + @JsonKey(name: 'desired_occupations') + List get desiredOccupations; + @override + @JsonKey(name: 'working_days') + int get workingDays; + @override + String get note; + @override + @JsonKey(name: 'schedule_candidate') + List get scheduleCandidates; + @override + _$InputParticipantInfoStateCopyWith<_InputParticipantInfoState> get copyWith; +} diff --git a/lib/pages/input_participant_info/input_participant_info_state.g.dart b/lib/pages/input_participant_info/input_participant_info_state.g.dart new file mode 100644 index 0000000..39a971f --- /dev/null +++ b/lib/pages/input_participant_info/input_participant_info_state.g.dart @@ -0,0 +1,34 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'input_participant_info_state.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_InputParticipantInfoState _$_$_InputParticipantInfoStateFromJson( + Map json) { + return _$_InputParticipantInfoState( + desiredOccupations: (json['desired_occupations'] as List) + ?.map((e) => e == null + ? null + : TechnicalStack.fromJson(e as Map)) + ?.toList(), + workingDays: json['working_days'] as int, + note: json['note'] as String, + scheduleCandidates: (json['schedule_candidate'] as List) + ?.map((e) => e == null + ? null + : ScheduleCandidate.fromJson(e as Map)) + ?.toList(), + ); +} + +Map _$_$_InputParticipantInfoStateToJson( + _$_InputParticipantInfoState instance) => + { + 'desired_occupations': instance.desiredOccupations, + 'working_days': instance.workingDays, + 'note': instance.note, + 'schedule_candidate': instance.scheduleCandidates, + }; diff --git a/lib/pages/input_participant_info/widgets/desired_occupation.dart b/lib/pages/input_participant_info/widgets/desired_occupation.dart index 20d5532..3bd99b1 100644 --- a/lib/pages/input_participant_info/widgets/desired_occupation.dart +++ b/lib/pages/input_participant_info/widgets/desired_occupation.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:morning_weakers/pages/input_participant_info/input_participant_info_controller.dart'; class DesiredOccupation extends StatelessWidget { final List desires = ['参加希望職種(第1希望)', '参加希望職種(第2希望)', '参加希望職種(第3希望)' ]; diff --git a/lib/pages/input_participant_info/widgets/schedule_candidate.dart b/lib/pages/input_participant_info/widgets/schedule_candidate.dart index b5cab9c..ff2a216 100644 --- a/lib/pages/input_participant_info/widgets/schedule_candidate.dart +++ b/lib/pages/input_participant_info/widgets/schedule_candidate.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:morning_weakers/pages/input_participant_info/input_participant_info_controller.dart'; class ScheduleCandidate extends StatelessWidget { final List scheduleCandidates = [ @@ -19,7 +21,7 @@ class ScheduleCandidate extends StatelessWidget { children: scheduleCandidates.map( (scheduleCandidate) => CheckboxListTile( value: false, - // onChanged: _handleCheckbox(), +// onChanged: context.read().setDesiredOccupationsState(value), activeColor: Theme.of(context).primaryColor, title: Text(scheduleCandidate), ), diff --git a/lib/pages/input_participant_info/widgets/submit_btn.dart b/lib/pages/input_participant_info/widgets/submit_btn.dart new file mode 100644 index 0000000..42201b0 --- /dev/null +++ b/lib/pages/input_participant_info/widgets/submit_btn.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:morning_weakers/pages/input_participant_info/input_participant_info_controller.dart'; + +class SubmitBtn extends StatelessWidget { + @override + Widget build(BuildContext context) { + return FlatButton( + child: const Text('OK'), + color: Theme.of(context).accentColor, + onPressed: () async { + await context.read().handlePostParticipantInfo(); + }); + } +} diff --git a/lib/pages/input_participant_info/widgets/working_days.dart b/lib/pages/input_participant_info/widgets/working_days.dart index 7cd173a..a4f7b55 100644 --- a/lib/pages/input_participant_info/widgets/working_days.dart +++ b/lib/pages/input_participant_info/widgets/working_days.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:morning_weakers/pages/input_participant_info/input_participant_info_controller.dart'; class WorkingDays extends StatelessWidget { final List workingDays = ['1', '2', '3', '4', '5']; @@ -9,7 +11,7 @@ class WorkingDays extends StatelessWidget { padding: const EdgeInsets.all(8), child: Column( children: [ - const Text('参加可能日程(複数選択可)'), + const Text('稼働可能日数(目安でOKです😃)'), Column( children: workingDays.map( (workingDay) => ListTile(