Initial commit
This commit is contained in:
16
lib/widgets/loader_widget.dart
Normal file
16
lib/widgets/loader_widget.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoaderWidget extends StatelessWidget {
|
||||
const LoaderWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator()
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
94
lib/widgets/schedule_element_widget.dart
Normal file
94
lib/widgets/schedule_element_widget.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:reverse_nn/enums/direction.dart';
|
||||
import 'package:reverse_nn/enums/schedule.dart';
|
||||
import 'package:sprintf/sprintf.dart';
|
||||
|
||||
class CurrentReversWidget extends StatelessWidget {
|
||||
const CurrentReversWidget({super.key, required this.scheduleElement});
|
||||
|
||||
final ScheduleElement scheduleElement;
|
||||
|
||||
IconData _getIconData() {
|
||||
switch(scheduleElement.direction) {
|
||||
case Direction.inCity: return Icons.arrow_upward;
|
||||
case Direction.outCity: return Icons.arrow_downward;
|
||||
case Direction.change: return Icons.cancel_outlined;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
||||
color: Theme.of(context).colorScheme.primaryContainer
|
||||
),
|
||||
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
|
||||
children: [
|
||||
Icon(_getIconData(), size: 56.0),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Реверс: ${scheduleElement.direction.displayName}', style: const TextStyle(fontSize: 20)),
|
||||
Text('${scheduleElement.getStartedTimeString()} - ${scheduleElement.getEndedTimeString()}', style: const TextStyle(fontSize: 36)),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
// child: Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: [
|
||||
// const Text('Текущий статус реверса:', style: TextStyle(
|
||||
// color: Colors.black87,
|
||||
// fontSize: 14.0
|
||||
// )),
|
||||
// Text(scheduleElement.direction.displayName, style: const TextStyle(
|
||||
// color: Colors.black,
|
||||
// fontSize: 32.0
|
||||
// ),),
|
||||
// ],
|
||||
// ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduledReversWidget extends StatelessWidget {
|
||||
const ScheduledReversWidget({super.key, required this.scheduleElement});
|
||||
|
||||
final ScheduleElement scheduleElement;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8),
|
||||
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
||||
color: Theme.of(context).colorScheme.secondaryContainer
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(sprintf('Следующий статус в %02i:%02i - %s', [
|
||||
scheduleElement.startHours,
|
||||
scheduleElement.startMinutes,
|
||||
scheduleElement.direction.displayName
|
||||
])),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
45
lib/widgets/schedule_widget.dart
Normal file
45
lib/widgets/schedule_widget.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:reverse_nn/enums/schedule.dart';
|
||||
import 'package:reverse_nn/utils/scheduler.dart';
|
||||
import 'package:reverse_nn/widgets/loader_widget.dart';
|
||||
import 'package:reverse_nn/widgets/schedule_element_widget.dart';
|
||||
|
||||
class ScheduleWidget extends StatefulWidget {
|
||||
const ScheduleWidget({super.key});
|
||||
|
||||
@override
|
||||
State<ScheduleWidget> createState() => _ScheduleWidgetState();
|
||||
}
|
||||
|
||||
class _ScheduleWidgetState extends State<ScheduleWidget> {
|
||||
bool _loading = true;
|
||||
List<ScheduleElement> _schedule = List.empty();
|
||||
|
||||
void loadScheduleData() async {
|
||||
setState(() { _loading = true; });
|
||||
setState(() { _schedule = Scheduler.getScheduleList(); });
|
||||
setState(() { _loading = false; });
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
loadScheduleData();
|
||||
|
||||
Future.delayed(const Duration(seconds: 15), () => loadScheduleData());
|
||||
|
||||
return _loading && _schedule.isNotEmpty ? const LoaderWidget() : ListView.separated(
|
||||
scrollDirection: Axis.vertical,
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.all(10),
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(height: index == 0 ? 10 : 4);
|
||||
},
|
||||
itemCount: _schedule.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
if(i == 0) { return CurrentReversWidget(scheduleElement: _schedule[i]); }
|
||||
return ScheduledReversWidget(scheduleElement: _schedule[i]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user