Files
eatvio_app/lib/features/settings/presentation/pages/settings_screen.dart
2024-09-30 17:44:25 +03:00

343 lines
10 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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:rive/rive.dart';
import 'package:url_launcher/url_launcher.dart';
class SettingsScreen extends StatefulWidget {
const SettingsScreen({super.key});
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
late bool updatesNotificationsSwitchState;
late bool fillDiaryNotificationsSwitchState;
@override
Widget build(BuildContext context) {
return BlocProvider<SettingsCubit>(
create: (BuildContext context) => sl<SettingsCubit>()..init(),
child: BlocConsumer<SettingsCubit, SettingsState>(
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(state),
const SizedBox(height: 12),
_notifications(state),
const SizedBox(height: 12),
_aboutEatvio(state),
const SizedBox(height: 12),
_becomeConsultantButton(state),
const SizedBox(height: 8),
_deleteAccountButton(state),
],
),
),
);
}
if (state is SettingsStateError) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(16),
child: Center(child: Text(state.errorMessage)),
),
);
}
return Scaffold(
body: Center(
child: SizedBox(
height: 32,
width: 32,
child: RiveAnimation.asset(
'assets/rive_animations/loading.riv',
),
),
),
);
},
),
);
}
_additionalInfo(SettingsStateLoaded state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Дополнительаная информация',
style: TextStyle(
fontSize: 16,
height: 1,
color: Colors.grey,
fontFamily: 'Mulish',
),
),
),
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'generalInfoScreen',
extra: state.profileDetails,
pathParameters: {
'isPublicProfile': state.profileSettings.isPublicProfile.toString(),
},
),
title: 'Общая информация',
),
_divider(context),
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'physicalFormScreen',
extra: state.profileDetails,
),
title: 'Физическая форма',
),
_divider(context),
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'pressureScreen',
extra: state.profileDetails,
),
title: 'Давление',
),
_divider(context),
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'otherInfoScreen',
extra: state.profileDetails,
),
title: 'Прочая информация',
),
_divider(context),
_tile(
onTap: () => GoRouter.of(context).pushNamed(
'physicalActivityScreen',
extra: state.profileDetails,
),
title: 'Физическая нагрузка',
),
],
);
}
_notifications(SettingsStateLoaded state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Уведомления',
style: TextStyle(
fontSize: 16,
height: 1,
color: Colors.grey,
),
),
),
_tile(
onTap: () {
setState(() {
updatesNotificationsSwitchState = !updatesNotificationsSwitchState;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
newUpdatesNotifications: updatesNotificationsSwitchState,
),
);
},
title: 'Уведомление о новых обновлениях',
trailing: CupertinoSwitch(
value: updatesNotificationsSwitchState,
activeColor: appTheme.blueA400,
onChanged: (newValue) {
setState(() {
updatesNotificationsSwitchState = newValue;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
newUpdatesNotifications: updatesNotificationsSwitchState,
),
);
},
),
),
_divider(context),
_tile(
onTap: () {
setState(() {
fillDiaryNotificationsSwitchState = !fillDiaryNotificationsSwitchState;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
diaryReminderNotifications: fillDiaryNotificationsSwitchState,
),
);
},
title: 'Напоминание о заполнении дневника',
trailing: CupertinoSwitch(
value: fillDiaryNotificationsSwitchState,
activeColor: appTheme.blueA400,
onChanged: (newValue) {
setState(() {
fillDiaryNotificationsSwitchState = newValue;
});
context.read<SettingsCubit>().updateProfileSettings(
profileSettingsModel: state.profileSettings.copyWith(
diaryReminderNotifications: fillDiaryNotificationsSwitchState,
),
);
},
),
),
],
);
}
_aboutEatvio(SettingsStateLoaded state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'О Eatvio',
style: TextStyle(
fontSize: 16,
height: 1,
color: Colors.grey,
),
),
),
_tile(
title: 'О компании',
onTap: () async => await launchUrl(Uri.parse(baseUrl + '/ru/company-details')),
),
_divider(context),
_tile(
title: 'Пользовательское соглашение',
onTap: () async => await launchUrl(Uri.parse(baseUrl + '/oferta_bs.pdf')),
),
],
);
}
_becomeConsultantButton(SettingsStateLoaded state) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: InkWell(
onTap: () {},
borderRadius: BorderRadius.circular(20),
child: Ink(
height: 52,
width: MediaQuery.of(context).size.width - 16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: appTheme.blueA400,
),
child: Center(
child: Text(
'Стать консультантом',
style: TextStyle(
color: Colors.white,
height: 1,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),
),
),
),
);
}
_deleteAccountButton(SettingsStateLoaded state) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: InkWell(
onTap: () {},
borderRadius: BorderRadius.circular(20),
child: Ink(
height: 52,
width: MediaQuery.of(context).size.width - 16,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xFFEAEAEA),
),
child: Center(
child: Text(
'Удалить аккаунт',
style: TextStyle(
color: Colors.black,
height: 1,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),
),
),
),
);
}
_tile({
required String title,
required Function() onTap,
Widget? trailing,
}) {
return ListTile(
onTap: onTap,
title: Text(
title,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
height: 1,
),
),
trailing: trailing ??
Icon(
Icons.arrow_forward_ios_rounded,
size: 12,
color: Colors.black38,
),
);
}
_divider(BuildContext context) {
return Center(
child: Container(
height: 0.4,
width: MediaQuery.of(context).size.width - 32,
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(16),
),
),
);
}
}