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