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 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, index: benkyouArgs.index ?? 0, isKanji: false, ), ); case '/benkyou/kanji': final benkyouArgs = args as BenkyouArgs; return MaterialPageRoute( builder: (_) => PractiseView( entries: benkyouArgs.cards as List, index: benkyouArgs.index ?? 0, isKanji: true, ), ); default: return MaterialPageRoute( builder: (_) => Scaffold( appBar: AppBar(title: const Text('Error')), body: Center(child: ErrorWidget('No such route...')), ), ); } } }