Skip to content

Commit

Permalink
Updates browser tab title setting method
Browse files Browse the repository at this point in the history
  • Loading branch information
lenzpaul authored and slovnicki committed Feb 12, 2024
1 parent 4a675d2 commit dcda31e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 7 additions & 7 deletions package/lib/src/beamer_delegate.dart
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit dcda31e

Please sign in to comment.