diff --git a/lib/components/drawing_board/drawing_board.dart b/lib/components/drawing_board/drawing_board.dart index 8244ec5..8da9d86 100644 --- a/lib/components/drawing_board/drawing_board.dart +++ b/lib/components/drawing_board/drawing_board.dart @@ -95,23 +95,28 @@ class _DrawingBoardState extends State { Widget kanjiChip(String kanji) => InkWell( onTap: () => widget.onSuggestionChosen?.call(kanji), - child: Container( - height: fontSize + 2 * suggestionCirclePadding, - width: fontSize + 2 * suggestionCirclePadding, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: BlocProvider.of(context) - .state - .theme - .menuGreyLight - .background, - ), - child: Center( - child: Text( - kanji, - style: const TextStyle(fontSize: fontSize), - ), - ), + child: BlocBuilder( + builder: (context, state) { + final colors = state.theme.menuGreyLight; + + return Container( + height: fontSize + 2 * suggestionCirclePadding, + width: fontSize + 2 * suggestionCirclePadding, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: colors.background, + ), + child: Center( + child: Text( + kanji, + style: TextStyle( + fontSize: fontSize, + color: colors.foreground, + ), + ), + ), + ); + }, ), ); diff --git a/lib/components/history/date_divider.dart b/lib/components/history/date_divider.dart index 91d4674..572e5ca 100644 --- a/lib/components/history/date_divider.dart +++ b/lib/components/history/date_divider.dart @@ -36,23 +36,23 @@ class DateDivider extends StatelessWidget { } @override - Widget build(BuildContext context) { - final Widget header = - (text != null) ? Text(text!) : Text(getHumanReadableDate(date!)); + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final colors = state.theme.menuGreyNormal; - final ColorSet _menuColors = - BlocProvider.of(context).state.theme.menuGreyNormal; - - return Container( - decoration: BoxDecoration(color: _menuColors.background), - padding: const EdgeInsets.symmetric( - vertical: 5, - horizontal: 10, - ), - child: DefaultTextStyle.merge( - child: header, - style: TextStyle(color: _menuColors.foreground), - ), - ); - } + return Container( + decoration: BoxDecoration(color: colors.background), + padding: const EdgeInsets.symmetric( + vertical: 5, + horizontal: 10, + ), + child: DefaultTextStyle.merge( + child: (text != null) + ? Text(text!) + : Text(getHumanReadableDate(date!)), + style: TextStyle(color: colors.foreground), + ), + ); + }, + ); } diff --git a/lib/components/history/kanji_box.dart b/lib/components/history/kanji_box.dart index 037465f..66d8382 100644 --- a/lib/components/history/kanji_box.dart +++ b/lib/components/history/kanji_box.dart @@ -11,32 +11,32 @@ class KanjiBox extends StatelessWidget { }) : super(key: key); @override - Widget build(BuildContext context) { - final ColorSet menuColors = - BlocProvider.of(context).state.theme.menuGreyLight; - - return IntrinsicHeight( - child: AspectRatio( - aspectRatio: 1, - child: Container( - padding: const EdgeInsets.all(5), - decoration: BoxDecoration( - color: menuColors.background, - borderRadius: BorderRadius.circular(10.0), - ), - child: Center( - child: FittedBox( - child: Text( - kanji, - style: TextStyle( - color: menuColors.foreground, - fontSize: 25, + Widget build(BuildContext context) => IntrinsicHeight( + child: AspectRatio( + aspectRatio: 1, + child: BlocBuilder( + builder: (context, state) { + final colors = state.theme.menuGreyLight; + return Container( + padding: const EdgeInsets.all(5), + decoration: BoxDecoration( + color: colors.background, + borderRadius: BorderRadius.circular(10.0), ), - ), - ), + child: Center( + child: FittedBox( + child: Text( + kanji, + style: TextStyle( + color: colors.foreground, + fontSize: 25, + ), + ), + ), + ), + ); + }, ), ), - ), - ); - } + ); } diff --git a/lib/components/kanji/kanji_result_body/examples.dart b/lib/components/kanji/kanji_result_body/examples.dart index 8e79cc0..0d694b5 100644 --- a/lib/components/kanji/kanji_result_body/examples.dart +++ b/lib/components/kanji/kanji_result_body/examples.dart @@ -53,31 +53,34 @@ class _Example extends StatelessWidget { const _Example(this.yomiExample, this.kanaType); @override - Widget build(BuildContext context) { - final theme = BlocProvider.of(context).state.theme; - final menuColors = theme.menuGreyNormal; - final kanaColors = - kanaType == _KanaType.kunyomi ? theme.kunyomiColor : theme.onyomiColor; + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final theme = state.theme; + final menuColors = theme.menuGreyNormal; + final kanaColors = kanaType == _KanaType.kunyomi + ? theme.kunyomiColor + : theme.onyomiColor; - return Container( - margin: const EdgeInsets.symmetric( - vertical: 5.0, - horizontal: 10.0, - ), - decoration: BoxDecoration( - color: menuColors.background, - borderRadius: BorderRadius.circular(10.0), - ), - child: IntrinsicHeight( - child: Row( - children: [ - _Kana(colors: kanaColors, example: yomiExample), - _ExampleText(colors: menuColors, example: yomiExample) - ], - ), - ), - ); - } + return Container( + margin: const EdgeInsets.symmetric( + vertical: 5.0, + horizontal: 10.0, + ), + decoration: BoxDecoration( + color: menuColors.background, + borderRadius: BorderRadius.circular(10.0), + ), + child: IntrinsicHeight( + child: Row( + children: [ + _Kana(colors: kanaColors, example: yomiExample), + _ExampleText(colors: menuColors, example: yomiExample) + ], + ), + ), + ); + }, + ); } class _Kana extends StatelessWidget { diff --git a/lib/components/kanji/kanji_result_body/grade.dart b/lib/components/kanji/kanji_result_body/grade.dart index 0850d35..63bac94 100644 --- a/lib/components/kanji/kanji_result_body/grade.dart +++ b/lib/components/kanji/kanji_result_body/grade.dart @@ -13,23 +13,24 @@ class Grade extends StatelessWidget { }) : super(key: key); @override - Widget build(BuildContext context) { - final colors = - BlocProvider.of(context).state.theme.kanjiResultColor; + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final colors = state.theme.kanjiResultColor; - return Container( - padding: const EdgeInsets.all(10.0), - decoration: BoxDecoration( - color: colors.background, - shape: BoxShape.circle, - ), - child: Text( - grade ?? ifNullChar, - style: TextStyle( - color: colors.foreground, - fontSize: 20.0, - ), - ), - ); - } + return Container( + padding: const EdgeInsets.all(10.0), + decoration: BoxDecoration( + color: colors.background, + shape: BoxShape.circle, + ), + child: Text( + grade ?? ifNullChar, + style: TextStyle( + color: colors.foreground, + fontSize: 20.0, + ), + ), + ); + }, + ); } diff --git a/lib/components/kanji/kanji_result_body/header.dart b/lib/components/kanji/kanji_result_body/header.dart index 222cdc0..7df084d 100644 --- a/lib/components/kanji/kanji_result_body/header.dart +++ b/lib/components/kanji/kanji_result_body/header.dart @@ -11,24 +11,25 @@ class Header extends StatelessWidget { }) : super(key: key); @override - Widget build(BuildContext context) { - final colors = - BlocProvider.of(context).state.theme.kanjiResultColor; + Widget build(BuildContext context) => AspectRatio( + aspectRatio: 1, + child: BlocBuilder( + builder: (context, state) { + final colors = state.theme.kanjiResultColor; - return AspectRatio( - aspectRatio: 1, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10.0), - color: colors.background, + return Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + color: colors.background, + ), + child: Center( + child: Text( + kanji, + style: TextStyle(fontSize: 70.0, color: colors.foreground), + ), + ), + ); + }, ), - child: Center( - child: Text( - kanji, - style: TextStyle(fontSize: 70.0, color: colors.foreground), - ), - ), - ), - ); - } + ); } diff --git a/lib/components/kanji/kanji_result_body/jlpt_level.dart b/lib/components/kanji/kanji_result_body/jlpt_level.dart index 19bc47a..ef62eed 100644 --- a/lib/components/kanji/kanji_result_body/jlpt_level.dart +++ b/lib/components/kanji/kanji_result_body/jlpt_level.dart @@ -13,23 +13,23 @@ class JlptLevel extends StatelessWidget { }) : super(key: key); @override - Widget build(BuildContext context) { - final colors = - BlocProvider.of(context).state.theme.kanjiResultColor; - - return Container( - padding: const EdgeInsets.all(10.0), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: colors.background, - ), - child: Text( - jlptLevel ?? ifNullChar, - style: TextStyle( - color: colors.foreground, - fontSize: 20.0, - ), - ), - ); - } + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final colors = state.theme.kanjiResultColor; + return Container( + padding: const EdgeInsets.all(10.0), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: colors.background, + ), + child: Text( + jlptLevel ?? ifNullChar, + style: TextStyle( + color: colors.foreground, + fontSize: 20.0, + ), + ), + ); + }, + ); } diff --git a/lib/components/kanji/kanji_result_body/radical.dart b/lib/components/kanji/kanji_result_body/radical.dart index b3d9e03..75aac51 100644 --- a/lib/components/kanji/kanji_result_body/radical.dart +++ b/lib/components/kanji/kanji_result_body/radical.dart @@ -6,25 +6,30 @@ 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(context).state.theme.kanjiResultColor; + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final colors = state.theme.kanjiResultColor; - return Container( - padding: const EdgeInsets.all(15.0), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: colors.background, - ), - child: Text( - radical.symbol, - style: TextStyle( - color: colors.foreground, - fontSize: 40.0, - ), - ), - ); - } + return Container( + padding: const EdgeInsets.all(15.0), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: colors.background, + ), + child: Text( + radical.symbol, + style: TextStyle( + color: colors.foreground, + fontSize: 40.0, + ), + ), + ); + }, + ); } diff --git a/lib/components/kanji/kanji_result_body/rank.dart b/lib/components/kanji/kanji_result_body/rank.dart index 5295f0b..2d8c8b9 100644 --- a/lib/components/kanji/kanji_result_body/rank.dart +++ b/lib/components/kanji/kanji_result_body/rank.dart @@ -13,24 +13,25 @@ class Rank extends StatelessWidget { }) : super(key: key); @override - Widget build(BuildContext context) { - final colors = - BlocProvider.of(context).state.theme.kanjiResultColor; + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final colors = state.theme.kanjiResultColor; - return Container( - padding: const EdgeInsets.all(10.0), - decoration: BoxDecoration( - shape: (rank == null) ? BoxShape.circle : BoxShape.rectangle, - borderRadius: (rank == null) ? null : BorderRadius.circular(10.0), - color: colors.background, - ), - child: Text( - rank != null ? '${rank.toString()} / 2500' : ifNullChar, - style: TextStyle( - color: colors.foreground, - fontSize: 20.0, - ), - ), - ); - } + return Container( + padding: const EdgeInsets.all(10.0), + decoration: BoxDecoration( + shape: (rank == null) ? BoxShape.circle : BoxShape.rectangle, + borderRadius: (rank == null) ? null : BorderRadius.circular(10.0), + color: colors.background, + ), + child: Text( + rank != null ? '${rank.toString()} / 2500' : ifNullChar, + style: TextStyle( + color: colors.foreground, + fontSize: 20.0, + ), + ), + ); + }, + ); } diff --git a/lib/components/kanji/kanji_result_body/stroke_order_gif.dart b/lib/components/kanji/kanji_result_body/stroke_order_gif.dart index decf273..fcb40c0 100644 --- a/lib/components/kanji/kanji_result_body/stroke_order_gif.dart +++ b/lib/components/kanji/kanji_result_body/stroke_order_gif.dart @@ -5,24 +5,26 @@ 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(context).state.theme.kanjiResultColor; - - return Container( - margin: const EdgeInsets.symmetric(vertical: 20.0), - padding: const EdgeInsets.all(5.0), - decoration: BoxDecoration( - color: colors.background, - borderRadius: BorderRadius.circular(15.0), - ), - child: ClipRRect( - borderRadius: BorderRadius.circular(10.0), - child: Image.network(uri), - ), - ); - } + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + return Container( + margin: const EdgeInsets.symmetric(vertical: 20.0), + padding: const EdgeInsets.all(5.0), + decoration: BoxDecoration( + color: state.theme.kanjiResultColor.background, + borderRadius: BorderRadius.circular(15.0), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(10.0), + child: Image.network(uri), + ), + ); + }, + ); } diff --git a/lib/components/kanji/kanji_result_body/yomi_chips.dart b/lib/components/kanji/kanji_result_body/yomi_chips.dart index 941f0af..8918f40 100644 --- a/lib/components/kanji/kanji_result_body/yomi_chips.dart +++ b/lib/components/kanji/kanji_result_body/yomi_chips.dart @@ -23,6 +23,7 @@ extension on YomiType { } ColorSet getColors(BuildContext context) { + // TODO: convert this into a blocbuilder or bloclistener final theme = BlocProvider.of(context).state.theme; switch (this) { diff --git a/lib/components/kanji/kanji_search_body/kanji_search_options_bar.dart b/lib/components/kanji/kanji_search_body/kanji_search_options_bar.dart index f6f31b9..a562755 100644 --- a/lib/components/kanji/kanji_search_body/kanji_search_options_bar.dart +++ b/lib/components/kanji/kanji_search_body/kanji_search_options_bar.dart @@ -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( - onPressed: onPressed, - icon: icon, - iconSize: 30, - color: BlocProvider.of(context).state.theme.menuGreyDark.background, - ); - } + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) => IconButton( + onPressed: onPressed, + icon: icon, + iconSize: 30, + color: state.theme.menuGreyDark.background, + ), + ); } diff --git a/lib/screens/search/search_mechanisms/radical_list.dart b/lib/screens/search/search_mechanisms/radical_list.dart index a8d08a5..a1a48c6 100644 --- a/lib/screens/search/search_mechanisms/radical_list.dart +++ b/lib/screens/search/search_mechanisms/radical_list.dart @@ -156,15 +156,13 @@ class _KanjiRadicalSearchState extends State { Expanded( child: (suggestions.isEmpty) ? Center( - child: Text( - 'Toggle a radical to start', - style: TextStyle( - fontSize: fontSize * 0.8, - color: BlocProvider.of(context) - .state - .theme - .menuGreyNormal - .background, + child: BlocBuilder( + builder: (context, state) => Text( + 'Toggle a radical to start', + style: TextStyle( + fontSize: fontSize * 0.8, + color: state.theme.menuGreyNormal.background, + ), ), ), ) diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 2fea4fd..e69ad44 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -37,113 +37,114 @@ class _SettingsViewState extends State { } @override - Widget build(BuildContext context) { - final TextStyle _titleTextStyle = TextStyle( - color: BlocProvider.of(context).state is DarkThemeState - ? AppTheme.jishoGreen.background - : null, - ); + Widget build(BuildContext context) => BlocBuilder( + builder: (context, state) { + final TextStyle _titleTextStyle = TextStyle( + color: + state is DarkThemeState ? AppTheme.jishoGreen.background : null, + ); - return SettingsList( - backgroundColor: Colors.transparent, - contentPadding: const EdgeInsets.symmetric(vertical: 10), - sections: [ - SettingsSection( - title: 'Dictionary', - titleTextStyle: _titleTextStyle, - tiles: [ - SettingsTile.switchTile( - title: 'Use romaji', - onToggle: (b) { - setState(() => romajiEnabled = b); - }, - switchValue: romajiEnabled, - switchActiveColor: AppTheme.jishoGreen.background, - ), - ], - ), - SettingsSection( - title: 'Theme', - titleTextStyle: _titleTextStyle, - tiles: [ - SettingsTile.switchTile( - title: 'Automatically determine theme', - onToggle: toggleAutoTheme, - switchValue: autoThemeEnabled, - switchActiveColor: AppTheme.jishoGreen.background, - ), - SettingsTile.switchTile( - title: 'Dark Theme', - onToggle: (b) { - BlocProvider.of(context) - .add(SetTheme(themeIsDark: b)); - setState(() => darkThemeEnabled = b); - }, - switchValue: darkThemeEnabled, - enabled: !autoThemeEnabled, - switchActiveColor: AppTheme.jishoGreen.background, - ), - ], - ), - SettingsSection( - title: 'Cache', - titleTextStyle: _titleTextStyle, - tiles: [ - SettingsTile.switchTile( - title: 'Cache grade 1-7 kanji', - switchValue: false, - onToggle: (v) {}, - enabled: false, - switchActiveColor: AppTheme.jishoGreen.background, - ), - SettingsTile.switchTile( - title: 'Cache grade standard kanji', - switchValue: false, - onToggle: (v) {}, - enabled: false, - switchActiveColor: AppTheme.jishoGreen.background, - ), - SettingsTile.switchTile( - title: 'Cache all favourites', - switchValue: false, - onToggle: (v) {}, - enabled: false, - switchActiveColor: AppTheme.jishoGreen.background, - ), - SettingsTile.switchTile( - title: 'Cache all searches', - switchValue: false, - onToggle: (v) {}, - enabled: false, - switchActiveColor: AppTheme.jishoGreen.background, - ), - ], - ), - SettingsSection( - title: 'Data', - titleTextStyle: _titleTextStyle, - tiles: [ - SettingsTile( - leading: const Icon(Icons.file_download), - title: 'Export Data', - enabled: false, - ), - SettingsTile( - leading: const Icon(Icons.delete), - title: 'Clear History', - onPressed: clearHistory, - titleTextStyle: const TextStyle(color: Colors.red), - ), - SettingsTile( - leading: const Icon(Icons.delete), - title: 'Clear Favourites', - onPressed: (c) {}, - titleTextStyle: const TextStyle(color: Colors.red), - enabled: false, - ) - ], - ), - ], - ); - } + return SettingsList( + backgroundColor: Colors.transparent, + contentPadding: const EdgeInsets.symmetric(vertical: 10), + sections: [ + SettingsSection( + title: 'Dictionary', + titleTextStyle: _titleTextStyle, + tiles: [ + SettingsTile.switchTile( + title: 'Use romaji', + onToggle: (b) { + setState(() => romajiEnabled = b); + }, + switchValue: romajiEnabled, + switchActiveColor: AppTheme.jishoGreen.background, + ), + ], + ), + SettingsSection( + title: 'Theme', + titleTextStyle: _titleTextStyle, + tiles: [ + SettingsTile.switchTile( + title: 'Automatically determine theme', + onToggle: toggleAutoTheme, + switchValue: autoThemeEnabled, + switchActiveColor: AppTheme.jishoGreen.background, + ), + SettingsTile.switchTile( + title: 'Dark Theme', + onToggle: (b) { + BlocProvider.of(context) + .add(SetTheme(themeIsDark: b)); + setState(() => darkThemeEnabled = b); + }, + switchValue: darkThemeEnabled, + enabled: !autoThemeEnabled, + switchActiveColor: AppTheme.jishoGreen.background, + ), + ], + ), + SettingsSection( + title: 'Cache', + titleTextStyle: _titleTextStyle, + tiles: [ + SettingsTile.switchTile( + title: 'Cache grade 1-7 kanji', + switchValue: false, + onToggle: (v) {}, + enabled: false, + switchActiveColor: AppTheme.jishoGreen.background, + ), + SettingsTile.switchTile( + title: 'Cache grade standard kanji', + switchValue: false, + onToggle: (v) {}, + enabled: false, + switchActiveColor: AppTheme.jishoGreen.background, + ), + SettingsTile.switchTile( + title: 'Cache all favourites', + switchValue: false, + onToggle: (v) {}, + enabled: false, + switchActiveColor: AppTheme.jishoGreen.background, + ), + SettingsTile.switchTile( + title: 'Cache all searches', + switchValue: false, + onToggle: (v) {}, + enabled: false, + switchActiveColor: AppTheme.jishoGreen.background, + ), + ], + ), + SettingsSection( + title: 'Data', + titleTextStyle: _titleTextStyle, + tiles: [ + SettingsTile( + leading: const Icon(Icons.file_download), + title: 'Export Data', + enabled: false, + ), + SettingsTile( + leading: const Icon(Icons.delete), + title: 'Clear History', + onPressed: clearHistory, + titleTextStyle: const TextStyle(color: Colors.red), + ), + SettingsTile( + leading: const Icon(Icons.delete), + title: 'Clear Favourites', + onPressed: (c) {}, + titleTextStyle: const TextStyle(color: Colors.red), + enabled: false, + ) + ], + ), + ], + ); + }, + ); }