-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#66): Adição de códigos relevantes
Co-authored-by: zDrNz <[email protected]>
- Loading branch information
1 parent
75e4c81
commit 2b2d051
Showing
5 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |