-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.dart
60 lines (58 loc) · 2.66 KB
/
routes.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import 'package:app4training/routes/about_page.dart';
import 'package:app4training/routes/error_page.dart';
import 'package:app4training/routes/home_page.dart';
import 'package:app4training/routes/onboarding/download_languages_page.dart';
import 'package:app4training/routes/onboarding/set_update_prefs_page.dart';
import 'package:app4training/routes/onboarding/welcome_page.dart';
import 'package:flutter/material.dart';
import 'package:app4training/routes/settings_page.dart';
import 'package:app4training/routes/startup_page.dart';
import 'package:app4training/routes/view_page.dart';
Route<Object?> generateRoutes(RouteSettings settings) {
debugPrint('Handling route "${settings.name}"');
if ((settings.name == null) || (settings.name == '/')) {
return MaterialPageRoute<void>(
settings: settings, // Necessary for the NavigatorObserver while testing
builder: (_) => const StartupPage(),
);
} else if (settings.name == '/home') {
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const HomePage());
} else if (settings.name!.startsWith('/view')) {
// route should be /view/pageName/langCode - deep linking is possible
final List<String> parts = settings.name!.split('/');
if ((parts.length <= 3) || (parts[2] == '') || (parts[3] == '')) {
debugPrint('Unexpected route ${settings.name} - redirecting to /home');
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const HomePage());
}
String page = parts[2];
String langCode = parts[3];
return MaterialPageRoute<void>(
settings: settings, builder: (_) => ViewPage(page, langCode));
} else if (settings.name == '/settings') {
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const SettingsPage());
} else if (settings.name == '/about') {
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const AboutPage());
} else if (settings.name!.startsWith('/onboarding')) {
final List<String> parts = settings.name!.split('/');
String step = '1';
if ((parts.length > 2) && (parts[2] != '')) step = parts[2];
if (step == '1') {
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const WelcomePage());
} else if (step == '2') {
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const DownloadLanguagesPage());
} else if (step == '3') {
return MaterialPageRoute<void>(
settings: settings, builder: (_) => const SetUpdatePrefsPage());
}
}
return MaterialPageRoute<void>(
settings: settings,
builder: (_) => ErrorPage('Unknown route ${settings.name}'),
);
}