Skip to content

Commit

Permalink
feat: finish out updated sponsors
Browse files Browse the repository at this point in the history
  • Loading branch information
glitchedmob committed Oct 8, 2024
1 parent 9552187 commit 2302c13
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 34 deletions.
15 changes: 15 additions & 0 deletions lib/data/umbraco/image_url.dart
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
import 'package:method_conf_app/env.dart';

String imageUrl(String url, {int? width, int? height}) {
var parsedUrl = Uri.parse(Env.umbracoBaseUrl).replace(path: url);

if (width != null) {
parsedUrl = parsedUrl.replace(queryParameters: {'width': width.toString()});
}

if (height != null) {
parsedUrl =
parsedUrl.replace(queryParameters: {'height': height.toString()});
}

return parsedUrl.toString();
}
89 changes: 56 additions & 33 deletions lib/screens/sponsors_screen.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'package:flutter/material.dart';
import 'package:method_conf_app/env.dart';
import 'package:method_conf_app/providers/sponsor_provider_v2.dart';
import 'package:method_conf_app/widgets/app_banner.dart';
import 'package:provider/provider.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:quiver/iterables.dart' show partition;
import 'package:cached_network_image/cached_network_image.dart';

import 'package:method_conf_app/data/umbraco/image_url.dart';
import 'package:method_conf_app/data/umbraco/models/sponsor.dart';
import 'package:method_conf_app/data/umbraco/models/sponsor_tier.dart';
import 'package:method_conf_app/env.dart';
import 'package:method_conf_app/providers/sponsor_provider_v2.dart';
import 'package:method_conf_app/widgets/app_banner.dart';
import 'package:method_conf_app/theme.dart';
import 'package:method_conf_app/utils/utils.dart';
import 'package:method_conf_app/widgets/page_loader.dart';
import 'package:method_conf_app/models/sponsor.dart';
import 'package:method_conf_app/widgets/app_screen.dart';
import 'package:method_conf_app/providers/sponsor_provider.dart';

class SponsorsScreen extends StatefulWidget {
const SponsorsScreen({super.key});
Expand All @@ -34,7 +35,6 @@ class _SponsorsScreenState extends State<SponsorsScreen> {

@override
Widget build(BuildContext context) {
var sponsorProvider = Provider.of<SponsorProvider>(context);
var sponsorProviderV2 = Provider.of<SponsorProviderV2>(context);

return AppScreen(
Expand All @@ -56,21 +56,27 @@ class _SponsorsScreenState extends State<SponsorsScreen> {
),
const SizedBox(height: 15),
...sponsorProviderV2.sponsorTiers.expand((tier) {
final title = tier.properties?.title;
final sponsors = tier.properties?.mobileAppSponsors ?? [];
final logoSizes =
tier.properties?.logoSizes ?? SponsorTierLogoSize.medium;
return [
Text(tier.properties?.title ?? 'Test'),
...tier.properties?.mobileAppSponsors.map((sponsor) {
return Text(sponsor.properties?.title ?? 'Test');
}) ??
[],
if (title != null)
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Text(
title,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
),
),
if (logoSizes == SponsorTierLogoSize.large)
..._buildLargeSponsors(sponsors)
else
..._buildMediumSponsors(sponsors),
];
}),
...sponsorProvider.largeSponsors.map((sponsor) {
return Padding(
padding: const EdgeInsets.only(bottom: 15),
child: _buildSponsor(sponsor),
);
}),
..._buildNormalSponsors(sponsorProvider.normalSponsors),
..._buildBanner(),
],
),
Expand All @@ -80,15 +86,19 @@ class _SponsorsScreenState extends State<SponsorsScreen> {
}

Widget _buildSponsor(Sponsor sponsor) {
final url = sponsor.properties?.url;
final logoUrl = sponsor.properties?.logo?.firstOrNull?.url;
return Container(
height: sponsor.mobileSponsor! ? 130 : 100,
color: sponsor.background == 'dark'
height: 130,
color: sponsor.properties?.darkBackground == true
? AppColors.primaryLight
: AppColors.neutralExtraLight,
child: TextButton(
style: TextButton.styleFrom(padding: const EdgeInsets.all(0)),
onPressed: () {
launchUrl(sponsor.url!);
if (url != null) {
launchUrl(url);
}
},
child: Row(
children: <Widget>[
Expand All @@ -97,16 +107,20 @@ class _SponsorsScreenState extends State<SponsorsScreen> {
flex: 8,
child: Center(
child: OverflowBox(
maxHeight: sponsor.mobileSponsor! ? 75 : 65,
child: CachedNetworkImage(
imageUrl: sponsor.image!,
placeholder: (context, url) =>
const CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.transparent),
),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
),
// maxHeight: sponsor.mobileSponsor! ? 75 : 65,
maxHeight: 75,
child: logoUrl != null
? CachedNetworkImage(
imageUrl: imageUrl(logoUrl, height: 75),
placeholder: (context, url) =>
const CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation(Colors.transparent),
),
errorWidget: (context, url, error) =>
const Icon(Icons.error),
)
: null,
),
),
),
Expand All @@ -117,7 +131,16 @@ class _SponsorsScreenState extends State<SponsorsScreen> {
);
}

List<Widget> _buildNormalSponsors(List<Sponsor> sponsors) {
List<Widget> _buildLargeSponsors(List<Sponsor> sponsors) {
return sponsors
.map((sponsor) => Padding(
padding: const EdgeInsets.only(bottom: 15),
child: _buildSponsor(sponsor),
))
.toList();
}

List<Widget> _buildMediumSponsors(List<Sponsor> sponsors) {
var chunked = partition(sponsors, 2);
return chunked.map((sponsorPair) {
return Padding(
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/app_navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _AppNavigationState extends State<AppNavigation> {
),
_NavigationItem(
route: '/partners',
item: _buildNavigationBarItem(AppIcons.piggyBank, 'Partners'),
item: _buildNavigationBarItem(AppIcons.piggyBank, 'Sponsors'),
),
_NavigationItem(
route: '/more',
Expand Down

0 comments on commit 2302c13

Please sign in to comment.