v1.1.0+3
This commit is contained in:
@@ -2,6 +2,7 @@ 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/components/schedule_item_component.dart';
|
||||
import 'package:reverse_nn/ui/layouts/application_layout.dart';
|
||||
import 'package:intl/intl.dart' show DateFormat;
|
||||
|
||||
@@ -15,40 +16,42 @@ class CalendarScreen extends StatelessWidget {
|
||||
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,
|
||||
onSelectDate: controller.goToConcreteDay,
|
||||
onTapPrev: controller.goToPrevDay,
|
||||
onTapNext: controller.goToNextDay,
|
||||
),
|
||||
|
||||
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) const Padding(
|
||||
padding: EdgeInsets.all(40),
|
||||
child: Center(child: CircularProgressIndicator())
|
||||
if(!controller.loading.value && controller.schedule.value != null) Expanded(
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: controller.schedule.value!
|
||||
.map((item) => ScheduleItemComponent(item: item))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
|
||||
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);
|
||||
// }),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -57,7 +60,10 @@ class CalendarScreen extends StatelessWidget {
|
||||
|
||||
class _SelectedDateWidget extends StatelessWidget {
|
||||
final DateTime date;
|
||||
const _SelectedDateWidget({super.key, required this.date});
|
||||
final void Function(DateTime)? onSelectDate;
|
||||
final void Function()? onTapPrev;
|
||||
final void Function()? onTapNext;
|
||||
const _SelectedDateWidget({super.key, required this.date, this.onSelectDate, this.onTapPrev, this.onTapNext});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -68,47 +74,36 @@ class _SelectedDateWidget extends StatelessWidget {
|
||||
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,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
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),
|
||||
],
|
||||
))
|
||||
],
|
||||
GestureDetector(
|
||||
onTap: () { onTapPrev?.call(); },
|
||||
child: const SizedBox(
|
||||
width: 40,
|
||||
child: Center(child: Icon(Icons.arrow_left, size: 40)),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {_openCalendar(context); },
|
||||
child: Center(
|
||||
child: Text(
|
||||
formatDate(date),
|
||||
style: Theme.of(context).textTheme.displaySmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () { onTapNext?.call(); },
|
||||
child: const SizedBox(
|
||||
width: 40,
|
||||
child: Center(child: Icon(Icons.arrow_right, size: 40)),
|
||||
),
|
||||
),
|
||||
]
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -116,6 +111,19 @@ class _ScheduleItemWidget extends StatelessWidget {
|
||||
String formatDate(DateTime date) {
|
||||
return DateFormat('dd.MM.yyyy').format(date);
|
||||
}
|
||||
|
||||
void _openCalendar(BuildContext context) async {
|
||||
DateTime now = DateTime.now();
|
||||
DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: now,
|
||||
firstDate: DateTime(2024, 8, 1, 12),
|
||||
lastDate: DateTime(2025, 12, 31, 12),
|
||||
locale: const Locale('ru')
|
||||
);
|
||||
|
||||
if(picked != null) { onSelectDate?.call(picked); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user