mirror of
https://github.com/h7x4/Jisho-Study-Tool.git
synced 2024-12-21 21:47:29 +01:00
Convert most bloc usage to listeners and builders
This commit is contained in:
parent
7e8442881a
commit
25a58d6f59
@ -95,25 +95,30 @@ class _DrawingBoardState extends State<DrawingBoard> {
|
|||||||
|
|
||||||
Widget kanjiChip(String kanji) => InkWell(
|
Widget kanjiChip(String kanji) => InkWell(
|
||||||
onTap: () => widget.onSuggestionChosen?.call(kanji),
|
onTap: () => widget.onSuggestionChosen?.call(kanji),
|
||||||
child: Container(
|
child: BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final colors = state.theme.menuGreyLight;
|
||||||
|
|
||||||
|
return Container(
|
||||||
height: fontSize + 2 * suggestionCirclePadding,
|
height: fontSize + 2 * suggestionCirclePadding,
|
||||||
width: fontSize + 2 * suggestionCirclePadding,
|
width: fontSize + 2 * suggestionCirclePadding,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
color: BlocProvider.of<ThemeBloc>(context)
|
color: colors.background,
|
||||||
.state
|
|
||||||
.theme
|
|
||||||
.menuGreyLight
|
|
||||||
.background,
|
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
kanji,
|
kanji,
|
||||||
style: const TextStyle(fontSize: fontSize),
|
style: TextStyle(
|
||||||
|
fontSize: fontSize,
|
||||||
|
color: colors.foreground,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
Widget suggestionBar() {
|
Widget suggestionBar() {
|
||||||
const padding = EdgeInsets.symmetric(horizontal: 10, vertical: 5);
|
const padding = EdgeInsets.symmetric(horizontal: 10, vertical: 5);
|
||||||
|
@ -36,23 +36,23 @@ class DateDivider extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final Widget header =
|
builder: (context, state) {
|
||||||
(text != null) ? Text(text!) : Text(getHumanReadableDate(date!));
|
final colors = state.theme.menuGreyNormal;
|
||||||
|
|
||||||
final ColorSet _menuColors =
|
|
||||||
BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyNormal;
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
decoration: BoxDecoration(color: _menuColors.background),
|
decoration: BoxDecoration(color: colors.background),
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 5,
|
vertical: 5,
|
||||||
horizontal: 10,
|
horizontal: 10,
|
||||||
),
|
),
|
||||||
child: DefaultTextStyle.merge(
|
child: DefaultTextStyle.merge(
|
||||||
child: header,
|
child: (text != null)
|
||||||
style: TextStyle(color: _menuColors.foreground),
|
? Text(text!)
|
||||||
|
: Text(getHumanReadableDate(date!)),
|
||||||
|
style: TextStyle(color: colors.foreground),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,17 +11,16 @@ class KanjiBox extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => IntrinsicHeight(
|
||||||
final ColorSet menuColors =
|
|
||||||
BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyLight;
|
|
||||||
|
|
||||||
return IntrinsicHeight(
|
|
||||||
child: AspectRatio(
|
child: AspectRatio(
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
child: Container(
|
child: BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final colors = state.theme.menuGreyLight;
|
||||||
|
return Container(
|
||||||
padding: const EdgeInsets.all(5),
|
padding: const EdgeInsets.all(5),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: menuColors.background,
|
color: colors.background,
|
||||||
borderRadius: BorderRadius.circular(10.0),
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
@ -29,14 +28,15 @@ class KanjiBox extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
kanji,
|
kanji,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: menuColors.foreground,
|
color: colors.foreground,
|
||||||
fontSize: 25,
|
fontSize: 25,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -53,11 +53,13 @@ class _Example extends StatelessWidget {
|
|||||||
const _Example(this.yomiExample, this.kanaType);
|
const _Example(this.yomiExample, this.kanaType);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final theme = BlocProvider.of<ThemeBloc>(context).state.theme;
|
builder: (context, state) {
|
||||||
|
final theme = state.theme;
|
||||||
final menuColors = theme.menuGreyNormal;
|
final menuColors = theme.menuGreyNormal;
|
||||||
final kanaColors =
|
final kanaColors = kanaType == _KanaType.kunyomi
|
||||||
kanaType == _KanaType.kunyomi ? theme.kunyomiColor : theme.onyomiColor;
|
? theme.kunyomiColor
|
||||||
|
: theme.onyomiColor;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.symmetric(
|
margin: const EdgeInsets.symmetric(
|
||||||
@ -77,7 +79,8 @@ class _Example extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _Kana extends StatelessWidget {
|
class _Kana extends StatelessWidget {
|
||||||
|
@ -13,9 +13,9 @@ class Grade extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final colors =
|
builder: (context, state) {
|
||||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
final colors = state.theme.kanjiResultColor;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
@ -31,5 +31,6 @@ class Grade extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,13 @@ class Header extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => AspectRatio(
|
||||||
final colors =
|
|
||||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
|
||||||
|
|
||||||
return AspectRatio(
|
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
child: Container(
|
child: BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final colors = state.theme.kanjiResultColor;
|
||||||
|
|
||||||
|
return Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10.0),
|
borderRadius: BorderRadius.circular(10.0),
|
||||||
color: colors.background,
|
color: colors.background,
|
||||||
@ -28,7 +28,8 @@ class Header extends StatelessWidget {
|
|||||||
style: TextStyle(fontSize: 70.0, color: colors.foreground),
|
style: TextStyle(fontSize: 70.0, color: colors.foreground),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -13,10 +13,9 @@ class JlptLevel extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final colors =
|
builder: (context, state) {
|
||||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
final colors = state.theme.kanjiResultColor;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -31,5 +30,6 @@ class JlptLevel extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,15 @@ import '../../../bloc/theme/theme_bloc.dart';
|
|||||||
class Radical extends StatelessWidget {
|
class Radical extends StatelessWidget {
|
||||||
final jisho.Radical radical;
|
final jisho.Radical radical;
|
||||||
|
|
||||||
const Radical({required this.radical, Key? key,}) : super(key: key);
|
const Radical({
|
||||||
|
required this.radical,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final colors = BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
builder: (context, state) {
|
||||||
|
final colors = state.theme.kanjiResultColor;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(15.0),
|
padding: const EdgeInsets.all(15.0),
|
||||||
@ -26,5 +30,6 @@ class Radical extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ class Rank extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final colors =
|
builder: (context, state) {
|
||||||
BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
final colors = state.theme.kanjiResultColor;
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
@ -32,5 +32,6 @@ class Rank extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,19 @@ import '../../../bloc/theme/theme_bloc.dart';
|
|||||||
class StrokeOrderGif extends StatelessWidget {
|
class StrokeOrderGif extends StatelessWidget {
|
||||||
final String uri;
|
final String uri;
|
||||||
|
|
||||||
const StrokeOrderGif({required this.uri, Key? key,}) : super(key: key);
|
const StrokeOrderGif({
|
||||||
|
required this.uri,
|
||||||
|
Key? key,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
final colors = BlocProvider.of<ThemeBloc>(context).state.theme.kanjiResultColor;
|
builder: (context, state) {
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.symmetric(vertical: 20.0),
|
margin: const EdgeInsets.symmetric(vertical: 20.0),
|
||||||
padding: const EdgeInsets.all(5.0),
|
padding: const EdgeInsets.all(5.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: colors.background,
|
color: state.theme.kanjiResultColor.background,
|
||||||
borderRadius: BorderRadius.circular(15.0),
|
borderRadius: BorderRadius.circular(15.0),
|
||||||
),
|
),
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
@ -24,5 +25,6 @@ class StrokeOrderGif extends StatelessWidget {
|
|||||||
child: Image.network(uri),
|
child: Image.network(uri),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ extension on YomiType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ColorSet getColors(BuildContext context) {
|
ColorSet getColors(BuildContext context) {
|
||||||
|
// TODO: convert this into a blocbuilder or bloclistener
|
||||||
final theme = BlocProvider.of<ThemeBloc>(context).state.theme;
|
final theme = BlocProvider.of<ThemeBloc>(context).state.theme;
|
||||||
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
|
@ -20,12 +20,14 @@ class KanjiSearchOptionsBar extends StatelessWidget {
|
|||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
_IconButton(
|
_IconButton(
|
||||||
icon: const Icon(Icons.school),
|
icon: const Icon(Icons.school),
|
||||||
onPressed: () => Navigator.pushNamed(context, Routes.kanjiSearchGrade),
|
onPressed: () =>
|
||||||
|
Navigator.pushNamed(context, Routes.kanjiSearchGrade),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
_IconButton(
|
_IconButton(
|
||||||
icon: const Icon(Icons.mode),
|
icon: const Icon(Icons.mode),
|
||||||
onPressed: () => Navigator.pushNamed(context, Routes.kanjiSearchDraw),
|
onPressed: () =>
|
||||||
|
Navigator.pushNamed(context, Routes.kanjiSearchDraw),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -44,12 +46,12 @@ class _IconButton extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
return IconButton(
|
builder: (context, state) => IconButton(
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
iconSize: 30,
|
iconSize: 30,
|
||||||
color: BlocProvider.of<ThemeBloc>(context).state.theme.menuGreyDark.background,
|
color: state.theme.menuGreyDark.background,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -156,15 +156,13 @@ class _KanjiRadicalSearchState extends State<KanjiRadicalSearch> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: (suggestions.isEmpty)
|
child: (suggestions.isEmpty)
|
||||||
? Center(
|
? Center(
|
||||||
child: Text(
|
child: BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
|
builder: (context, state) => Text(
|
||||||
'Toggle a radical to start',
|
'Toggle a radical to start',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: fontSize * 0.8,
|
fontSize: fontSize * 0.8,
|
||||||
color: BlocProvider.of<ThemeBloc>(context)
|
color: state.theme.menuGreyNormal.background,
|
||||||
.state
|
),
|
||||||
.theme
|
|
||||||
.menuGreyNormal
|
|
||||||
.background,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -37,11 +37,11 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
||||||
|
builder: (context, state) {
|
||||||
final TextStyle _titleTextStyle = TextStyle(
|
final TextStyle _titleTextStyle = TextStyle(
|
||||||
color: BlocProvider.of<ThemeBloc>(context).state is DarkThemeState
|
color:
|
||||||
? AppTheme.jishoGreen.background
|
state is DarkThemeState ? AppTheme.jishoGreen.background : null,
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return SettingsList(
|
return SettingsList(
|
||||||
@ -145,5 +145,6 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user