From c7f6f8c4b2931196aac820b41e9248c495e6f104 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 24 Aug 2020 23:45:47 +0200 Subject: [PATCH] Update search card layout --- lib/components/search/parts/header.dart | 2 + lib/components/search/parts/other_forms.dart | 17 ++++++-- lib/components/search/parts/senses.dart | 42 ++++++++++++++++++++ lib/components/search/search_card.dart | 7 +++- 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 lib/components/search/parts/senses.dart diff --git a/lib/components/search/parts/header.dart b/lib/components/search/parts/header.dart index 8849aff..6b75b6a 100644 --- a/lib/components/search/parts/header.dart +++ b/lib/components/search/parts/header.dart @@ -10,6 +10,8 @@ class JapaneseHeader extends StatelessWidget { final hasFurigana = (_word.word != null); return Container( + alignment: Alignment.centerLeft, + padding: EdgeInsets.only(left: 10.0), child: Column( children: [ (hasFurigana) ? Text(_word.reading) : Text(''), diff --git a/lib/components/search/parts/other_forms.dart b/lib/components/search/parts/other_forms.dart index e26558f..ca83901 100644 --- a/lib/components/search/parts/other_forms.dart +++ b/lib/components/search/parts/other_forms.dart @@ -8,9 +8,18 @@ class OtherForms extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - child: Row( - children: _otherForms.map((form) => _KanaBox(form)).toList(), - )); + child: Column( + children: [ + Text( + 'Other Forms', + style: TextStyle(fontWeight: FontWeight.bold), + ), + Row( + children: _otherForms.map((form) => _KanaBox(form)).toList(), + ), + ], + ), + ); } } @@ -47,4 +56,4 @@ class _KanaBox extends StatelessWidget { ), ); } -} \ No newline at end of file +} diff --git a/lib/components/search/parts/senses.dart b/lib/components/search/parts/senses.dart new file mode 100644 index 0000000..3d3771d --- /dev/null +++ b/lib/components/search/parts/senses.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:unofficial_jisho_api/parser.dart'; + +class Senses extends StatelessWidget { + final List _senses; + const Senses(this._senses); + + @override + Widget build(BuildContext context) { + final List _senseWidgets = + _senses.map((sense) => _Sense(sense)).toList(); + + return Container( + child: Column( + children: _senseWidgets, + )); + } +} + +class _Sense extends StatelessWidget { + final JishoWordSense _sense; + const _Sense(this._sense); + + @override + Widget build(BuildContext context) { + return Container( + child: Column( + children: [ + Text( + _sense.parts_of_speech.join(', '), + style: TextStyle(fontWeight: FontWeight.bold), + textAlign: TextAlign.left, + ), + Column( + children: + _sense.english_definitions.map((def) => Text(def)).toList(), + ) + ], + ), + ); + } +} diff --git a/lib/components/search/search_card.dart b/lib/components/search/search_card.dart index 6d445f1..20b2032 100644 --- a/lib/components/search/search_card.dart +++ b/lib/components/search/search_card.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:unofficial_jisho_api/api.dart'; import 'parts/header.dart'; +import 'parts/senses.dart'; import 'parts/other_forms.dart'; class SearchResultCard extends StatelessWidget { @@ -19,8 +20,10 @@ class SearchResultCard extends StatelessWidget { Widget build(BuildContext context) { return ExpansionTile( title: JapaneseHeader(_mainWord), - children: [OtherForms(_otherForms)], + children: [ + Senses(_result.senses), + OtherForms(_otherForms), + ], ); } } -