yokutango-mobile-reader/lib/router.dart

58 lines
1.8 KiB
Dart
Raw Permalink Normal View History

2022-01-26 00:25:07 +01:00
import 'dart:io';
2024-04-26 01:14:49 +02:00
import 'package:yokutango_mobile_reader/models/data_entry.dart';
import 'package:yokutango_mobile_reader/models/router_args.dart';
import 'package:yokutango_mobile_reader/screens/home.dart';
import 'package:yokutango_mobile_reader/screens/pages/tango_list.dart';
2022-01-26 00:25:07 +01:00
import 'package:flutter/material.dart';
2024-04-26 01:14:49 +02:00
import 'package:yokutango_mobile_reader/screens/practise/practise.dart';
2022-01-26 00:25:07 +01:00
2022-01-26 01:58:47 +01:00
import 'screens/pages/kanji_list.dart';
2022-01-26 00:25:07 +01:00
class PageRouter {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case '/':
return MaterialPageRoute(builder: (_) => const Home());
2022-01-26 01:58:47 +01:00
case '/list/tango':
2022-01-26 00:25:07 +01:00
final file = args as File;
return MaterialPageRoute(builder: (_) => TangoList(file: file));
2022-01-26 01:58:47 +01:00
case '/list/kanji':
final file = args as File;
return MaterialPageRoute(builder: (_) => KanjiList(file: file));
case '/benkyou/tango':
2022-01-26 00:25:07 +01:00
final benkyouArgs = args as BenkyouArgs;
return MaterialPageRoute(
2022-01-29 19:16:13 +01:00
builder: (_) => PractiseView(
entries: benkyouArgs.cards as List<YokutangoEntry>,
index: benkyouArgs.index ?? 0,
isKanji: false,
2022-01-26 00:25:07 +01:00
),
);
2022-01-26 01:58:47 +01:00
case '/benkyou/kanji':
2022-01-29 19:16:13 +01:00
final benkyouArgs = args as BenkyouArgs;
return MaterialPageRoute(
builder: (_) => PractiseView(
entries: benkyouArgs.cards as List<KanjiEntry>,
index: benkyouArgs.index ?? 0,
isKanji: true,
),
);
2022-01-26 01:58:47 +01:00
2022-01-26 00:25:07 +01:00
default:
return MaterialPageRoute(
2022-01-26 01:58:47 +01:00
builder: (_) => Scaffold(
appBar: AppBar(title: const Text('Error')),
2022-01-29 19:16:13 +01:00
body: Center(child: ErrorWidget('No such route...')),
2022-01-26 01:58:47 +01:00
),
);
2022-01-26 00:25:07 +01:00
}
}
}