Skip to content

Commit

Permalink
feat(#64): corrije inicio da view
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielCostaDeOliveira committed Jan 16, 2025
1 parent e3a8cb4 commit 3bd37f4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 60 deletions.
77 changes: 38 additions & 39 deletions lib/ui/journey/view/journey_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:aranduapp/core/log/log.dart';
import 'package:aranduapp/ui/journey/viewmodel/journey_viewmodel.dart';
import 'package:aranduapp/ui/shared/erro_screen.dart';
import 'package:aranduapp/ui/shared/loading_widget.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
Expand Down Expand Up @@ -71,45 +73,42 @@ class JourneyScreen extends StatelessWidget {
return Card(
child: Column(
children: [
ListenableBuilder(
listenable: viewModel.journeyCommand,
builder: (context, child) {
if (viewModel.journeyCommand.isOk) {
return ListView.builder(
itemCount: viewModel.journeys.length,
shrinkWrap: true,
itemBuilder: (context, index) {
var journey = viewModel.journeys[index];
return ListTile(
leading: Icon(
Icons.border_right,
color: Theme.of(context).colorScheme.primary,
size: 32,
),
title: Text(journey.title),
subtitle: Text(journey.description),
trailing: Icon(
Icons.chevron_right,
color: Theme.of(context).colorScheme.primary,
size: 32,
),
onTap: () {
Navigator.of(context).pop();
},
);
});
} else if (viewModel.journeyCommand.isError) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Erro ao carregar jornadas.',
style: TextStyle(color: Theme.of(context).primaryColor),
),
);
} else {
return const LoadingWidget();
}
},
RefreshIndicator(
onRefresh: viewModel.journeyCommand.execute,
child: ListenableBuilder(
listenable: viewModel.journeyCommand,
builder: (context, child) {
if (viewModel.journeyCommand.isOk) {
return ListView.builder(
itemCount: viewModel.journeyCommand.result!.asValue!.value.length,
shrinkWrap: true,
itemBuilder: (context, index) {
var journey = viewModel.journeyCommand.result!.asValue!.value[index];
return ListTile(
leading: Icon(
Icons.border_right,
color: Theme.of(context).colorScheme.primary,
size: 32,
),
title: Text(journey.title),
subtitle: Text(journey.description),
trailing: Icon(
Icons.chevron_right,
color: Theme.of(context).colorScheme.primary,
size: 32,
),
onTap: () {
Log.d("tap");
},
);
});
} else if (viewModel.journeyCommand.isError) {
return const ErrorScreen(message: "Deslize para baixo");
} else {
return const LoadingWidget();
}
},
),
),
],
),
Expand Down
56 changes: 35 additions & 21 deletions lib/ui/journey/viewmodel/journey_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,48 @@ class JourneyViewModel extends ChangeNotifier {

List<JourneyResponse> journeys = [];

late Command0<void> journeyCommand;
late Command0<List<JourneyRequest>> journeyCommand;

JourneyViewModel()
: formKey = GlobalKey<FormState>(),
titleController = TextEditingController(),
descriptionController = TextEditingController(),
pointIdController = TextEditingController() {
journeyCommand = Command0(journey);



journeyCommand.execute();
}

Future<Result<void>> journey() async {
if (!formKey.currentState!.validate()) {
return Result.error('Valores inválidos');
}

JourneyRequest request = JourneyRequest(
title: titleController.text,
description: descriptionController.text,
pointId: pointIdController.text);

List<JourneyResponse>? journeysResponse =
await GetIt.instance<JourneyService>().getJourneys(request);

if (journeysResponse != null) {
journeys = journeysResponse;
notifyListeners();
return Result.value(null);
}
return Result.error('nenhuma jornada encontrada');
}
Future<Result<List<JourneyRequest>>> journey() async {
// if (!formKey.currentState!.validate()) {
// return Result.error('Valores inválidos');
// }

// JourneyRequest request = JourneyRequest(
// title: titleController.text,
// description: descriptionController.text,
// pointId: pointIdController.text);

// List<JourneyResponse>? journeysResponse =
// await GetIt.instance<JourneyService>().getJourneys(request);

// if (journeysResponse != null) {
// journeys = journeysResponse;
// notifyListeners();
// return Result.value(null);
// }
// return Result.error('nenhuma jornada encontrada');

await Future.delayed(const Duration(seconds: 1));

final journeyRequest = JourneyRequest(
title: "Viagem ao Parque",
description: "Explorar o parque local com os amigos.",
pointId: "123",
);

return Result.value(List.generate(50, (_) => journeyRequest));
}
}

0 comments on commit 3bd37f4

Please sign in to comment.