Skip to content

Commit

Permalink
feat(#66): Adição de códigos relevantes
Browse files Browse the repository at this point in the history
Co-authored-by: zDrNz <[email protected]>
  • Loading branch information
MarinaGaldi and zDrNz committed Jan 20, 2025
1 parent 75e4c81 commit 2b2d051
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/ui/subjects/model/subjects_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:convert';

class SubjectsRequest {
final String title;
final String description;

SubjectsRequest({
required this.title,
required this.description,
});

Map<String, dynamic> toJson() {
return <String, dynamic>{
'title': title,
'description': description,
};
}

factory SubjectsRequest.fromJsonString(String jsonString) {
final json = jsonDecode(jsonString);

return SubjectsRequest(
title: json['title']! as String,
description: json['description']! as String,
);
}
}
16 changes: 16 additions & 0 deletions lib/ui/subjects/model/subjects_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'dart:convert';

class SubjectsResponse {
final String title;
final String description;

SubjectsResponse(this.title, this.description);

factory SubjectsResponse.fromJsonString(String jsonString) {
Map<String, dynamic> json = jsonDecode(jsonString);
return SubjectsResponse(
json['title'] as String,
json['description'] as String
);
}
}
7 changes: 7 additions & 0 deletions lib/ui/subjects/service/subjects_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

class DisciplinaService {
static Future<List<String>> carregar() async {
// Simulando uma chamada de API
return ["Lógica", "Disciplina 02", "Disciplina 03"];
}
}
98 changes: 98 additions & 0 deletions lib/ui/subjects/view/subjects_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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:provider/provider.dart';

class Journey extends StatelessWidget {
const Journey({super.key});

@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<JourneyViewModel>.value(
value: GetIt.instance<JourneyViewModel>(),
child: const JourneyScreen(),
);
}
}

class JourneyScreen extends StatelessWidget {
const JourneyScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _buildAppBar(context),
body: _buildJourney(context),
);
}

AppBar _buildAppBar(BuildContext context) {
return AppBar(
backgroundColor: Theme.of(context).colorScheme.onPrimary,
scrolledUnderElevation: 0,
title: Text(
'Jornadas de Lógica',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
),
centerTitle: true,
leading: IconButton(
icon: Icon(
Icons.chevron_left,
color: Theme.of(context).colorScheme.primary,
size: 32,
),
onPressed: () {
Navigator.of(context).pop();
},
),
);
}

Widget _buildJourney(BuildContext context) {
JourneyViewModel viewModel = Provider.of<JourneyViewModel>(context);

return 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();
}
},
),
);
}
}
38 changes: 38 additions & 0 deletions lib/ui/subjects/viewmodel/subjects_viewmodel.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:aranduapp/core/state/command.dart';
import 'package:aranduapp/ui/subjects/model/subjects_request.dart';
//import 'package:aranduapp/ui/subjects/model/subjects_response.dart';
import 'package:async/async.dart';
import 'package:flutter/material.dart';

class SubjectsViewmodel extends ChangeNotifier {
final GlobalKey<FormState> formKey;
final TextEditingController titleController;
final TextEditingController descriptionController;
final TextEditingController pointIdController;

List<SubjectsRequest> journeys = [];

late Command0<List<SubjectsRequest>> journeyCommand;

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

journeyCommand.execute();
}

Future<Result<List<SubjectsRequest>>> journey() async {

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

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

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

0 comments on commit 2b2d051

Please sign in to comment.