2022-11-01 09:46:23 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-08-24 09:39:36 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:timetable/timetable.dart';
|
|
|
|
|
|
|
|
void main() {
|
2022-08-26 09:04:08 +02:00
|
|
|
runApp(const MaterialApp(home: TimetableDemo()));
|
2022-08-24 09:39:36 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 12:03:32 +02:00
|
|
|
class TimetableDemo extends StatefulWidget {
|
2022-08-24 09:39:36 +02:00
|
|
|
const TimetableDemo({Key? key}) : super(key: key);
|
|
|
|
|
2022-08-24 12:03:32 +02:00
|
|
|
@override
|
|
|
|
State<TimetableDemo> createState() => _TimetableDemoState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TimetableDemoState extends State<TimetableDemo> {
|
2022-08-24 16:02:07 +02:00
|
|
|
bool _grouped = false;
|
2022-11-08 10:33:48 +01:00
|
|
|
bool _horizontal = true;
|
2022-08-24 12:03:32 +02:00
|
|
|
final ScrollController _scrollController = ScrollController();
|
|
|
|
final List<TimeBlock> blocks = [
|
2022-08-24 16:02:07 +02:00
|
|
|
TimeBlock(
|
2022-08-26 09:04:08 +02:00
|
|
|
start: const TimeOfDay(hour: 8, minute: 0),
|
|
|
|
end: const TimeOfDay(hour: 9, minute: 0),
|
2022-11-22 16:06:34 +01:00
|
|
|
child: Container(
|
|
|
|
color: Colors.red,
|
|
|
|
child: const Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: const Text(
|
|
|
|
'Exercise',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
2022-11-08 10:33:48 +01:00
|
|
|
),
|
2022-11-22 16:06:34 +01:00
|
|
|
id: 1,
|
2022-08-24 16:02:07 +02:00
|
|
|
),
|
2022-08-24 17:14:50 +02:00
|
|
|
TimeBlock(
|
2022-11-22 16:06:34 +01:00
|
|
|
start: const TimeOfDay(hour: 10, minute: 0),
|
|
|
|
end: const TimeOfDay(hour: 12, minute: 0),
|
|
|
|
child: Container(
|
|
|
|
color: Colors.orange,
|
|
|
|
child: const Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: const Text(
|
|
|
|
'Brunch',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
2022-11-08 10:33:48 +01:00
|
|
|
),
|
2022-11-22 16:06:34 +01:00
|
|
|
childDimension: 300,
|
|
|
|
id: 3,
|
2022-08-24 17:14:50 +02:00
|
|
|
),
|
2022-11-08 10:33:48 +01:00
|
|
|
TimeBlock(
|
2022-11-22 16:06:34 +01:00
|
|
|
start: const TimeOfDay(hour: 14, minute: 0),
|
|
|
|
end: const TimeOfDay(hour: 15, minute: 0),
|
|
|
|
id: 100,
|
|
|
|
child: const SizedBox(
|
|
|
|
height: 300,
|
|
|
|
child: Text(
|
|
|
|
'Clean Living Room',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
)),
|
2022-11-08 10:33:48 +01:00
|
|
|
TimeBlock(
|
2022-11-22 16:06:34 +01:00
|
|
|
start: const TimeOfDay(hour: 14, minute: 0),
|
|
|
|
end: const TimeOfDay(hour: 15, minute: 0),
|
|
|
|
id: 101,
|
|
|
|
child: const SizedBox(
|
|
|
|
height: 200,
|
|
|
|
child: Text(
|
|
|
|
'Clean Kitchen',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
)),
|
2022-11-08 10:33:48 +01:00
|
|
|
TimeBlock(
|
|
|
|
start: const TimeOfDay(hour: 14, minute: 0),
|
|
|
|
end: const TimeOfDay(hour: 15, minute: 0),
|
|
|
|
id: 102,
|
2022-11-22 16:06:34 +01:00
|
|
|
child: const SizedBox(
|
|
|
|
height: 100,
|
|
|
|
child: Text(
|
|
|
|
'Clean Bathroom',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
2022-11-08 10:33:48 +01:00
|
|
|
),
|
|
|
|
TimeBlock(
|
|
|
|
start: const TimeOfDay(hour: 14, minute: 0),
|
|
|
|
end: const TimeOfDay(hour: 15, minute: 0),
|
|
|
|
id: 103,
|
2022-11-22 16:06:34 +01:00
|
|
|
child: const SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Text(
|
|
|
|
'Clean Toilet',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
2022-11-08 10:33:48 +01:00
|
|
|
),
|
2022-08-24 12:03:32 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_scrollController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
2022-08-24 09:39:36 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-18 14:22:05 +01:00
|
|
|
var size = MediaQuery.of(context).size;
|
2022-08-24 12:03:32 +02:00
|
|
|
return Scaffold(
|
2022-11-22 16:06:34 +01:00
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Timetable Demo'),
|
|
|
|
),
|
2022-11-18 14:22:05 +01:00
|
|
|
// backgroundColor: Colors.green,
|
2022-11-22 16:06:34 +01:00
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2022-11-18 14:22:05 +01:00
|
|
|
children: [
|
2022-11-22 16:06:34 +01:00
|
|
|
// toggle between horizontal and vertical
|
|
|
|
const Text('Axis horizontal'),
|
|
|
|
Switch(
|
|
|
|
value: _horizontal,
|
|
|
|
onChanged: (value) {
|
2022-11-18 14:22:05 +01:00
|
|
|
setState(() {
|
2022-11-22 16:06:34 +01:00
|
|
|
_horizontal = value;
|
2022-11-18 14:22:05 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2022-11-22 16:06:34 +01:00
|
|
|
// toggle between grouped and ungrouped blocks
|
2022-11-18 14:22:05 +01:00
|
|
|
const Text('Grouped'),
|
|
|
|
Switch(
|
|
|
|
value: _grouped,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
_grouped = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-11-22 16:06:34 +01:00
|
|
|
),
|
|
|
|
Container(
|
|
|
|
color: Colors.white,
|
|
|
|
child: Timetable(
|
|
|
|
size: Size(size.width, size.height * 0.64),
|
|
|
|
tableDirection: _horizontal ? Axis.horizontal : Axis.vertical,
|
|
|
|
startHour: 3,
|
|
|
|
endHour: 24,
|
|
|
|
timeBlocks: blocks,
|
|
|
|
scrollController: _scrollController,
|
|
|
|
combineBlocks: true,
|
|
|
|
mergeBlocks: _grouped,
|
|
|
|
theme: const TableTheme(
|
|
|
|
tablePaddingStart: 0,
|
|
|
|
blockPaddingBetween: 10,
|
2022-11-08 10:33:48 +01:00
|
|
|
),
|
2022-11-18 14:22:05 +01:00
|
|
|
),
|
2022-11-22 16:06:34 +01:00
|
|
|
),
|
|
|
|
],
|
2022-08-24 12:03:32 +02:00
|
|
|
),
|
|
|
|
);
|
2022-08-24 09:39:36 +02:00
|
|
|
}
|
|
|
|
}
|