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

Updates browser tab title setting method #657

Merged
merged 1 commit into from Feb 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package/lib/src/beamer_delegate.dart
@@ -1,4 +1,7 @@
import 'package:beamer/beamer.dart';
import 'package:beamer/src/browser_tab_title_util_non_web.dart'
if (dart.library.html) 'package:beamer/src/browser_tab_title_util_web.dart'
as browser_tab_title_util;
import 'package:beamer/src/utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -987,13 +990,10 @@ class BeamerDelegate extends RouterDelegate<RouteInformation>
}

void _setBrowserTitle(BuildContext context) {
if (active && kIsWeb && setBrowserTabTitle) {
SystemChrome.setApplicationSwitcherDescription(
ApplicationSwitcherDescription(
label: _currentPages.last.title ??
currentBeamLocation.state.routeInformation.uri.path,
primaryColor: Theme.of(context).primaryColor.value,
));
if (active && setBrowserTabTitle) {
final String title = _currentPages.last.title ??
currentBeamLocation.state.routeInformation.uri.path;
browser_tab_title_util.setTabTitle(title);
}
}

Expand Down
4 changes: 4 additions & 0 deletions package/lib/src/browser_tab_title_util_non_web.dart
@@ -0,0 +1,4 @@
/// {@macro browser_tab_title_util.tab_title}
setTabTitle(String title) {
// no-op
}
10 changes: 10 additions & 0 deletions package/lib/src/browser_tab_title_util_web.dart
@@ -0,0 +1,10 @@
import 'dart:html' as html;

/// {@template browser_tab_title_util.tab_title}
/// Sets the title of the browser tab on web.
///
/// This is a no-op on non-web platforms.
/// {@endtemplate}
setTabTitle(String title) {
html.document.title = title;
}