Skip to content

Commit

Permalink
Merge pull request #10 from naaando/15-simplificar-repetição-fora-da-…
Browse files Browse the repository at this point in the history
…pagina

15 - simplificar repetição fora da pagina
  • Loading branch information
naaando authored Oct 19, 2023
2 parents df37ce9 + c444d96 commit 711dd47
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
50 changes: 42 additions & 8 deletions pets/lib/components/lista_ocorridos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ListaOcorridos extends HookConsumerWidget {
const SizedBox(height: 8),
ref.watch(eventosProvider).when(
data: (medicacoes) => lista(
ref,
context,
medicacoes.where((m) => m.completado).toList(),
),
Expand Down Expand Up @@ -70,14 +71,18 @@ class ListaOcorridos extends HookConsumerWidget {
);
}

Widget lista(BuildContext context, List<Medicacao> medicacoes) {
Widget lista(
WidgetRef ref,
BuildContext context,
List<Medicacao> medicacoes,
) {
if (medicacoes.isEmpty) {
return PlaceholderOcorridos(showMenu);
}

final medicacoesComoEvento = medicacoes
.map<MapEntry<int, Widget>>(
(medicacao) => medicacaoComoEvento(context, medicacao))
(medicacao) => medicacaoComoEvento(ref, context, medicacao))
.toList();

final eventosPorData = medicacoesComoEvento
Expand All @@ -90,6 +95,7 @@ class ListaOcorridos extends HookConsumerWidget {
}

MapEntry<int, Widget> medicacaoComoEvento(
WidgetRef ref,
BuildContext context,
Medicacao medicacao,
) {
Expand All @@ -98,6 +104,8 @@ class ListaOcorridos extends HookConsumerWidget {
String subtitle = medicacao.nome;
Jiffy date = Jiffy.parse(medicacao.quando!, isUtc: true).toLocal();

final scheme = Theme.of(context).colorScheme;

final defaultTileColor = Theme.of(context).colorScheme.primaryContainer;

var widget = Padding(
Expand All @@ -108,12 +116,26 @@ class ListaOcorridos extends HookConsumerWidget {
leading: PetAvatar.fromPet(pet),
title: Text(title),
subtitle: Text(subtitle),
trailing:
Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(date.fromNow()),
const SizedBox(height: 4),
ChipEvento.parse(context, medicacao.tipo)
]),
trailing: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(date.fromNow()),
const SizedBox(height: 4),
ChipEvento.parse(context, medicacao.tipo)
],
),
const SizedBox(width: 8),
IconButton(
onPressed: () => copiar(ref, context, medicacao),
icon: const Icon(Icons.copy_all),
color: scheme.primary,
),
],
),
onTap: () => Navigator.pushNamed(
context,
'/medicacao',
Expand All @@ -125,4 +147,16 @@ class ListaOcorridos extends HookConsumerWidget {

return MapEntry(date.millisecondsSinceEpoch, widget);
}

copiar(
WidgetRef ref,
BuildContext context,
Medicacao medicacao,
) {
Navigator.pushNamed(
context,
'/medicacao',
arguments: medicacao.copyWith(id: null, completado: false),
);
}
}
5 changes: 2 additions & 3 deletions pets/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:sentry_logging/sentry_logging.dart';

import 'notifications.dart';

Expand Down Expand Up @@ -39,9 +40,7 @@ void main() async {
await FastCachedImageConfig.init();

await SentryFlutter.init(
(options) {
options.tracesSampleRate = 1.0;
},
(options) => options..addIntegration(LoggingIntegration()),
appRunner: () => runApp(
const ProviderScope(
child: App(),
Expand Down
8 changes: 8 additions & 0 deletions pets/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.10.1"
sentry_logging:
dependency: "direct main"
description:
name: sentry_logging
sha256: f02ece07bf5d90c66ffbaa9fa6a0aa56eef50faffca02f55cde4c30108bba23e
url: "https://pub.dev"
source: hosted
version: "7.10.1"
shelf:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pets/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies:
fuzzywuzzy: ^1.1.6
freezed_annotation: ^2.4.1
sentry_flutter: ^7.10.1
sentry_logging: ^7.10.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 711dd47

Please sign in to comment.