Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Campus Tab Layout #298

Merged
merged 10 commits into from
Oct 31, 2024
2 changes: 1 addition & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,6 @@
"campus": "Campus",
"studies": "Studium",
"suggested": "Interessante {}",
"all": "Alle",
"more": "Mehr",
"visibility": "Sichtbarkeit"
}
2 changes: 1 addition & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,6 @@
"campus": "Campus",
"studies": "Studies",
"suggested": "Suggested {}",
"all": "All",
"more": "More",
"visibility": "Visibility"
}
38 changes: 38 additions & 0 deletions lib/base/util/grid_utility.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:campus_flutter/base/enums/device.dart';
import 'package:campus_flutter/base/services/device_type_service.dart';
import 'package:flutter/material.dart';

class GridUtility {
static int campusCrossAxisCount(BuildContext context) {
switch (DeviceService.getType(context)) {
case Device.landscapeTablet:
return 6;
case Device.portraitTablet:
return 4;
case Device.phone:
return 2;
}
}

static int campusPaddedCrossAxisCount(BuildContext context) {
switch (DeviceService.getType(context)) {
case Device.landscapeTablet:
return 3;
case Device.portraitTablet:
return 4;
case Device.phone:
return 2;
}
}

static int campusNumberOfItems(BuildContext context) {
switch (DeviceService.getType(context)) {
case Device.landscapeTablet:
return 6;
case Device.portraitTablet:
return 8;
case Device.phone:
return 6;
}
}
}
28 changes: 6 additions & 22 deletions lib/campusComponent/screen/movie_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:campus_flutter/base/enums/device.dart';
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/errorHandling/error_handling_router.dart';
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:campus_flutter/base/services/device_type_service.dart';
import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/util/grid_utility.dart';
import 'package:campus_flutter/base/util/url_launcher.dart';
import 'package:campus_flutter/campusComponent/view/movie/movie_card_view.dart';
import 'package:campus_flutter/campusComponent/view/movie/movie_grid_view.dart';
import 'package:campus_flutter/campusComponent/viewmodel/movies_viewmodel.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -34,15 +33,11 @@ class MovieScreen extends ConsumerWidget {
),
body: () {
if (snapshot.hasData) {
return GridView.count(
return MovieGridView(
movies: snapshot.data!,
padding: EdgeInsets.all(context.padding),
crossAxisCount: crossAxisCount(context),
mainAxisSpacing: context.padding,
crossAxisSpacing: context.padding,
childAspectRatio: 250 / 470,
children: [
for (var movie in snapshot.data!) MovieCardView(movie: movie),
],
crossAxisCount: GridUtility.campusCrossAxisCount(context),
withinScrollView: false,
);
} else if (snapshot.hasError) {
return Center(
Expand All @@ -63,15 +58,4 @@ class MovieScreen extends ConsumerWidget {
},
);
}

int crossAxisCount(BuildContext context) {
switch (DeviceService.getType(context)) {
case Device.landscapeTablet:
return 6;
case Device.portraitTablet:
return 4;
case Device.phone:
return 2;
}
}
}
36 changes: 7 additions & 29 deletions lib/campusComponent/screen/student_clubs_screen.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:campus_flutter/base/enums/device.dart';
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/errorHandling/error_handling_router.dart';
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pb.dart';
import 'package:campus_flutter/base/services/device_type_service.dart';
import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/util/url_launcher.dart';
import 'package:campus_flutter/campusComponent/model/student_club_collection.dart';
import 'package:campus_flutter/campusComponent/view/studentClub/student_club_item_view.dart';
import 'package:campus_flutter/campusComponent/view/studentClub/student_club_grid_view.dart';
import 'package:campus_flutter/campusComponent/viewmodel/student_club_viewmodel.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -48,34 +49,11 @@ class StudentClubsScreen extends ConsumerWidget {
return TabBarView(
children: [
for (var collection in snapshot.data!)
Padding(
padding: const EdgeInsets.only(
top: 15,
left: 11,
right: 11,
),
child: GridView.count(
crossAxisCount: crossAxisCount(context),
children: [
for (var studentClub in collection.clubs)
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
decoration: const ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(28.0),
),
),
),
clipBehavior: Clip.antiAlias,
child: StudentClubItemView(
studentClub: studentClub,
),
),
),
],
),
StudentClubGridView(
studentClubs: collection.clubs,
padding: EdgeInsets.all(context.padding),
crossAxisCount: crossAxisCount(context),
withinScrollView: false,
),
],
);
Expand Down
27 changes: 8 additions & 19 deletions lib/campusComponent/view/movie/movie_card_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,25 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class MovieCardView extends ConsumerWidget {
const MovieCardView({
super.key,
required this.movie,
this.isCarousel = false,
});
const MovieCardView({super.key, required this.movie});

final Movie movie;
final bool isCarousel;

@override
Widget build(BuildContext context, WidgetRef ref) {
if (isCarousel) {
return body(context);
} else {
return InkWell(
onTap: () {
UrlLauncher.urlString(movie.additionalInformationUrl, ref);
},
child: body(context),
);
}
return InkWell(
onTap: () {
UrlLauncher.urlString(movie.additionalInformationUrl, ref);
},
child: body(context),
);
}

Widget body(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Theme.of(context).cardTheme.color,
borderRadius: isCarousel
? BorderRadius.zero
: const BorderRadius.all(Radius.circular(12)),
borderRadius: const BorderRadius.all(Radius.circular(12)),
),
clipBehavior: Clip.antiAlias,
child: AspectRatio(
Expand Down
33 changes: 33 additions & 0 deletions lib/campusComponent/view/movie/movie_grid_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pb.dart';
import 'package:campus_flutter/campusComponent/view/movie/movie_card_view.dart';
import 'package:flutter/material.dart';

class MovieGridView extends StatelessWidget {
const MovieGridView({
super.key,
required this.movies,
required this.padding,
required this.crossAxisCount,
required this.withinScrollView,
});

final List<Movie> movies;
final EdgeInsets padding;
final int crossAxisCount;
final bool withinScrollView;

@override
Widget build(BuildContext context) {
return GridView.count(
shrinkWrap: withinScrollView,
physics: withinScrollView ? NeverScrollableScrollPhysics() : null,
padding: padding,
crossAxisCount: crossAxisCount,
mainAxisSpacing: context.padding,
crossAxisSpacing: context.padding,
childAspectRatio: 250 / 470,
children: [for (var movie in movies) MovieCardView(movie: movie)],
);
}
}
59 changes: 22 additions & 37 deletions lib/campusComponent/view/movie/movies_widget_view.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:campus_flutter/base/enums/error_handling_view_type.dart';
import 'package:campus_flutter/base/extensions/context.dart';
import 'package:campus_flutter/base/routing/routes.dart';
import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pbgrpc.dart';
import 'package:campus_flutter/base/errorHandling/error_handling_router.dart';
import 'package:campus_flutter/base/util/url_launcher.dart';
import 'package:campus_flutter/base/util/grid_utility.dart';
import 'package:campus_flutter/campusComponent/view/movie/movie_grid_view.dart';
import 'package:campus_flutter/homeComponent/view/widget/widget_frame_view.dart';
import 'package:campus_flutter/campusComponent/viewmodel/movies_viewmodel.dart';
import 'package:campus_flutter/campusComponent/view/movie/movie_card_view.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -47,7 +48,7 @@ class _MoviesHomeWidgetState extends ConsumerState<MovieWidgetView> {
const Spacer(),
InkWell(
child: Text(
context.tr("all"),
context.tr("more"),
style: Theme.of(context).textTheme.titleMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
Expand All @@ -65,45 +66,29 @@ class _MoviesHomeWidgetState extends ConsumerState<MovieWidgetView> {

Widget body(AsyncSnapshot<List<Movie>?> snapshot) {
if (snapshot.hasData) {
final height = MediaQuery.of(context).size.height * 0.34;
final width = height * 250 / 470;
return SizedBox(
height: height,
child: Padding(
padding: const EdgeInsets.only(left: 11),
child: CarouselView(
itemExtent: width,
shrinkExtent: width,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
children: [
for (var data in snapshot.data!)
MovieCardView(
movie: data,
isCarousel: true,
),
],
onTap: (index) => UrlLauncher.urlString(
snapshot.data![index].additionalInformationUrl,
ref,
),
),
),
return MovieGridView(
movies: snapshot.data!
.take(GridUtility.campusNumberOfItems(context))
.toList(),
padding: EdgeInsets.symmetric(horizontal: context.padding),
crossAxisCount: GridUtility.campusPaddedCrossAxisCount(context),
withinScrollView: true,
);
} else if (snapshot.hasError) {
return SizedBox(
height: MediaQuery.of(context).size.height * 0.34,
child: ErrorHandlingRouter(
error: snapshot.error!,
errorHandlingViewType: ErrorHandlingViewType.textOnly,
retry: (() => ref.read(movieViewModel).fetch(true)),
return AspectRatio(
aspectRatio: 2,
child: Card(
child: ErrorHandlingRouter(
error: Error(),
errorHandlingViewType: ErrorHandlingViewType.textOnly,
retry: (() => ref.read(movieViewModel).fetch(true)),
),
),
);
} else {
return Card(
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.34,
return AspectRatio(
aspectRatio: 2,
child: Card(
child: DelayedLoadingIndicator(name: context.tr("movies")),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/campusComponent/view/news/news_widget_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class _NewsWidgetViewState extends ConsumerState<NewsWidgetView> {
const Spacer(),
InkWell(
child: Text(
context.tr("all"),
context.tr("more"),
style: Theme.of(context).textTheme.titleMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,26 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';

class StudentClubItemView extends ConsumerWidget {
const StudentClubItemView({
class StudentClubCardView extends ConsumerWidget {
const StudentClubCardView({
super.key,
required this.studentClub,
this.isCarousel = false,
});

final StudentClub studentClub;
final bool isCarousel;

@override
Widget build(BuildContext context, WidgetRef ref) {
if (isCarousel) {
return body(context);
} else {
return InkWell(
onTap: () => UrlLauncher.urlString(studentClub.linkUrl, ref),
child: body(context),
);
}
return InkWell(
onTap: () => UrlLauncher.urlString(studentClub.linkUrl, ref),
child: body(context),
);
}

Widget body(BuildContext context) {
return Container(
color: Theme.of(context).cardTheme.color,
return Card(
margin: EdgeInsets.zero,
clipBehavior: Clip.hardEdge,
child: Column(
children: [
if (studentClub.coverUrl.contains("svg"))
Expand Down Expand Up @@ -67,6 +62,7 @@ class StudentClubItemView extends ConsumerWidget {
),
),
),
Divider(height: 0),
Expanded(
flex: 2,
child: Center(
Expand Down
Loading
Loading