mirror of
https://github.com/h7x4/Jisho-Study-Tool.git
synced 2024-12-23 06:17:29 +01:00
h7x4
28f900c02e
* Add lots of new functionality to search results * Fix jlpt level * Make antonyms clickable * Add kanji list * Replace Blocof with BlocBuilder * Make kanji widgets squared * Add missing colons to headers * add romaji under sentences * Fix extensive search not showing * Miscellaneous refactoring
92 lines
3.0 KiB
Dart
92 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:unofficial_jisho_api/api.dart';
|
|
|
|
import '../../../../../bloc/theme/theme_bloc.dart';
|
|
import 'antonyms.dart';
|
|
import 'definition_abstract.dart';
|
|
import 'english_definitions.dart';
|
|
import 'sentences.dart';
|
|
import 'supplemental_info.dart';
|
|
|
|
class Sense extends StatelessWidget {
|
|
final int index;
|
|
final JishoWordSense sense;
|
|
final PhraseScrapeMeaning? meaning;
|
|
|
|
const Sense({
|
|
Key? key,
|
|
required this.index,
|
|
required this.sense,
|
|
this.meaning,
|
|
}) : super(key: key);
|
|
|
|
// TODO: This assumes that there is only one antonym. However, the
|
|
// antonym system is made with the case of multiple antonyms
|
|
// in mind.
|
|
List<String> _removeAntonyms(List<String> supplementalInfo) {
|
|
for (int i = 0; i < supplementalInfo.length; i++) {
|
|
if (RegExp(r'^Antonym: .*$').hasMatch(supplementalInfo[i])) {
|
|
supplementalInfo.removeAt(i);
|
|
break;
|
|
}
|
|
}
|
|
return supplementalInfo;
|
|
}
|
|
|
|
List<String>? get _supplementalWithoutAntonyms => meaning == null
|
|
? null
|
|
: _removeAntonyms(List.from(meaning!.supplemental));
|
|
|
|
bool get hasSupplementalInfo =>
|
|
sense.info.isNotEmpty ||
|
|
sense.source.isNotEmpty ||
|
|
sense.tags.isNotEmpty ||
|
|
(_supplementalWithoutAntonyms?.isNotEmpty ?? false);
|
|
|
|
@override
|
|
Widget build(BuildContext context) => BlocBuilder<ThemeBloc, ThemeState>(
|
|
builder: (context, state) => Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 5),
|
|
padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
color: state.theme.menuGreyLight.background,
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
'${index + 1}. ${sense.partsOfSpeech.join(', ')}',
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
textAlign: TextAlign.left,
|
|
),
|
|
EnglishDefinitions(
|
|
englishDefinitions: sense.englishDefinitions,
|
|
colors: state.theme.menuGreyNormal,
|
|
),
|
|
if (hasSupplementalInfo)
|
|
SupplementalInfo(
|
|
sense: sense,
|
|
supplementalInfo: _supplementalWithoutAntonyms,
|
|
),
|
|
if (meaning?.definitionAbstract != null)
|
|
DefinitionAbstract(
|
|
text: meaning!.definitionAbstract!,
|
|
color: state.theme.foreground,
|
|
),
|
|
if (sense.antonyms.isNotEmpty) Antonyms(antonyms: sense.antonyms),
|
|
if (meaning != null && meaning!.sentences.isNotEmpty)
|
|
Sentences(sentences: meaning!.sentences)
|
|
]
|
|
.map(
|
|
(e) => Container(
|
|
margin: const EdgeInsets.symmetric(vertical: 5),
|
|
child: e,
|
|
),
|
|
)
|
|
.toList(),
|
|
),
|
|
),
|
|
);
|
|
}
|