feat: added table layout

This commit is contained in:
Freek van de Ven 2022-08-24 11:01:50 +02:00
parent d8b2f55a2d
commit 06609a7537
4 changed files with 114 additions and 3 deletions

View file

@ -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
View 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(),
],
],
),
),
],
],
);
}
}

View file

@ -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,
),
],
),
);
}
}

View file

@ -3,3 +3,4 @@ library timetable;
import 'package:flutter/material.dart';
part 'src/timetable.dart';
part 'src/table.dart';