yokutango-mobile-reader/lib/router.dart

58 lines
1.7 KiB
Dart

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