2020-07-09 22:17:10 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:unofficial_jisho_api/api.dart';
|
|
|
|
|
|
|
|
class SearchResultCard extends StatelessWidget {
|
|
|
|
final JishoResult _result;
|
2020-08-23 00:06:09 +02:00
|
|
|
JishoJapaneseWord _mainWord;
|
|
|
|
List<JishoJapaneseWord> _otherForms;
|
|
|
|
|
|
|
|
SearchResultCard(this._result) {
|
|
|
|
this._mainWord = _result.japanese[0];
|
|
|
|
this._otherForms = _result.japanese.sublist(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return ExpansionTile(
|
|
|
|
title: _JapaneseHeader(_mainWord),
|
|
|
|
children: [_OtherForms(_otherForms)],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _JapaneseHeader extends StatelessWidget {
|
|
|
|
final JishoJapaneseWord _word;
|
|
|
|
const _JapaneseHeader(this._word);
|
2020-07-09 22:17:10 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-08-23 00:06:09 +02:00
|
|
|
return Container(
|
|
|
|
child: _KanaBox(_word),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _OtherForms extends StatelessWidget {
|
|
|
|
final List<JishoJapaneseWord> _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);
|
|
|
|
|
2020-08-19 16:27:00 +02:00
|
|
|
return Container(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
2020-08-23 00:06:09 +02:00
|
|
|
(hasFurigana) ? Text(_word.reading) : Text(''),
|
|
|
|
(hasFurigana) ? Text(_word.word) : Text(_word.reading),
|
2020-08-19 16:27:00 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
margin: EdgeInsets.symmetric(
|
2020-08-23 00:06:09 +02:00
|
|
|
horizontal: 5.0,
|
|
|
|
vertical: 5.0,
|
2020-08-19 16:27:00 +02:00
|
|
|
),
|
2020-08-23 00:06:09 +02:00
|
|
|
padding: EdgeInsets.all(5.0),
|
2020-08-19 16:27:00 +02:00
|
|
|
decoration: BoxDecoration(
|
2020-08-23 00:06:09 +02:00
|
|
|
color: Colors.white,
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.grey.withOpacity(0.5),
|
|
|
|
spreadRadius: 1,
|
|
|
|
blurRadius: 0.5,
|
|
|
|
offset: Offset(1, 1),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-07-09 22:17:10 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|