temp
This commit is contained in:
@@ -2,18 +2,36 @@ import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class ApplicationController extends GetxController {
|
||||
final _storage = GetStorage();
|
||||
|
||||
IconData getThemeIcon() => Get.isDarkMode
|
||||
? Icons.light_mode
|
||||
: Icons.dark_mode;
|
||||
|
||||
void toggleTheme() {
|
||||
Get.changeThemeMode(
|
||||
Get.isDarkMode
|
||||
? ThemeMode.light
|
||||
: ThemeMode.dark
|
||||
);
|
||||
ThemeMode getThemeModeFromStorage() {
|
||||
ThemeMode mode = ThemeMode.system;
|
||||
final themeKey = _storage.read('current_theme_mode');
|
||||
|
||||
if(themeKey == 'light') { mode = ThemeMode.light; }
|
||||
if(themeKey == 'dark') { mode = ThemeMode.dark; }
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
void setThemeMode(ThemeMode themeMode) {
|
||||
Get.changeThemeMode(themeMode);
|
||||
update();
|
||||
}
|
||||
|
||||
void toggleTheme() {
|
||||
_storage.write('current_theme_mode', Get.isDarkMode ? 'light' : 'dark');
|
||||
setThemeMode(
|
||||
Get.isDarkMode
|
||||
? ThemeMode.light
|
||||
: ThemeMode.dark
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:reverse_nn/application/services/schedule.dart';
|
||||
import 'package:reverse_nn/ui/screens/calendar_screen.dart';
|
||||
|
||||
class CalendarScheduleController extends GetxController {
|
||||
Rx<DateTime> date = DateTime.now().copyWith(hour: 12, minute: 00).obs;
|
||||
RxBool loading = false.obs;
|
||||
Rx<List<Map<String, dynamic>>?> schedule = null.obs;
|
||||
|
||||
@override void onReady() {
|
||||
super.onReady();
|
||||
loadSchedule(date.value);
|
||||
}
|
||||
|
||||
void loadSchedule(DateTime date) async {
|
||||
loading = true.obs; update();
|
||||
schedule = (await ScheduleService().getScheduleByDate(date)).obs;
|
||||
loading = false.obs; update();
|
||||
}
|
||||
|
||||
static void openScreen() async {
|
||||
Get.to(() => const CalendarScreen());
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:reverse_nn/application/services/schedule.dart';
|
||||
|
||||
@@ -6,9 +8,13 @@ class ScheduleController extends GetxController {
|
||||
|
||||
@override void onReady() {
|
||||
super.onReady();
|
||||
ScheduleService().getCurrentStatus().then((currentSchedule) {
|
||||
this.currentSchedule = currentSchedule.obs;
|
||||
update();
|
||||
});
|
||||
updateCurrentSchedule();
|
||||
}
|
||||
|
||||
void updateCurrentSchedule() async {
|
||||
currentSchedule = (await ScheduleService().getCurrentStatus()).obs;
|
||||
update();
|
||||
|
||||
Future.delayed(const Duration(seconds: 5), updateCurrentSchedule);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:core';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' show DateFormat;
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -85,7 +86,31 @@ class ScheduleService {
|
||||
|
||||
if(scheduleKey == null) return null;
|
||||
|
||||
return await getScheduleByKey(scheduleKey);
|
||||
List<Map<String, dynamic>>? schedule = await getScheduleByKey(scheduleKey);
|
||||
if(schedule == null) return null;
|
||||
|
||||
int durationOffset = 0;
|
||||
for (var i = 0; i < schedule.length; i++) {
|
||||
final scheduleItem = schedule[i];
|
||||
final int duration = (scheduleItem['duration'] as int);
|
||||
final DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
|
||||
DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
|
||||
durationOffset += duration;
|
||||
|
||||
bool showEndDate = false;
|
||||
if(i == (schedule.length -1)) {
|
||||
final scheduleNextDay = await getScheduleByDate(datetime.copyWith().add(const Duration(days: 1)));
|
||||
final firstScheduleElement = scheduleNextDay?[0];
|
||||
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
|
||||
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
|
||||
showEndDate = true;
|
||||
}
|
||||
}
|
||||
|
||||
schedule[i]['start'] = start;
|
||||
schedule[i]['end'] = end;
|
||||
}
|
||||
return schedule;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getCurrentStatus() async {
|
||||
@@ -101,32 +126,50 @@ class ScheduleService {
|
||||
}
|
||||
|
||||
int durationOffset = 0;
|
||||
for (final Map<String, dynamic> scheduleItem in schedule) {
|
||||
for (var i = 0; i < schedule.length; i++) {
|
||||
final scheduleItem = schedule[i];
|
||||
final int duration = (scheduleItem['duration'] as int);
|
||||
final DateTime start = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset));
|
||||
final DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
|
||||
DateTime end = datetimeStartWithOffset.copyWith().add(Duration(minutes: durationOffset + duration));
|
||||
durationOffset += duration;
|
||||
|
||||
bool showEndDate = false;
|
||||
|
||||
if(i == (schedule.length -1)) {
|
||||
final scheduleNextDay = await getScheduleByDate(now.copyWith().add(const Duration(days: 1)));
|
||||
final firstScheduleElement = scheduleNextDay?[0];
|
||||
if(firstScheduleElement != null && (firstScheduleElement['direction'] as String) == (scheduleItem['direction'] as String)) {
|
||||
end = end.add(Duration(minutes: firstScheduleElement['duration'] as int));
|
||||
showEndDate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(now.isAfter(start) && now.isBefore(end)) {
|
||||
return <String, dynamic>{
|
||||
"direction": scheduleItem['direction'] as String,
|
||||
"start": start,
|
||||
"end": end
|
||||
"end": end,
|
||||
"need_show_end_date": showEndDate,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static String formatDirection(String direction) {
|
||||
switch(direction) {
|
||||
case 'in_city': return 'В город';
|
||||
case 'out_city': return 'Из города';
|
||||
default: return 'Переключение';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// final datetimeStartWithOffset = now.copyWith(hour: 0, minute: 0, second: 0, microsecond: 0, millisecond: 0)
|
||||
// .add(dayOffset);
|
||||
//
|
||||
// final DateTime usedScheduleDatetime = now.isAfter(datetimeStartWithOffset)
|
||||
// ? now
|
||||
// : now.copyWith().subtract(const Duration(days: 1));
|
||||
|
||||
|
||||
static IconData getIconByDirection(String? direction) {
|
||||
switch(direction) {
|
||||
case 'in_city': return Icons.input_outlined;
|
||||
case 'out_city': return Icons.output_outlined;
|
||||
default: return Icons.change_circle_outlined;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user