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

Add go_router to our website and use path URL strategy instead of hash URL strategy #1184

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions website/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,29 +121,24 @@
},
{
"source": "/impressum",
"destination": "https://sharezone.net/#imprint-page",
"destination": "https://sharezone.net/imprint",
"type": 302
},
{
"source": "/datenschutzerklaerung",
"destination": "https://sharezone.net/privacy-app#privacy-app",
"destination": "https://sharezone.net/privacy-policy",
"type": 302
},
{
"source": "/dse",
"destination": "https://sharezone.net/privacy-app#privacy-app",
"destination": "https://sharezone.net/privacy-policy",
"type": 302
},
{
"source": "/dse-v1-0-0-pdf",
"destination": "https://firebasestorage.googleapis.com/v0/b/sharezone-c2bd8.appspot.com/o/Legal%2FDatenschutzerkl%C3%A4rung%20Sharezone%20v1.0.0.pdf?alt=media&token=b48bcd88-013f-4d69-9501-e55ef8d10719",
"type": 302
},
{
"source": "/support",
"destination": "https://sharezone.net/#support-page",
"type": 301
},
{
"source": "/macos-direct",
"destination": "macappstore://itunes.apple.com/app/id1434868489",
Expand All @@ -156,7 +151,7 @@
},
{
"source": "/imprint#privacy-app",
"destination": "https://sharezone.net/#privacy-app",
"destination": "https://sharezone.net/privacy-policy",
"type": 302
},
{
Expand Down
3 changes: 2 additions & 1 deletion website/lib/footer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:sharezone_website/legal/imprint_page.dart';
import 'package:sharezone_website/legal/privacy_policy.dart';
import 'package:sharezone_website/support_page.dart';
Expand Down Expand Up @@ -263,7 +264,7 @@ class _FooterSection extends StatelessWidget {
text: l.title,
onTap: () {
if (l.link == null) {
Navigator.pushNamed(context, l.tag!);
context.go('/${l.tag}');
} else {
launchUrl(l.link!);
}
Expand Down
2 changes: 0 additions & 2 deletions website/lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ bool isPhone(BuildContext context) {
class HomePage extends StatelessWidget {
const HomePage({super.key});

static const tag = "home-page";

@override
Widget build(BuildContext context) {
return const PageTemplate(
Expand Down
3 changes: 2 additions & 1 deletion website/lib/home/src/support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:sharezone_website/widgets/headline.dart';
import 'package:sharezone_website/widgets/image_text.dart';
import 'package:sharezone_website/widgets/section_action_button.dart';
Expand Down Expand Up @@ -40,7 +41,7 @@ class Support extends StatelessWidget {
const SizedBox(height: 20),
SectionActionButton(
text: "Support kontaktieren",
onTap: () => Navigator.pushNamed(context, SupportPage.tag),
onTap: () => context.go('/$SupportPage.tag'),
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion website/lib/legal/imprint_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import 'imprint.dart';
class ImprintPage extends StatelessWidget {
const ImprintPage({super.key});

static const tag = 'imprint-page';
static const tag = 'imprint';

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion website/lib/legal/privacy_policy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'package:sharezone_website/widgets/max_width_constraint_box.dart';
class PrivacyPolicyPage extends StatelessWidget {
const PrivacyPolicyPage({super.key});

static const tag = "privacy-app";
static const tag = "privacy-policy";

@override
Widget build(BuildContext context) {
Expand Down
48 changes: 39 additions & 9 deletions website/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,63 @@
// SPDX-License-Identifier: EUPL-1.2

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:sharezone_website/support_page.dart';
// ignore: depend_on_referenced_packages
import 'package:flutter_web_plugins/url_strategy.dart';

import 'home/home_page.dart';
import 'legal/imprint_page.dart';
import 'legal/privacy_policy.dart';

void main() => runApp(const MyApp());
void main() {
usePathUrlStrategy();
runApp(const MyApp());
}

class SharezoneStyle {
static const primaryColor = Color(0xFF68B3E9);
static const font = 'Rubik';
}

/// The route configuration.
final GoRouter _router = GoRouter(
routes: <RouteBase>[
GoRoute(
path: '/',
builder: (BuildContext context, GoRouterState state) => const HomePage(),
routes: <RouteBase>[
GoRoute(
path: ImprintPage.tag,
builder: (BuildContext context, GoRouterState state) {
return const ImprintPage();
},
),
GoRoute(
path: SupportPage.tag,
builder: (BuildContext context, GoRouterState state) {
return const SupportPage();
},
),
GoRoute(
path: PrivacyPolicyPage.tag,
builder: (BuildContext context, GoRouterState state) {
return const PrivacyPolicyPage();
},
),
],
),
],
);

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
return MaterialApp.router(
routerConfig: _router,
title: 'Sharezone - Vernetzter Schulplaner',
routes: {
HomePage.tag: (context) => const HomePage(),
ImprintPage.tag: (context) => const ImprintPage(),
SupportPage.tag: (context) => const SupportPage(),
PrivacyPolicyPage.tag: (context) => const PrivacyPolicyPage(),
},
theme: ThemeData(
useMaterial3: false,
primaryColor: SharezoneStyle.primaryColor,
Expand All @@ -44,7 +75,6 @@ class MyApp extends StatelessWidget {
},
),
),
home: const HomePage(),
);
}
}
Expand Down
13 changes: 5 additions & 8 deletions website/lib/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// SPDX-License-Identifier: EUPL-1.2

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:sharezone_website/support_page.dart';
import 'package:sharezone_website/utils.dart';
import 'package:sharezone_website/widgets/column_spacing.dart';
Expand Down Expand Up @@ -38,8 +39,7 @@ class PageTemplate extends StatelessWidget {
ListTile(
leading: const Icon(Icons.home),
title: const Text("Hauptseite"),
onTap: () =>
Navigator.popAndPushNamed(context, HomePage.tag),
onTap: () => context.go('/'),
),
ListTile(
leading: const Icon(Icons.question_answer),
Expand All @@ -49,8 +49,7 @@ class PageTemplate extends StatelessWidget {
ListTile(
leading: const Icon(Icons.help),
title: const Text("Support"),
onTap: () =>
Navigator.pushNamed(context, SupportPage.tag),
onTap: () => context.go('/$SupportPage.tag'),
),
],
),
Expand Down Expand Up @@ -116,8 +115,7 @@ class _AppBarTitle extends StatelessWidget implements PreferredSizeWidget {
)
else
TransparentButton(
onTap: () =>
Navigator.popAndPushNamed(context, HomePage.tag),
onTap: () => context.go('/'),
child: const SharezoneLogo(
logoColor: LogoColor.blueShort,
height: 50,
Expand All @@ -131,8 +129,7 @@ class _AppBarTitle extends StatelessWidget implements PreferredSizeWidget {
if (!isPhone(context)) ...[
TransparentButton(
child: const Text("Support"),
onTap: () =>
Navigator.pushNamed(context, SupportPage.tag),
onTap: () => context.go('/${SupportPage.tag}'),
),
const SizedBox(width: 30),
TransparentButton.openLink(
Expand Down
2 changes: 1 addition & 1 deletion website/lib/support_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const phoneNumber = '+49 1516 7754541';
class SupportPage extends StatelessWidget {
const SupportPage({super.key});

static const String tag = 'support-page';
static const String tag = 'support';

@override
Widget build(BuildContext context) {
Expand Down
16 changes: 16 additions & 0 deletions website/pubspec.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
flutter_markdown: ^0.6.18+2
flutter_staggered_animations: ^1.1.1
flutter_svg: ^2.0.9
go_router: ^12.1.3
number_slide_animation: ^0.2.1
url_launcher: ^6.2.2

Expand Down
Loading