Jisho-Study-Tool/lib/screens/home.dart

118 lines
3.1 KiB
Dart
Raw Normal View History

2022-01-19 02:10:05 +01:00
import 'package:flutter/foundation.dart';
2021-12-06 20:26:52 +01:00
import 'package:flutter/material.dart';
import 'package:mdi/mdi.dart';
import '../bloc/theme/theme_bloc.dart';
2022-01-23 23:56:26 +01:00
import '../components/common/denshi_jisho_background.dart';
2023-02-24 09:55:55 +01:00
import '../components/library/new_library_dialog.dart';
2022-01-19 02:10:05 +01:00
import 'debug.dart';
import 'history.dart';
2023-02-24 09:55:55 +01:00
import 'library/library_view.dart';
2022-01-19 02:10:05 +01:00
import 'search/kanji_view.dart';
import 'search/search_view.dart';
import 'settings.dart';
2021-12-06 20:26:52 +01:00
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _HomeState();
}
class _HomeState extends State<Home> {
int pageNum = 0;
2023-02-24 09:55:55 +01:00
_Page get page => pages[pageNum];
2021-12-06 20:26:52 +01:00
@override
Widget build(BuildContext context) {
return BlocBuilder<ThemeBloc, ThemeState>(
builder: (context, themeState) {
return Scaffold(
appBar: AppBar(
2023-02-24 09:55:55 +01:00
title: Text(page.titleBar),
2021-12-06 20:26:52 +01:00
centerTitle: true,
backgroundColor: AppTheme.jishoGreen.background,
foregroundColor: AppTheme.jishoGreen.foreground,
2023-02-24 09:55:55 +01:00
actions: page.actions,
2021-12-06 20:26:52 +01:00
),
2023-02-24 09:55:55 +01:00
body: DenshiJishoBackground(child: page.content),
2021-12-06 20:26:52 +01:00
bottomNavigationBar: BottomNavigationBar(
fixedColor: AppTheme.jishoGreen.background,
currentIndex: pageNum,
onTap: (index) => setState(() {
pageNum = index;
}),
2023-02-24 09:55:55 +01:00
items: pages
.map(
(p) => BottomNavigationBarItem(
label: p.titleBar,
icon: p.icon,
),
)
.toList(),
2021-12-06 20:26:52 +01:00
showSelectedLabels: false,
showUnselectedLabels: false,
unselectedItemColor: themeState.theme.menuGreyDark.background,
),
);
},
);
}
List<_Page> get pages => [
const _Page(
content: SearchView(),
2023-02-24 09:55:55 +01:00
titleBar: 'Search',
icon: Icon(Icons.search),
2021-12-06 20:26:52 +01:00
),
const _Page(
content: KanjiView(),
2023-02-24 09:55:55 +01:00
titleBar: 'Kanji Search',
icon: Icon(Mdi.ideogramCjk, size: 30),
2021-12-06 20:26:52 +01:00
),
const _Page(
content: HistoryView(),
2023-02-24 09:55:55 +01:00
titleBar: 'History',
icon: Icon(Icons.history),
2021-12-06 20:26:52 +01:00
),
_Page(
2023-02-24 09:55:55 +01:00
content: const LibraryView(),
titleBar: 'Library',
icon: const Icon(Icons.bookmark),
actions: [
IconButton(
onPressed: showNewLibraryDialog(context),
icon: const Icon(Icons.add),
)
],
2021-12-06 20:26:52 +01:00
),
const _Page(
content: SettingsView(),
2023-02-24 09:55:55 +01:00
titleBar: 'Settings',
icon: Icon(Icons.settings),
2021-12-06 20:26:52 +01:00
),
2022-01-19 02:10:05 +01:00
if (kDebugMode) ...[
const _Page(
content: DebugView(),
2023-02-24 09:55:55 +01:00
titleBar: 'Debug Page',
icon: Icon(Icons.biotech),
2022-01-19 02:10:05 +01:00
)
],
2021-12-06 20:26:52 +01:00
];
}
class _Page {
final Widget content;
2023-02-24 09:55:55 +01:00
final String titleBar;
final Icon icon;
final List<Widget> actions;
2021-12-06 20:26:52 +01:00
const _Page({
required this.content,
required this.titleBar,
2023-02-24 09:55:55 +01:00
required this.icon,
this.actions = const [],
2021-12-06 20:26:52 +01:00
});
}