Modularize search_card parts

pull/4/head
Oystein Kristoffer Tveit 2020-08-23 00:38:42 +02:00
parent 5681b9708c
commit c4e5fdd9ff
3 changed files with 76 additions and 61 deletions

View File

@ -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),
],
),
);
}
}

View File

@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart';
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);
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),
),
],
),
);
}
}

View File

@ -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<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);
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),
),
],
),
);
}
}