Skip to content

Commit

Permalink
✨ Add table SPlan (#114)
Browse files Browse the repository at this point in the history
Adds an SPlan view as a table for tablets.

Commits:
* Add table SPlan
  • Loading branch information
strifel authored Feb 20, 2021
1 parent 56bb4a4 commit 89ba6b9
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 36 deletions.
135 changes: 106 additions & 29 deletions lib/components/timetable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../dynimports/apifile/dynapifile.dart'
if (dart.library.html) '../dynimports/apifile/webapifile.dart'
if (dart.library.io) '../dynimports/apifile/mobileapifile.dart' as apifile;
import 'helpers.dart';
import 'user.dart';


// ignore: must_be_immutable
Expand Down Expand Up @@ -50,27 +51,55 @@ class TimeTableView extends StatelessWidget {

@override
Widget build(BuildContext context) {
return TabBarView(
children: [1,2,3,4,5].map((day) => ListView(
children: splan.lessons.where((e) => e.dayOfWeek == day).map((e) => TimeTableListEntry(e, isTeacher: isTeacher, hideTeacher: hideTeacher),
if (MediaQuery.of(context).size.width <= SPLAN_PHONE_WIDTH) {
return TabBarView(
children: [1,2,3,4,5].map((day) =>
ListView(children: splan.lessons.where((e) => e.dayOfWeek == day).map((e) =>
TimeTableListEntry(e, isTeacher: isTeacher, hideTeacher: hideTeacher)
).toList())
).toList(),
)).toList(),
);
);
} else {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [1,2,3,4,5].map((day) =>
Container(child: ListView(children: splan.lessons.where((e) => e.dayOfWeek == day).map((e) =>
TimeTableListEntry(e, isTeacher: isTeacher, hideTeacher: hideTeacher)
).toList()), width: MediaQuery.of(context).size.width / 5)
).toList(),
);
}
}

}


TabBar timeTableTabBar() {
return TabBar(
tabs: [
Tab(text: "Mo"),
Tab(text: "Di"),
Tab(text: "Mi"),
Tab(text: "Do"),
Tab(text: "Fr") ,
],
);
PreferredSizeWidget timeTableTabBar(BuildContext context, {bool isTablet = false}) {
if (isTablet) {
return PreferredSize(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TabletTimeTableDay("Montag"),
TabletTimeTableDay("Dienstag"),
TabletTimeTableDay("Mittwoch"),
TabletTimeTableDay("Donnerstag"),
TabletTimeTableDay("Freitag")
],
),
preferredSize: Size.fromHeight(20)
);
} else {
return TabBar(
tabs: [
Tab(text: "Mo"),
Tab(text: "Di"),
Tab(text: "Mi"),
Tab(text: "Do"),
Tab(text: "Fr") ,
],
);
}
}

class TimeTablePage extends StatelessWidget {
Expand All @@ -83,20 +112,35 @@ class TimeTablePage extends StatelessWidget {

@override
Widget build(BuildContext context) {
int weekday = DateTime.now().weekday - 1;
return DefaultTabController(length: 5, initialIndex: weekday > 4 ? 0 : weekday, child: Scaffold(
appBar: AppBar(
title: Text("Stundenplan"),
bottom: timeTableTabBar(),
actions: splan.pdf != null ? [
Padding(
padding: EdgeInsets.all(10),
child: RaisedButton(onPressed: () => apifile.openFile(context, splan.pdf, "application/pdf"), child: Text("Als PDF", style: TextStyle(color: Colors.white))),
)
] : [],
),
body: TimeTableView(splan, isTeacher: isTeacher),
));
List<Widget> actions = splan.pdf != null ? [
Padding(
padding: EdgeInsets.all(10),
child: RaisedButton(onPressed: () => apifile.openFile(context, splan.pdf, "application/pdf"), child: Text("Als PDF", style: TextStyle(color: Colors.white))),
)
] : [];
return LayoutBuilder(builder: (context, constraints) {
if (constraints.maxWidth > SPLAN_PHONE_WIDTH) {
return Scaffold(
appBar: AppBar(
title: Text("Stundenplan"),
bottom: timeTableTabBar(context, isTablet: true),
actions: actions,
),
body: TimeTableView(splan, isTeacher: isTeacher),
);
} else {
int weekday = DateTime.now().weekday - 1;
return DefaultTabController(length: 5, initialIndex: weekday > 4 ? 0 : weekday, child: Scaffold(
appBar: AppBar(
title: Text("Stundenplan"),
bottom: timeTableTabBar(context),
actions: actions,
),
body: TimeTableView(splan, isTeacher: isTeacher),
));
}
});

}

}
Expand Down Expand Up @@ -173,4 +217,37 @@ class TimeTableListEntry extends StatelessWidget {
);
}

}

class TabletTimeTableDay extends StatelessWidget {

final String _day;

TabletTimeTableDay(this._day);

@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Colors.white
),
left: BorderSide(
color: Colors.white
),
top: BorderSide(
color: Colors.white
)
)
),
padding: EdgeInsets.all(10),
child: Center(
child: Text(_day, style: TextStyle(color: Colors.white)),
),
),
);
}

}
29 changes: 22 additions & 7 deletions lib/components/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if (dart.library.html) '../dynimports/apifile/webapifile.dart'
if (dart.library.io) '../dynimports/apifile/mobileapifile.dart' as file;
import 'timetable.dart';

const int SPLAN_PHONE_WIDTH = 800;

class UserPage extends StatelessWidget {
UserPage(this.shownName, this.timeTable, {this.isTeacher = false});

Expand All @@ -24,13 +26,26 @@ class UserPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
int weekday = DateTime.now().weekday - 1;
return DefaultTabController(length: 5, initialIndex: weekday > 4 ? 0 : weekday, child: Scaffold(
appBar: AppBar(actions: [UserMenu(isTeacher: isTeacher)],
title: Text(shownName != null ? shownName : ""),
bottom: timeTableTabBar(),
),
body: timeTable,
));
return LayoutBuilder(builder: (context, constraints) {
return constraints.maxWidth <= SPLAN_PHONE_WIDTH ?
// Phone Rendering
DefaultTabController(length: 5, initialIndex: weekday > 4 ? 0 : weekday, child: Scaffold(
appBar: AppBar(actions: [UserMenu(isTeacher: isTeacher)],
title: Text(shownName != null ? shownName : ""),
bottom: timeTableTabBar(context),
),
body: timeTable,
))
:
// Tablet Rendering
Scaffold(
appBar: AppBar(actions: [UserMenu(isTeacher: isTeacher)],
title: Text(shownName != null ? shownName : ""),
bottom: timeTableTabBar(context, isTablet: true),
),
body: timeTable,
);
});
}
}

Expand Down

0 comments on commit 89ba6b9

Please sign in to comment.