mirror of
https://github.com/Iconica-Development/flutter_timetable.git
synced 2025-05-18 19:43:43 +02:00
feat: added table layout
This commit is contained in:
parent
d8b2f55a2d
commit
06609a7537
4 changed files with 114 additions and 3 deletions
|
@ -10,6 +10,6 @@ class TimetableDemo extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(body: Timetable());
|
||||
return const Scaffold(body: Timetable());
|
||||
}
|
||||
}
|
||||
|
|
69
lib/src/table.dart
Normal file
69
lib/src/table.dart
Normal file
|
@ -0,0 +1,69 @@
|
|||
part of timetable;
|
||||
|
||||
class Table extends StatelessWidget {
|
||||
const Table({
|
||||
required this.startHour,
|
||||
required this.endHour,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
final int startHour;
|
||||
final int endHour;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
for (int i = startHour; i <= endHour; i++) ...[
|
||||
SizedBox(
|
||||
height: i == endHour ? 40 : 80,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'${(i).toString().padLeft(2, '0')}:00',
|
||||
),
|
||||
const SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
height: 2,
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
if (i != endHour) ...[
|
||||
const Spacer(),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(
|
||||
left: 40,
|
||||
),
|
||||
height: 2,
|
||||
child: Row(
|
||||
children: [
|
||||
for (int i = 0; i < 25; i++) ...[
|
||||
Container(
|
||||
width:
|
||||
(MediaQuery.of(context).size.width - 40) / 25,
|
||||
height: 2,
|
||||
color: i.isEven
|
||||
? Colors.grey.withOpacity(0.5)
|
||||
: Colors.transparent,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,56 @@
|
|||
part of timetable;
|
||||
|
||||
class Timetable extends StatefulWidget {
|
||||
const Timetable({Key? key}) : super(key: key);
|
||||
const Timetable({
|
||||
this.scrollController,
|
||||
this.startHour = 0,
|
||||
this.endHour = 24,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
/// Hour at which the timetable starts.
|
||||
final int startHour;
|
||||
|
||||
/// Hour at which the timetable ends.
|
||||
final int endHour;
|
||||
|
||||
/// The scroll controller to control the scrolling of the timetable.
|
||||
final ScrollController? scrollController;
|
||||
|
||||
@override
|
||||
State<Timetable> createState() => _TimetableState();
|
||||
}
|
||||
|
||||
class _TimetableState extends State<Timetable> {
|
||||
late ScrollController _scrollController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollController = widget.scrollController ?? ScrollController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (widget.scrollController == null) {
|
||||
_scrollController.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Text('timetable');
|
||||
return SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
controller: _scrollController,
|
||||
child: Stack(
|
||||
children: [
|
||||
Table(
|
||||
startHour: widget.startHour,
|
||||
endHour: widget.endHour,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@ library timetable;
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
part 'src/timetable.dart';
|
||||
part 'src/table.dart';
|
||||
|
|
Loading…
Reference in a new issue