Jisho-Study-Tool/lib/routing/router.dart

63 lines
2.0 KiB
Dart
Raw Normal View History

2022-01-19 02:10:05 +01:00
import 'package:flutter/material.dart';
import '../screens/home.dart';
import '../screens/info/about.dart';
import '../screens/info/licenses.dart';
2022-01-19 02:10:05 +01:00
import '../screens/search/kanji_result_page.dart';
import '../screens/search/search_mechanisms/drawing.dart';
import '../screens/search/search_mechanisms/grade_list.dart';
import '../screens/search/search_mechanisms/radical_list.dart';
import '../screens/search/search_results_page.dart';
import 'routes.dart';
Route<Widget> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case Routes.root:
return MaterialPageRoute(builder: (_) => const Home());
case Routes.search:
final searchTerm = args! as String;
return MaterialPageRoute(
builder: (_) => SearchResultsPage(searchTerm: searchTerm),
);
case Routes.kanjiSearch:
final searchTerm = args! as String;
return MaterialPageRoute(
builder: (_) => KanjiResultPage(kanjiSearchTerm: searchTerm),
);
case Routes.kanjiSearchDraw:
return MaterialPageRoute(builder: (_) => const KanjiDrawingSearch());
case Routes.kanjiSearchGrade:
return MaterialPageRoute(builder: (_) => const KanjiGradeSearch());
case Routes.kanjiSearchRadicals:
final prechosenRadical = args as String?;
return MaterialPageRoute(
builder: (_) => KanjiRadicalSearch(prechosenRadical: prechosenRadical),
);
case Routes.about:
return MaterialPageRoute(builder: (_) => const AboutView());
case Routes.aboutLicenses:
return MaterialPageRoute(builder: (_) => const LicensesView());
2022-01-19 02:10:05 +01:00
// TODO: Add more specific error screens.
case Routes.errorNotFound:
case Routes.errorNetwork:
case Routes.errorOther:
default:
return MaterialPageRoute(
builder: (_) => Scaffold(
appBar:
AppBar(title: const Text('Error'), backgroundColor: Colors.red),
body: Center(child: ErrorWidget('Some kind of error occured')),
),
);
}
}