Jisho-Study-Tool/lib/view/components/kanji/result/meaning.dart

81 lines
1.7 KiB
Dart
Raw Normal View History

2020-07-16 14:08:51 +02:00
import 'package:flutter/material.dart';
class Meaning extends StatelessWidget {
2021-03-03 00:24:25 +01: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) {
2021-03-03 00:24:25 +01:00
if (expandable) {
2020-07-16 22:11:55 +02:00
return ExpansionTile(
initiallyExpanded: false,
title: Center(child: _MeaningCard('Meanings')),
children: [
SizedBox(
height: 20.0,
),
Wrap(
runSpacing: 10.0,
2021-03-03 00:24:25 +01:00
children: meaningCards,
2020-07-16 22:11:55 +02:00
),
SizedBox(
height: 25.0,
),
],
);
} else {
return Wrap(
2020-07-16 14:08:51 +02:00
runSpacing: 10.0,
2021-03-03 00:24:25 +01:00
children: meaningCards,
2020-07-16 22:11:55 +02:00
);
}
}
2021-03-03 00:24:25 +01:00
Meaning(meaning) {
this.meanings = meaning.split(', ');
this.meaningCards =
meanings.map((m) => _MeaningCard(m)).toList();
this.expandable = (this.meanings.length > 6);
2020-07-16 22:11:55 +02:00
}
}
class _MeaningCard extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final String meaning;
2020-07-16 22:11:55 +02:00
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 10.0,
),
child: Text(
2021-03-03 00:24:25 +01:00
meaning,
2020-07-16 22:11:55 +02:00
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
),
);
}
2021-03-03 00:24:25 +01:00
_MeaningCard(this.meaning);
2020-07-16 14:08:51 +02:00
}