Skip to content

Commit

Permalink
refactor(word_page): ♻️ extract widget (#43)
Browse files Browse the repository at this point in the history
* refactor(word_page): ♻️ extract widget

- Rename elimina → treu
- Rename `interactive` → `isInteractive`
- Enable interaction for Chips

* feat(word_page): ✨ use standard `showModalBottomSheet`

* feat(scope_chip): ♿️ show tooltip
  • Loading branch information
albertms10 authored Feb 2, 2024
1 parent 5f03c67 commit 9fe52b1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 47 deletions.
36 changes: 36 additions & 0 deletions lib/src/pages/word_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:el_meu_diec/src/widgets/autocomplete_entry_card.dart';
import 'package:flutter/material.dart';

import '../model/word.dart';

class WordPage extends StatelessWidget {
final Word word;

const WordPage({super.key, required this.word});

@override
Widget build(BuildContext context) {
final theme = Theme.of(context);

return Scaffold(
backgroundColor: Colors.transparent,
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsetsDirectional.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
word.word,
style: theme.textTheme.displaySmall,
textAlign: TextAlign.start,
),
const SizedBox(height: 24),
DefinitionEntrySenses(word: word),
],
),
),
),
);
}
}
42 changes: 15 additions & 27 deletions lib/src/widgets/autocomplete_entry_card.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'dart:io';

import 'package:el_meu_diec/model.dart';
import 'package:el_meu_diec/src/constants.dart';
import 'package:el_meu_diec/src/pages/word_page.dart';
import 'package:el_meu_diec/src/theme.dart';
import 'package:el_meu_diec/src/widgets/definition_entry_sense_line.dart';
import 'package:el_meu_diec/src/widgets/equipped_card.dart';
import 'package:flutter/material.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:provider/provider.dart';

class AutocompleteEntryCard extends StatelessWidget {
Expand All @@ -31,25 +29,10 @@ class AutocompleteEntryCard extends StatelessWidget {
return EquippedCard(
height: autocompleteEntryCardHeight,
isLoading: isLoading,
onTap: () => (Platform.isAndroid
? showBarModalBottomSheet
: showCupertinoModalBottomSheet)<void>(
onTap: () => showModalBottomSheet<void>(
context: context,
builder: (context) {
return Align(
alignment: Alignment.topCenter,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsetsDirectional.all(20),
child: Column(
children: [
Text(word.word),
_DefinitionEntrySenses(word: word),
],
),
),
),
);
return WordPage(word: word);
},
),
child: Column(
Expand Down Expand Up @@ -77,7 +60,8 @@ class AutocompleteEntryCard extends StatelessWidget {
_BookmarkButton(word: word),
],
),
if (word.senses != null) _DefinitionEntrySenses(word: word),
if (word.senses != null)
DefinitionEntrySenses(word: word, isInteractive: false),
],
),
);
Expand All @@ -98,7 +82,7 @@ class _BookmarkButton extends StatelessWidget {
TextSpan(
children: [
TextSpan(
text: bookmarked ? 'S’ha afegit ' : 'S’ha eliminat ',
text: bookmarked ? 'S’ha afegit ' : 'S’ha tret ',
),
TextSpan(
text: word.word,
Expand Down Expand Up @@ -127,17 +111,21 @@ class _BookmarkButton extends StatelessWidget {
isBookmarked ? Icons.bookmark : Icons.bookmark_outline,
),
enableFeedback: true,
tooltip:
isBookmarked ? 'Elimina de la coŀlecció' : 'Afegeix a la coŀlecció',
tooltip: isBookmarked ? 'Treu de la coŀlecció' : 'Afegeix a la coŀlecció',
onPressed: () => _onPressed(context),
);
}
}

class _DefinitionEntrySenses extends StatelessWidget {
class DefinitionEntrySenses extends StatelessWidget {
final Word word;
final bool isInteractive;

const _DefinitionEntrySenses({super.key, required this.word});
const DefinitionEntrySenses({
super.key,
required this.word,
this.isInteractive = true,
});

@override
Widget build(BuildContext context) {
Expand All @@ -148,7 +136,7 @@ class _DefinitionEntrySenses extends StatelessWidget {
for (var i = 0; i < word.senses!.length; i++)
DefinitionEntrySenseLine(
sense: word.senses![i],
interactive: false,
isInteractive: isInteractive,
isFirstNumber:
i == 0 || word.senses![i - 1].number != word.senses![i].number,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/widgets/autocomplete_entry_future_card.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:el_meu_diec/model.dart';
import 'package:el_meu_diec/src/widgets/autocomplete_entry_card.dart';
import 'package:el_meu_diec/src/widgets/autocomplete_entry_card.dart'
hide DefinitionEntrySenses;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand Down
6 changes: 3 additions & 3 deletions lib/src/widgets/definition_entry_sense_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import 'package:flutter/material.dart';
class DefinitionEntrySenseLine extends StatelessWidget {
final DefinitionEntrySense sense;
final bool isFirstNumber;
final bool interactive;
final bool isInteractive;

const DefinitionEntrySenseLine({
super.key,
required this.sense,
this.isFirstNumber = true,
this.interactive = true,
this.isInteractive = true,
});

@override
Expand Down Expand Up @@ -74,7 +74,7 @@ class DefinitionEntrySenseLine extends StatelessWidget {
padding: const EdgeInsetsDirectional.only(end: 4),
child: ScopeChip(
scope: scope,
interactive: interactive,
isInteractive: isInteractive,
),
),
),
Expand Down
35 changes: 19 additions & 16 deletions lib/src/widgets/scope_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'package:flutter/material.dart';

class ScopeChip extends StatelessWidget {
final Scope scope;
final bool interactive;
final bool isInteractive;

const ScopeChip({super.key, required this.scope, this.interactive = true});
const ScopeChip({super.key, required this.scope, this.isInteractive = true});

void _onTap(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
Expand All @@ -26,20 +26,23 @@ class ScopeChip extends StatelessWidget {
borderRadius: BorderRadius.all(Radius.circular(4)),
side: BorderSide(color: Color(0xFFE0E0E0)),
),
child: InkWell(
onTap: interactive ? () => _onTap(context) : null,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 6,
end: 6,
top: 3,
bottom: 4,
),
child: Text(
scope.name,
style: const TextStyle(
color: Colors.black,
fontSize: 12,
child: Tooltip(
message: 'Mostra l’abreviatura',
child: InkWell(
onTap: isInteractive ? () => _onTap(context) : null,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 6,
end: 6,
top: 3,
bottom: 4,
),
child: Text(
scope.name,
style: const TextStyle(
color: Colors.black,
fontSize: 12,
),
),
),
),
Expand Down

0 comments on commit 9fe52b1

Please sign in to comment.