Jisho-Study-Tool/lib/main.dart

120 lines
2.6 KiB
Dart
Raw Normal View History

2020-06-28 00:39:45 +02:00
import 'package:flutter/material.dart';
2020-07-14 14:33:21 +02:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
2020-06-30 22:51:32 +02:00
import 'package:jisho_study_tool/screens/kanji_search.dart';
2020-07-13 23:41:31 +02:00
import 'package:jisho_study_tool/screens/history.dart';
2020-07-09 22:17:10 +02:00
import 'package:jisho_study_tool/screens/search.dart';
2020-06-28 00:39:45 +02:00
2020-07-14 14:33:21 +02:00
import 'bloc/search/search_bloc.dart';
2020-06-28 00:39:45 +02:00
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
2020-07-09 20:06:48 +02:00
title: 'Jisho Study Tool',
2020-06-28 00:39:45 +02:00
theme: ThemeData(
primarySwatch: Colors.blue,
),
2020-07-14 14:33:21 +02:00
home: MultiBlocProvider(
providers: [
BlocProvider(create: (context) => SearchBloc()),
BlocProvider(create: (context) => KanjiBloc()),
],
child: Home(),
),
2020-06-28 00:39:45 +02:00
);
}
}
class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int _selectedPage = 0;
@override
2020-07-09 20:59:00 +02:00
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2020-07-14 12:52:48 +02:00
title: pages[_selectedPage].titleBar,
2020-07-09 20:59:00 +02:00
centerTitle: true,
),
body: pages[_selectedPage].content,
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedPage,
onTap: (int index) {
setState(() {
_selectedPage = index;
});
},
items: navBar,
showSelectedLabels: false,
showUnselectedLabels: false,
unselectedItemColor: Colors.blue,
selectedItemColor: Colors.green,
),
);
}
2020-06-30 22:51:32 +02:00
}
2020-07-13 23:39:16 +02:00
final List<BottomNavigationBarItem> navBar = [
2020-06-30 22:51:32 +02:00
BottomNavigationBarItem(
title: Text('Search'),
2020-07-09 20:59:00 +02:00
icon: Icon(Icons.search),
2020-06-30 22:51:32 +02:00
),
BottomNavigationBarItem(
title: Text('Kanji'),
icon: Text(
'',
2020-07-09 20:59:00 +02:00
style: TextStyle(fontSize: 18),
),
),
BottomNavigationBarItem(
2020-07-13 23:41:31 +02:00
title: Text('History'),
2020-07-09 20:59:00 +02:00
icon: Icon(Icons.bookmark),
2020-06-30 22:51:32 +02:00
),
BottomNavigationBarItem(
title: Text('Memorize'),
2020-07-09 20:59:00 +02:00
icon: Icon(Icons.local_offer),
2020-06-30 22:51:32 +02:00
),
BottomNavigationBarItem(
title: Text('Settings'),
2020-07-09 20:59:00 +02:00
icon: Icon(Icons.settings),
2020-06-30 22:51:32 +02:00
),
];
class Page {
Widget content;
2020-07-14 12:52:48 +02:00
Widget titleBar;
2020-06-30 22:51:32 +02:00
2020-07-14 14:33:21 +02:00
Page({
this.content,
this.titleBar,
});
2020-06-30 22:51:32 +02:00
}
2020-07-13 23:39:16 +02:00
final List<Page> pages = [
2020-07-14 14:33:21 +02:00
Page(content: SearchView(), titleBar: Text('Search')),
2020-06-30 22:51:32 +02:00
Page(
2020-07-09 22:17:10 +02:00
content: KanjiView(),
2020-07-14 12:52:48 +02:00
titleBar: KanjiViewBar(),
2020-07-09 20:59:00 +02:00
),
Page(
2020-07-13 23:41:31 +02:00
content: HistoryView(),
2020-07-14 12:52:48 +02:00
titleBar: Text("History"),
2020-06-30 22:51:32 +02:00
),
Page(
2020-07-09 20:59:00 +02:00
content: Container(),
2020-07-14 12:52:48 +02:00
titleBar: Text("Memorization"),
2020-06-30 22:51:32 +02:00
),
Page(
2020-07-09 20:59:00 +02:00
content: Container(),
2020-07-14 12:52:48 +02:00
titleBar: Text("Settings"),
2020-06-30 22:51:32 +02:00
),
2020-07-09 20:59:00 +02:00
];