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

62 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-25 20:44:00 +01:00
import '../screens/search/result_page.dart';
2022-01-19 02:10:05 +01:00
import '../screens/search/search_mechanisms/drawing.dart';
import '../screens/search/search_mechanisms/grade_list.dart';
import '../screens/search/search_mechanisms/radical_list.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(
2022-01-25 20:44:00 +01:00
builder: (_) => ResultPage(searchTerm: searchTerm, isKanji: false),
2022-01-19 02:10:05 +01:00
);
case Routes.kanjiSearch:
final searchTerm = args! as String;
return MaterialPageRoute(
2022-01-25 20:44:00 +01:00
builder: (_) => ResultPage(searchTerm: searchTerm, isKanji: true),
2022-01-19 02:10:05 +01:00
);
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')),
),
);
}
}