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

116 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';
2022-01-19 02:10:05 +01:00
import 'debug.dart';
import 'history.dart';
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;
@override
Widget build(BuildContext context) {
return BlocBuilder<ThemeBloc, ThemeState>(
builder: (context, themeState) {
return Scaffold(
appBar: AppBar(
title: pages[pageNum].titleBar,
centerTitle: true,
backgroundColor: AppTheme.jishoGreen.background,
foregroundColor: AppTheme.jishoGreen.foreground,
),
2022-01-23 23:56:26 +01:00
body: DenshiJishoBackground(child: pages[pageNum].content),
2021-12-06 20:26:52 +01:00
bottomNavigationBar: BottomNavigationBar(
fixedColor: AppTheme.jishoGreen.background,
currentIndex: pageNum,
onTap: (index) => setState(() {
pageNum = index;
}),
items: pages.map((p) => p.item).toList(),
showSelectedLabels: false,
showUnselectedLabels: false,
unselectedItemColor: themeState.theme.menuGreyDark.background,
),
);
},
);
}
List<_Page> get pages => [
const _Page(
content: SearchView(),
titleBar: Text('Search'),
item: BottomNavigationBarItem(
label: 'Search',
icon: Icon(Icons.search),
),
),
const _Page(
content: KanjiView(),
2022-01-19 02:10:05 +01:00
titleBar: Text('Kanji Search'),
2021-12-06 20:26:52 +01:00
item: BottomNavigationBarItem(
label: 'Kanji',
icon: Icon(Mdi.ideogramCjk, size: 30),
),
),
const _Page(
content: HistoryView(),
titleBar: Text('History'),
item: BottomNavigationBarItem(
label: 'History',
icon: Icon(Icons.history),
),
),
_Page(
content: Container(),
titleBar: const Text('Saved'),
item: const BottomNavigationBarItem(
label: 'Saved',
icon: Icon(Icons.bookmark),
),
),
const _Page(
content: SettingsView(),
titleBar: Text('Settings'),
item: BottomNavigationBarItem(
label: 'Settings',
icon: Icon(Icons.settings),
),
),
2022-01-19 02:10:05 +01:00
if (kDebugMode) ...[
const _Page(
content: DebugView(),
2022-01-23 23:56:26 +01:00
titleBar: Text('Debug Page'),
item: BottomNavigationBarItem(
2022-01-19 02:10:05 +01:00
label: 'Debug',
icon: Icon(Icons.biotech),
),
)
],
2021-12-06 20:26:52 +01:00
];
}
class _Page {
final Widget content;
final Widget titleBar;
final BottomNavigationBarItem item;
const _Page({
required this.content,
required this.titleBar,
required this.item,
});
}