From c4e5fdd9ff63513a9b46041aa455a2b2e1005ac7 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Sun, 23 Aug 2020 00:38:42 +0200 Subject: [PATCH] Modularize search_card parts --- lib/components/search/parts/header.dart | 21 +++++++ lib/components/search/parts/other_forms.dart | 50 +++++++++++++++ lib/components/search/search_card.dart | 66 ++------------------ 3 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 lib/components/search/parts/header.dart create mode 100644 lib/components/search/parts/other_forms.dart diff --git a/lib/components/search/parts/header.dart b/lib/components/search/parts/header.dart new file mode 100644 index 0000000..8849aff --- /dev/null +++ b/lib/components/search/parts/header.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; +import 'package:unofficial_jisho_api/api.dart'; + +class JapaneseHeader extends StatelessWidget { + final JishoJapaneseWord _word; + const JapaneseHeader(this._word); + + @override + Widget build(BuildContext context) { + final hasFurigana = (_word.word != null); + + return Container( + child: Column( + children: [ + (hasFurigana) ? Text(_word.reading) : Text(''), + (hasFurigana) ? Text(_word.word) : Text(_word.reading), + ], + ), + ); + } +} diff --git a/lib/components/search/parts/other_forms.dart b/lib/components/search/parts/other_forms.dart new file mode 100644 index 0000000..e26558f --- /dev/null +++ b/lib/components/search/parts/other_forms.dart @@ -0,0 +1,50 @@ +import 'package:flutter/material.dart'; +import 'package:unofficial_jisho_api/api.dart'; + +class OtherForms extends StatelessWidget { + final List _otherForms; + OtherForms(this._otherForms); + + @override + Widget build(BuildContext context) { + return Container( + child: Row( + children: _otherForms.map((form) => _KanaBox(form)).toList(), + )); + } +} + +class _KanaBox extends StatelessWidget { + final JishoJapaneseWord _word; + const _KanaBox(this._word); + + @override + Widget build(BuildContext context) { + final hasFurigana = (_word.word != null); + + return Container( + child: Column( + children: [ + (hasFurigana) ? Text(_word.reading) : Text(''), + (hasFurigana) ? Text(_word.word) : Text(_word.reading), + ], + ), + margin: EdgeInsets.symmetric( + horizontal: 5.0, + vertical: 5.0, + ), + padding: EdgeInsets.all(5.0), + decoration: BoxDecoration( + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 1, + blurRadius: 0.5, + offset: Offset(1, 1), + ), + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/components/search/search_card.dart b/lib/components/search/search_card.dart index 6574ce4..6d445f1 100644 --- a/lib/components/search/search_card.dart +++ b/lib/components/search/search_card.dart @@ -2,6 +2,9 @@ import 'package:flutter/material.dart'; import 'package:unofficial_jisho_api/api.dart'; +import 'parts/header.dart'; +import 'parts/other_forms.dart'; + class SearchResultCard extends StatelessWidget { final JishoResult _result; JishoJapaneseWord _mainWord; @@ -15,68 +18,9 @@ class SearchResultCard extends StatelessWidget { @override Widget build(BuildContext context) { return ExpansionTile( - title: _JapaneseHeader(_mainWord), - children: [_OtherForms(_otherForms)], + title: JapaneseHeader(_mainWord), + children: [OtherForms(_otherForms)], ); } } -class _JapaneseHeader extends StatelessWidget { - final JishoJapaneseWord _word; - const _JapaneseHeader(this._word); - - @override - Widget build(BuildContext context) { - return Container( - child: _KanaBox(_word), - ); - } -} - -class _OtherForms extends StatelessWidget { - final List _otherForms; - _OtherForms(this._otherForms); - - @override - Widget build(BuildContext context) { - return Container( - child: Row( - children: _otherForms.map((form) => _KanaBox(form)).toList(), - )); - } -} - -class _KanaBox extends StatelessWidget { - final JishoJapaneseWord _word; - const _KanaBox(this._word); - - @override - Widget build(BuildContext context) { - final hasFurigana = (_word.word != null); - - return Container( - child: Column( - children: [ - (hasFurigana) ? Text(_word.reading) : Text(''), - (hasFurigana) ? Text(_word.word) : Text(_word.reading), - ], - ), - margin: EdgeInsets.symmetric( - horizontal: 5.0, - vertical: 5.0, - ), - padding: EdgeInsets.all(5.0), - decoration: BoxDecoration( - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.5), - spreadRadius: 1, - blurRadius: 0.5, - offset: Offset(1, 1), - ), - ], - ), - ); - } -}