Skip to content

Commit f89e6fe

Browse files
committed
Refactor navigation logic to use a utility function for screen transitions
1 parent db48d18 commit f89e6fe

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/screens/home.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import '../common/app_settings.dart';
1212
import '../common/strings.dart' as strings;
1313
import '../common/urls.dart' as urls;
1414
import '../models/counter.dart';
15+
import '../utils/utils.dart' as utils;
1516
import '../utils/utils.dart';
1617
import '../widgets/accept_cancel_dialog.dart';
1718
import '../widgets/counter_display.dart';
@@ -101,9 +102,9 @@ class _HomeScreenState extends State<HomeScreen> {
101102

102103
/// Navigates to the Settings screen, and refreshes on return.
103104
Future<void> _loadSettingsScreen() async {
104-
await Navigator.push<void>(
105+
await utils.navigateToScreen<void>(
105106
context,
106-
MaterialPageRoute(builder: (context) => SettingsScreen(appSettings: _appSettings)),
107+
SettingsScreen(appSettings: _appSettings),
107108
);
108109
setState(() {
109110
/* Refresh after returning from Settings screen. */

lib/utils/utils.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ String toDecimalString(BuildContext context, int number) {
1515
return localizations.formatDecimal(number);
1616
}
1717

18+
/// Navigates to the given screen widget.
19+
Future<T?> navigateToScreen<T>(BuildContext context, Widget screen) {
20+
return Navigator.of(context).push<T>(
21+
MaterialPageRoute<T>(
22+
builder: (context) => screen,
23+
),
24+
);
25+
}
26+
1827
/// Launches the specified [URL] in the mobile platform, using the default external application.
1928
///
2029
/// Shows an error [SnackBar] if there is no support for launching the URL.

0 commit comments

Comments
 (0)