Jisho-Study-Tool/lib/components/kanji/kanji__search_page/meaning.dart

81 lines
1.8 KiB
Dart
Raw Permalink Normal View History

2020-07-16 14:08:51 +02:00
import 'package:flutter/material.dart';
class Meaning extends StatelessWidget {
2020-07-16 22:11:55 +02:00
List<String> _meanings;
List<_MeaningCard> _meaningCards;
bool _expandable;
2020-07-16 14:08:51 +02:00
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 5.0,
),
alignment: Alignment.centerLeft,
2020-07-16 22:11:55 +02:00
child: _MeaningWrapper(context),
);
}
Widget _MeaningWrapper(BuildContext context) {
if (_expandable) {
return ExpansionTile(
initiallyExpanded: false,
title: Center(child: _MeaningCard('Meanings')),
children: [
SizedBox(
height: 20.0,
),
Wrap(
runSpacing: 10.0,
children: _meaningCards,
),
SizedBox(
height: 25.0,
),
],
);
} else {
return Wrap(
2020-07-16 14:08:51 +02:00
runSpacing: 10.0,
2020-07-16 22:11:55 +02:00
children: _meaningCards,
);
}
}
Meaning(_meaning) {
this._meanings = _meaning.split(', ');
this._meaningCards =
_meanings.map((meaning) => _MeaningCard(meaning)).toList();
this._expandable = (this._meanings.length > 6);
}
}
class _MeaningCard extends StatelessWidget {
final String _meaning;
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 10.0,
),
child: Text(
_meaning,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(10.0),
2020-07-16 14:08:51 +02:00
),
);
}
2020-07-16 22:11:55 +02:00
_MeaningCard(this._meaning);
2020-07-16 14:08:51 +02:00
}