silence interval now works
This commit is contained in:
parent
d83625521b
commit
74b0630328
|
|
@ -36,11 +36,11 @@ class AppInitializer {
|
|||
} else {
|
||||
await StorageService.setValue(
|
||||
key: 'notificationTimeRangeStart',
|
||||
value: '00:00',
|
||||
value: '0',
|
||||
);
|
||||
await StorageService.setValue(
|
||||
key: 'notificationTimeRangeEnd',
|
||||
value: '23:59',
|
||||
value: '24',
|
||||
);
|
||||
await StorageService.setValue(
|
||||
key: 'fontFamily',
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:didvan/models/view/action_sheet_data.dart';
|
|||
import 'package:didvan/models/view/app_bar_data.dart';
|
||||
import 'package:didvan/providers/theme_provider.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
import 'package:didvan/utils/date_time.dart';
|
||||
import 'package:didvan/views/home/settings/general_settings/settings_state.dart';
|
||||
import 'package:didvan/views/home/widgets/menu_item.dart';
|
||||
import 'package:didvan/views/widgets/didvan/card.dart';
|
||||
|
|
@ -36,6 +37,9 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
return 'کوچک';
|
||||
}
|
||||
|
||||
int _intervalStart = 0;
|
||||
int _intervalEnd = 24;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<GeneralSettingsState>(
|
||||
|
|
@ -50,7 +54,13 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
title: 'زمان دریافت اعلان',
|
||||
onTap: () => _pickTimeRange(context),
|
||||
icon: DidvanIcons.notification_regular,
|
||||
suffix: state.notificationTimeRange[0],
|
||||
suffix: DateTimeUtils.normalizeTimeDuration(
|
||||
Duration(minutes: state.notificationTimeRange[1]),
|
||||
) +
|
||||
' - ' +
|
||||
DateTimeUtils.normalizeTimeDuration(
|
||||
Duration(minutes: state.notificationTimeRange[0]),
|
||||
),
|
||||
),
|
||||
),
|
||||
const ItemTitle(
|
||||
|
|
@ -183,6 +193,9 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
}
|
||||
|
||||
Future<void> _pickTimeRange(BuildContext context) async {
|
||||
final state = context.read<GeneralSettingsState>();
|
||||
_intervalStart = state.notificationTimeRange[0];
|
||||
_intervalEnd = state.notificationTimeRange[1];
|
||||
ActionSheetUtils.showBottomSheet(
|
||||
data: ActionSheetData(
|
||||
content: Row(
|
||||
|
|
@ -198,6 +211,9 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
),
|
||||
title: 'زمان دریافت اعلان',
|
||||
titleIcon: DidvanIcons.notification_regular,
|
||||
onConfirmed: () {
|
||||
state.notificationTimeRange = [_intervalStart, _intervalEnd];
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -222,7 +238,9 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
color: Theme.of(context).colorScheme.border,
|
||||
),
|
||||
),
|
||||
child: DidvanText(state.notificationTimeRange[index]),
|
||||
child: DidvanText(DateTimeUtils.normalizeTimeDuration(
|
||||
Duration(minutes: index == 0 ? _intervalStart : _intervalEnd),
|
||||
)),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -230,7 +248,6 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
}
|
||||
|
||||
Future<void> _openTimePicker(BuildContext context, int index) async {
|
||||
final GeneralSettingsState state = context.read<GeneralSettingsState>();
|
||||
await Navigator.of(context).push(
|
||||
showPicker(
|
||||
okText: 'تایید',
|
||||
|
|
@ -240,8 +257,9 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
cancelStyle: Theme.of(context).textTheme.bodyText2!,
|
||||
unselectedColor: Theme.of(context).colorScheme.text,
|
||||
blurredBackground: true,
|
||||
hourLabel: 'ساعت',
|
||||
minuteLabel: 'دقیقه',
|
||||
disableMinute: true,
|
||||
hourLabel: ':',
|
||||
minuteLabel: '',
|
||||
is24HrFormat: true,
|
||||
iosStylePicker: true,
|
||||
minuteInterval: MinuteInterval.FIFTEEN,
|
||||
|
|
@ -249,12 +267,11 @@ class _GeneralSettingsState extends State<GeneralSettings> {
|
|||
value: const TimeOfDay(hour: 0, minute: 0),
|
||||
themeData: Theme.of(context),
|
||||
onChange: (time) {
|
||||
state.notificationTimeRange = state.notificationTimeRange
|
||||
..replaceRange(
|
||||
index,
|
||||
index + 1,
|
||||
['${time.hour}:${time.minute}'],
|
||||
);
|
||||
if (index == 0) {
|
||||
_intervalStart = time.hour;
|
||||
return;
|
||||
}
|
||||
_intervalEnd = time.hour;
|
||||
},
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/providers/core_provider.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
|
||||
class GeneralSettingsState extends CoreProvier {
|
||||
|
|
@ -7,24 +9,26 @@ class GeneralSettingsState extends CoreProvier {
|
|||
getSettingsFromStorage();
|
||||
}
|
||||
|
||||
List _notificationTimeRange = ['00:00', '23:59'];
|
||||
List<int> _notificationTimeRange = [0, 24];
|
||||
String _fontFamily = 'Dana-FA';
|
||||
double _fontSizeScale = 1;
|
||||
String _brightness = 'light';
|
||||
|
||||
set notificationTimeRange(List value) {
|
||||
set notificationTimeRange(List<int> value) {
|
||||
_notificationTimeRange = value;
|
||||
StorageService.setValue(
|
||||
key: 'notificationTimeRangeStart',
|
||||
value: value[0],
|
||||
);
|
||||
StorageService.setValue(
|
||||
key: 'notificationTimeRangeStart',
|
||||
key: 'notificationTimeRangeEnd',
|
||||
value: value[1],
|
||||
);
|
||||
notifyListeners();
|
||||
_setSilenceInterval();
|
||||
}
|
||||
|
||||
List get notificationTimeRange => _notificationTimeRange;
|
||||
List<int> get notificationTimeRange => _notificationTimeRange;
|
||||
|
||||
set fontFamily(String value) {
|
||||
_fontFamily = value;
|
||||
|
|
@ -59,12 +63,22 @@ class GeneralSettingsState extends CoreProvier {
|
|||
|
||||
String get brightness => _brightness;
|
||||
|
||||
Future<void> _setSilenceInterval() async {
|
||||
final service = RequestService(RequestHelper.silenceInterval, body: {
|
||||
'start': notificationTimeRange[0],
|
||||
'end': notificationTimeRange[1]
|
||||
});
|
||||
await service.put();
|
||||
}
|
||||
|
||||
Future<void> getSettingsFromStorage() async {
|
||||
appState = AppState.busy;
|
||||
_notificationTimeRange[0] =
|
||||
await StorageService.getValue(key: 'notificationTimeRangeStart');
|
||||
_notificationTimeRange[1] =
|
||||
await StorageService.getValue(key: 'notificationTimeRangeEnd');
|
||||
_notificationTimeRange[0] = int.parse(
|
||||
await StorageService.getValue(key: 'notificationTimeRangeStart'),
|
||||
);
|
||||
_notificationTimeRange[1] = int.parse(
|
||||
await StorageService.getValue(key: 'notificationTimeRangeEnd'),
|
||||
);
|
||||
_fontFamily = await StorageService.getValue(key: 'fontFamily');
|
||||
_brightness = await StorageService.getValue(key: 'brightness');
|
||||
final scale = await StorageService.getValue(key: 'fontSizeScale');
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ packages:
|
|||
name: day_night_time_picker
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.4+1"
|
||||
version: "1.0.5"
|
||||
expandable_bottom_sheet:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ dependencies:
|
|||
pin_code_fields: ^7.3.0
|
||||
rive: ^0.7.33
|
||||
image_picker: ^0.8.4+4
|
||||
day_night_time_picker: ^1.0.3+1
|
||||
day_night_time_picker: ^1.0.5
|
||||
path_provider: ^2.0.8
|
||||
flutter_spinkit: ^5.1.0
|
||||
flutter_svg: ^1.0.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue