Skip to content

Commit

Permalink
Move 'See also' text into a separate widget
Browse files Browse the repository at this point in the history
  • Loading branch information
petlyh committed Nov 7, 2024
1 parent 5e0d1f3 commit a5a1737
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 12 additions & 8 deletions lib/screens/word_details/definition_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import "package:jsdict/screens/word_details/word_details_screen.dart";
import "package:jsdict/widgets/link_span.dart";

class DefinitionTile extends StatelessWidget {
const DefinitionTile({
required this.definition,
this.textColor,
this.isLast = false,
});
const DefinitionTile({required this.definition, this.isLast = false});

final Definition definition;
final Color? textColor;
final bool isLast;

@override
Expand All @@ -40,13 +35,22 @@ class DefinitionTile extends StatelessWidget {
Text(definition.types.join(", ")),
if (definition.tags.isNotEmpty) JpText(definition.tags.join(", ")),
if (definition.seeAlso.isNotEmpty)
seeAlsoText(context, definition.seeAlso),
_SeeAlsoText(words: definition.seeAlso),
],
),
);
}
}

class _SeeAlsoText extends StatelessWidget {
const _SeeAlsoText({required this.words});

final List<String> words;

@override
Widget build(BuildContext context) {
final textColor = Theme.of(context).textTheme.bodyLarge!.color;

Widget seeAlsoText(BuildContext context, List<String> words) {
return SelectableText.rich(
TextSpan(
children: [
Expand Down
2 changes: 0 additions & 2 deletions lib/screens/word_details/word_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class _WordContentWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final textColor = Theme.of(context).textTheme.bodyLarge!.color;
final shadowColor = Theme.of(context).colorScheme.shadow;

return SingleChildScrollView(
Expand Down Expand Up @@ -127,7 +126,6 @@ class _WordContentWidget extends StatelessWidget {
.map(
(definition) => DefinitionTile(
definition: definition,
textColor: textColor,
isLast: definition == word.definitions.last,
),
)
Expand Down

0 comments on commit a5a1737

Please sign in to comment.