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

78 lines
1.7 KiB
Dart
Raw Normal View History

2020-07-12 23:58:30 +02:00
import 'package:flutter/material.dart';
class Kunyomi extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final List<String> kunyomi;
2021-07-26 21:39:17 +02:00
late final List<_KunyomiCard> kunyomiCards;
late final bool expandable;
2020-07-16 22:49:07 +02:00
2021-03-03 00:24:25 +01:00
Kunyomi(this.kunyomi) {
kunyomiCards = kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList();
expandable = (kunyomi.length > 6);
2020-07-16 22:49:07 +02:00
}
2020-07-14 15:39:31 +02:00
2020-07-12 23:58:30 +02:00
@override
Widget build(BuildContext context) {
return Container(
2020-07-16 14:09:03 +02:00
margin: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 5.0,
),
alignment: Alignment.centerLeft,
2021-07-26 21:39:17 +02:00
child: _kunyomiWrapper(context),
2020-07-16 22:49:07 +02:00
);
}
2021-07-26 21:39:17 +02:00
Widget _kunyomiWrapper(BuildContext context) {
2021-03-03 00:24:25 +01:00
if (expandable) {
2020-07-16 22:49:07 +02:00
return ExpansionTile(
initiallyExpanded: false,
title: Center(child: _KunyomiCard('Kunyomi')),
children: [
SizedBox(
height: 20.0,
),
Wrap(
runSpacing: 10.0,
2021-03-03 00:24:25 +01:00
children: kunyomiCards,
2020-07-16 22:49:07 +02:00
),
SizedBox(
height: 25.0,
),
],
);
} else {
return Wrap(
2020-07-16 14:09:03 +02:00
runSpacing: 10.0,
2021-03-03 00:24:25 +01:00
children: kunyomiCards,
2020-07-16 22:49:07 +02:00
);
}
}
}
class _KunyomiCard extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final String kunyomi;
const _KunyomiCard(this.kunyomi);
2020-07-16 22:49:07 +02:00
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 10.0,
),
child: Text(
2021-03-03 00:24:25 +01:00
kunyomi,
2020-07-16 22:49:07 +02:00
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
decoration: BoxDecoration(
color: Colors.lightBlue,
borderRadius: BorderRadius.circular(10.0),
2020-07-14 15:39:31 +02:00
),
2020-07-12 23:58:30 +02:00
);
}
2020-07-14 15:39:31 +02:00
}