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