This commit is contained in:
2024-12-16 02:35:30 +03:00
parent 3800860d02
commit de1d6c85e5
12 changed files with 351 additions and 39 deletions

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart' show DateFormat;
import 'package:reverse_nn/application/controllers/schedule_controller.dart';
import 'package:reverse_nn/application/services/schedule.dart';
class CurrentStatusComponent extends StatelessWidget {
const CurrentStatusComponent({super.key});
@@ -22,15 +23,16 @@ class CurrentStatusComponent extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Icon(Icons.exit_to_app, size: 96),
Icon(ScheduleService.getIconByDirection(scheduleController.currentSchedule.value?['direction']), size: 96),
const SizedBox(width: 16),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if(scheduleController.currentSchedule.value != null) ...[
Text(scheduleController.currentSchedule.value?['direction'] ?? '', style: Theme.of(context).textTheme.headlineLarge),
Text('C ${formatDate(scheduleController.currentSchedule.value?['start'])} До ${formatDate(scheduleController.currentSchedule.value!['end'])}', style: Theme.of(context).textTheme.titleMedium)
Text(ScheduleService.formatDirection(scheduleController.currentSchedule.value?['direction'] ?? ''), style: Theme.of(context).textTheme.headlineLarge),
Text('C\t\t\t\t${formatDate(scheduleController.currentSchedule.value?['start'], showDate: scheduleController.currentSchedule.value!['need_show_end_date'])}', style: Theme.of(context).textTheme.titleMedium),
Text('До\t${formatDate(scheduleController.currentSchedule.value!['end'], showDate: scheduleController.currentSchedule.value!['need_show_end_date'])}', style: Theme.of(context).textTheme.titleMedium),
]
],
)
@@ -42,6 +44,6 @@ class CurrentStatusComponent extends StatelessWidget {
);
}
String formatDate(DateTime date) => DateFormat('hh:mm').format(date);
String formatDate(DateTime date, {bool showDate = false}) => DateFormat(showDate ? 'hh:mm (dd.MM.yyyy)' : 'hh:mm').format(date);
}

View File

@@ -0,0 +1,121 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:reverse_nn/application/controllers/calendar_schedule_controller.dart';
import 'package:reverse_nn/application/services/schedule.dart';
import 'package:reverse_nn/ui/layouts/application_layout.dart';
import 'package:intl/intl.dart' show DateFormat;
class CalendarScreen extends StatelessWidget {
const CalendarScreen({super.key});
@override
Widget build(BuildContext context) {
final CalendarScheduleController controller = Get.put(CalendarScheduleController());
return ApplicationLayout(
body: RefreshIndicator(
onRefresh: () async { controller.loadSchedule(controller.date.value); },
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: GetBuilder<CalendarScheduleController>(
builder: (controller) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_SelectedDateWidget(date: controller.date.value),
if(controller.loading.value) const Padding(
padding: EdgeInsets.all(40),
child: Center(child: CircularProgressIndicator())
),
if(!controller.loading.value && controller.schedule.value != null) ListView.builder(
shrinkWrap: true,
itemBuilder: (_, index) => _ScheduleItemWidget(item: controller.schedule.value![index]),
itemCount: controller.schedule.value!.length
),
// if(!controller.loading.value && controller.schedule.value != null) ...controller.schedule.value!.map((element) {
// return _ScheduleItemWidget(item: element);
// }),
],
),
);
}
),
),
),
);
}
}
class _SelectedDateWidget extends StatelessWidget {
final DateTime date;
const _SelectedDateWidget({super.key, required this.date});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: Text(
formatDate(date),
style: Theme.of(context).textTheme.displayMedium,
),
);
}
String formatDate(DateTime date) {
return DateFormat('dd.MM.yyyy').format(date);
}
}
class _ScheduleItemWidget extends StatelessWidget {
final Map<String, dynamic> item;
const _ScheduleItemWidget({super.key, required this.item});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 10),
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(ScheduleService.getIconByDirection(item['direction'] as String), size: 56),
Expanded(child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(ScheduleService.formatDirection(item['direction'] ?? ''), style: Theme.of(context).textTheme.headlineLarge),
Text('C\t\t\t\t${formatDate(item['start'])}', style: Theme.of(context).textTheme.titleMedium),
Text('До\t${formatDate(item['end'])}', style: Theme.of(context).textTheme.titleMedium),
],
))
],
),
);
}
String formatDate(DateTime date) {
return DateFormat('dd.MM.yyyy').format(date);
}
}

View File

@@ -2,6 +2,7 @@ import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:reverse_nn/application/controllers/calendar_schedule_controller.dart';
import 'package:reverse_nn/application/controllers/home_controller.dart';
import 'package:reverse_nn/application/services/schedule.dart';
import 'package:reverse_nn/ui/components/current_status_component.dart';
@@ -28,14 +29,9 @@ class HomeScreen extends GetWidget<HomeController> {
mainAxisSpacing: 10,
crossAxisSpacing: 10,
),
children: [
GridMenuItem(icon: Icons.calendar_month, label: 'Расписание', onTap: () {
// log(DateTime(2024, 8, 1, 0, 0, 0).toIso8601String());
ScheduleService().getCurrentStatus().then((val) {
log(val.toString());
});
}),
const GridMenuItem(icon: Icons.monetization_on, label: 'Поддержать автора'),
children: const [
GridMenuItem(icon: Icons.calendar_month, label: 'Расписание', onTap: CalendarScheduleController.openScreen),
// const GridMenuItem(icon: Icons.monetization_on, label: 'Поддержать автора'),
// GridMenuItem(),
// GridMenuItem(),
]