forked from eatvio/eatvio_app
feat: add settings
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import 'package:eatvio_app/core/const.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';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
@@ -13,32 +17,59 @@ class SettingsScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
bool updatesNotificationsSwitchState = true;
|
||||
bool fillDiaryNotificationsSwitchState = true;
|
||||
final SettingsCubit settingsCubit = sl<SettingsCubit>()..init();
|
||||
late bool updatesNotificationsSwitchState;
|
||||
late bool fillDiaryNotificationsSwitchState;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Настройки'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
physics: const BouncingScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
_additionalInfo(),
|
||||
const SizedBox(height: 12),
|
||||
_notifications(),
|
||||
const SizedBox(height: 12),
|
||||
_aboutEatvio(),
|
||||
const SizedBox(height: 12),
|
||||
_becomeConsultantButton(),
|
||||
const SizedBox(height: 8),
|
||||
_deleteAccountButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
return 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;
|
||||
}
|
||||
},
|
||||
builder: (BuildContext context, SettingsState state) {
|
||||
if (state is SettingsStateLoaded) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Настройки'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
physics: const BouncingScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
_additionalInfo(),
|
||||
const SizedBox(height: 12),
|
||||
_notifications(),
|
||||
const SizedBox(height: 12),
|
||||
_aboutEatvio(),
|
||||
const SizedBox(height: 12),
|
||||
_becomeConsultantButton(),
|
||||
const SizedBox(height: 8),
|
||||
_deleteAccountButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (state is SettingsStateError) {
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(child: Text(state.errorMessage)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -59,27 +90,42 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
),
|
||||
_tile(
|
||||
onTap: () => GoRouter.of(context).pushNamed('generalInfoScreen'),
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'generalInfoScreen',
|
||||
extra: (settingsCubit.state as SettingsStateLoaded).profileDetails,
|
||||
),
|
||||
title: 'Общая информация',
|
||||
),
|
||||
_divider(context),
|
||||
_tile(
|
||||
onTap: () => GoRouter.of(context).pushNamed('physicalFormScreen'),
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'physicalFormScreen',
|
||||
extra: (settingsCubit.state as SettingsStateLoaded).profileDetails,
|
||||
),
|
||||
title: 'Физическая форма',
|
||||
),
|
||||
_divider(context),
|
||||
_tile(
|
||||
onTap: () => GoRouter.of(context).pushNamed('pressureScreen'),
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'pressureScreen',
|
||||
extra: (settingsCubit.state as SettingsStateLoaded).profileDetails,
|
||||
),
|
||||
title: 'Давление',
|
||||
),
|
||||
_divider(context),
|
||||
_tile(
|
||||
onTap: () => GoRouter.of(context).pushNamed('otherInfoScreen'),
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'otherInfoScreen',
|
||||
extra: (settingsCubit.state as SettingsStateLoaded).profileDetails,
|
||||
),
|
||||
title: 'Прочая информация',
|
||||
),
|
||||
_divider(context),
|
||||
_tile(
|
||||
onTap: () => GoRouter.of(context).pushNamed('physicalActivityScreen'),
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'physicalActivityScreen',
|
||||
extra: (settingsCubit.state as SettingsStateLoaded).profileDetails,
|
||||
),
|
||||
title: 'Физическая нагрузка',
|
||||
),
|
||||
],
|
||||
@@ -106,6 +152,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
setState(() {
|
||||
updatesNotificationsSwitchState = !updatesNotificationsSwitchState;
|
||||
});
|
||||
settingsCubit.updateProfileSettings(
|
||||
profileSettingsModel: (settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
||||
newUpdatesNotifications: updatesNotificationsSwitchState,
|
||||
),
|
||||
);
|
||||
},
|
||||
title: 'Уведомление о новых обновлениях',
|
||||
trailing: CupertinoSwitch(
|
||||
@@ -115,6 +166,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
setState(() {
|
||||
updatesNotificationsSwitchState = newValue;
|
||||
});
|
||||
settingsCubit.updateProfileSettings(
|
||||
profileSettingsModel: (settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
||||
newUpdatesNotifications: updatesNotificationsSwitchState,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -124,6 +180,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
setState(() {
|
||||
fillDiaryNotificationsSwitchState = !fillDiaryNotificationsSwitchState;
|
||||
});
|
||||
settingsCubit.updateProfileSettings(
|
||||
profileSettingsModel: (settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
||||
diaryReminderNotifications: fillDiaryNotificationsSwitchState,
|
||||
),
|
||||
);
|
||||
},
|
||||
title: 'Напоминание о заполнении дневника',
|
||||
trailing: CupertinoSwitch(
|
||||
@@ -133,6 +194,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
setState(() {
|
||||
fillDiaryNotificationsSwitchState = newValue;
|
||||
});
|
||||
settingsCubit.updateProfileSettings(
|
||||
profileSettingsModel: (settingsCubit.state as SettingsStateLoaded).profileSettings.copyWith(
|
||||
diaryReminderNotifications: fillDiaryNotificationsSwitchState,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user