feat: settings (data save) + new fields

This commit is contained in:
mso7nueh
2024-10-02 13:10:21 +03:00
parent 5442a3f2e2
commit de30b93fa6
11 changed files with 338 additions and 117 deletions

View File

@@ -1,4 +1,5 @@
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/features/settings/entities/settings_entity.dart';
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
import 'package:eatvio_app/locator_service.dart';
@@ -18,18 +19,24 @@ class SettingsScreen extends StatefulWidget {
}
class _SettingsScreenState extends State<SettingsScreen> {
final SettingsCubit settingsCubit = sl<SettingsCubit>()..init();
late bool updatesNotificationsSwitchState;
late bool fillDiaryNotificationsSwitchState;
late bool bedTimeSwitchState;
late bool moodSwitchState;
@override
Widget build(BuildContext context) {
return BlocProvider<SettingsCubit>(
create: (BuildContext context) => sl<SettingsCubit>()..init(),
create: (BuildContext context) => settingsCubit,
child: BlocConsumer<SettingsCubit, SettingsState>(
bloc: settingsCubit,
listener: (BuildContext context, SettingsState state) {
if (state is SettingsStateLoaded) {
updatesNotificationsSwitchState = state.profileSettings.newUpdatesNotifications == 1 ? true : false;
fillDiaryNotificationsSwitchState = state.profileSettings.diaryReminderNotifications == 1 ? true : false;
bedTimeSwitchState = state.profileSettings.isBedtimeFillable == 1 ? true : false;
moodSwitchState = state.profileSettings.isMoodFillable == 1 ? true : false;
}
},
builder: (BuildContext context, SettingsState state) {
@@ -100,10 +107,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'generalInfoScreen',
extra: state.profileDetails,
pathParameters: {
'isPublicProfile': state.profileSettings.isPublicProfile.toString(),
},
extra: SettingsEntity(
profileSettingsModel: state.profileSettings,
profileDetailsModel: state.profileDetails,
settingsCubit: settingsCubit,
),
),
title: 'Общая информация',
),
@@ -111,7 +119,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'physicalFormScreen',
extra: state.profileDetails,
extra: SettingsEntity(
profileSettingsModel: state.profileSettings,
profileDetailsModel: state.profileDetails,
settingsCubit: settingsCubit,
),
),
title: 'Физическая форма',
),
@@ -119,7 +131,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'pressureScreen',
extra: state.profileDetails,
extra: SettingsEntity(
profileSettingsModel: state.profileSettings,
profileDetailsModel: state.profileDetails,
settingsCubit: settingsCubit,
),
),
title: 'Давление',
),
@@ -127,7 +143,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'otherInfoScreen',
extra: state.profileDetails,
extra: SettingsEntity(
profileSettingsModel: state.profileSettings,
profileDetailsModel: state.profileDetails,
settingsCubit: settingsCubit,
),
),
title: 'Прочая информация',
),
@@ -135,10 +155,26 @@ class _SettingsScreenState extends State<SettingsScreen> {
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'physicalActivityScreen',
extra: state.profileDetails,
extra: SettingsEntity(
profileSettingsModel: state.profileSettings,
profileDetailsModel: state.profileDetails,
settingsCubit: settingsCubit,
),
),
title: 'Физическая нагрузка',
),
_divider(context),
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'changePasswordScreen',
extra: SettingsEntity(
profileSettingsModel: state.profileSettings,
profileDetailsModel: state.profileDetails,
settingsCubit: settingsCubit,
),
),
title: 'Сменить пароль',
),
],
);
}
@@ -163,11 +199,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() {
updatesNotificationsSwitchState = !updatesNotificationsSwitchState;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
newUpdatesNotifications: updatesNotificationsSwitchState,
),
);
);
},
title: 'Уведомление о новых обновлениях',
trailing: CupertinoSwitch(
@@ -177,11 +213,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() {
updatesNotificationsSwitchState = newValue;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
newUpdatesNotifications: updatesNotificationsSwitchState,
),
);
);
},
),
),
@@ -191,11 +227,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() {
fillDiaryNotificationsSwitchState = !fillDiaryNotificationsSwitchState;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
diaryReminderNotifications: fillDiaryNotificationsSwitchState,
),
);
);
},
title: 'Напоминание о заполнении дневника',
trailing: CupertinoSwitch(
@@ -205,11 +241,67 @@ class _SettingsScreenState extends State<SettingsScreen> {
setState(() {
fillDiaryNotificationsSwitchState = newValue;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
diaryReminderNotifications: fillDiaryNotificationsSwitchState,
),
);
);
},
),
),
_divider(context),
_tile(
onTap: () {
setState(() {
moodSwitchState = !moodSwitchState;
});
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
isMoodFillable: moodSwitchState,
),
);
},
title: 'Указывать “настроение” в заполнение дневника',
trailing: CupertinoSwitch(
value: moodSwitchState,
activeColor: appTheme.blueA400,
onChanged: (newValue) {
setState(() {
moodSwitchState = newValue;
});
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
isMoodFillable: moodSwitchState,
),
);
},
),
),
_divider(context),
_tile(
onTap: () {
setState(() {
bedTimeSwitchState = !bedTimeSwitchState;
});
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
isBedtimeFillable: bedTimeSwitchState,
),
);
},
title: 'Указывать “отход ко сну” в заполнение дневника',
trailing: CupertinoSwitch(
value: bedTimeSwitchState,
activeColor: appTheme.blueA400,
onChanged: (newValue) {
setState(() {
bedTimeSwitchState = newValue;
});
settingsCubit.updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
isBedtimeFillable: bedTimeSwitchState,
),
);
},
),
),
@@ -264,7 +356,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
color: Colors.white,
height: 1,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),
@@ -293,7 +384,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: TextStyle(
color: Colors.black,
height: 1,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),