1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 13:37:29 +01:00

Wrap yomi on large amount

This commit is contained in:
Oystein Kristoffer Tveit 2020-07-16 22:49:07 +02:00
parent 99256f6b3c
commit 95927ace4d
2 changed files with 120 additions and 48 deletions

View File

@ -2,6 +2,13 @@ import 'package:flutter/material.dart';
class Kunyomi extends StatelessWidget {
final List<String> _kunyomi;
List<_KunyomiCard> _kunyomiCards;
bool _expandable;
Kunyomi(this._kunyomi) {
_kunyomiCards = _kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList();
_expandable = (_kunyomi.length > 6);
}
@override
Widget build(BuildContext context) {
@ -11,31 +18,60 @@ class Kunyomi extends StatelessWidget {
vertical: 5.0,
),
alignment: Alignment.centerLeft,
child: Wrap(
runSpacing: 10.0,
children: _kunyomi.map((onyomi) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 10.0,
),
child: Text(
onyomi,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
decoration: BoxDecoration(
color: Colors.lightBlue,
borderRadius: BorderRadius.circular(10.0),
),
);
}).toList(),
),
child: _KunyomiWrapper(context),
);
}
Kunyomi(this._kunyomi);
Widget _KunyomiWrapper(BuildContext context) {
if (_expandable) {
return ExpansionTile(
initiallyExpanded: false,
title: Center(child: _KunyomiCard('Kunyomi')),
children: [
SizedBox(
height: 20.0,
),
Wrap(
runSpacing: 10.0,
children: _kunyomiCards,
),
SizedBox(
height: 25.0,
),
],
);
} else {
return Wrap(
runSpacing: 10.0,
children: _kunyomiCards,
);
}
}
}
class _KunyomiCard extends StatelessWidget {
final String _kunyomi;
const _KunyomiCard(this._kunyomi);
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 10.0,
),
child: Text(
_kunyomi,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
decoration: BoxDecoration(
color: Colors.lightBlue,
borderRadius: BorderRadius.circular(10.0),
),
);
}
}

View File

@ -2,6 +2,13 @@ import 'package:flutter/material.dart';
class Onyomi extends StatelessWidget {
final List<String> _onyomi;
List<_OnyomiCard> _onyomiCards;
bool _expandable;
Onyomi(this._onyomi) {
_onyomiCards = _onyomi.map((onyomi) => _OnyomiCard(onyomi)).toList();
_expandable = (_onyomi.length > 6);
}
@override
Widget build(BuildContext context) {
@ -11,31 +18,60 @@ class Onyomi extends StatelessWidget {
vertical: 5.0,
),
alignment: Alignment.centerLeft,
child: Wrap(
runSpacing: 10.0,
children: _onyomi.map((onyomi) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 10.0,
),
child: Text(
onyomi,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(10.0),
),
);
}).toList(),
),
child: _OnyomiWrapper(context),
);
}
Onyomi(this._onyomi);
Widget _OnyomiWrapper(BuildContext context) {
if (_expandable) {
return ExpansionTile(
initiallyExpanded: false,
title: Center(child: _OnyomiCard('Onyomi')),
children: [
SizedBox(
height: 20.0,
),
Wrap(
runSpacing: 10.0,
children: _onyomiCards,
),
SizedBox(
height: 25.0,
),
],
);
} else {
return Wrap(
runSpacing: 10.0,
children: _onyomiCards,
);
}
}
}
class _OnyomiCard extends StatelessWidget {
final String _onyomi;
const _OnyomiCard(this._onyomi);
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 10.0),
padding: EdgeInsets.symmetric(
vertical: 10.0,
horizontal: 10.0,
),
child: Text(
_onyomi,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(10.0),
),
);
}
}