-
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.
- Loading branch information
1 parent
aad5a29
commit 2f7e2fe
Showing
6 changed files
with
202 additions
and
2 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
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,31 @@ | ||
import 'dart:convert'; | ||
|
||
class JourneyRequest { | ||
final String title; | ||
final String description; | ||
final String pointId; | ||
|
||
JourneyRequest({ | ||
required this.title, | ||
required this.description, | ||
required this.pointId, | ||
}); | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'title': title, | ||
'description': description, | ||
'pointId': pointId, | ||
}; | ||
} | ||
|
||
factory JourneyRequest.fromJsonString(String jsonString) { | ||
final json = jsonDecode(jsonString); | ||
|
||
return JourneyRequest( | ||
title: json['title']! as String, | ||
description: json['description']! as String, | ||
pointId: json['pointId']! 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,11 @@ | ||
import 'package:aranduapp/core/network/base_api.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_request.dart'; | ||
import 'package:aranduapp/ui/journey/view/journey_view.dart'; | ||
import 'package:aranduapp/ui/journey/viewmodel/journey_viewmodel.dart'; | ||
|
||
class JourneyService { | ||
static Future<JourneyViewModel> (JourneyRequest journeyRequest) async { | ||
await BaseApi.getInstance(auth: true) | ||
.get(path: '/journeys', data: journeyRequest.toJson()); | ||
} | ||
} |
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,94 @@ | ||
import 'package:aranduapp/ui/home/view/HomeView.dart'; | ||
import 'package:aranduapp/ui/journey/viewmodel/journey_viewmodel.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( | ||
create: (context) => JourneyViewModel(), | ||
child: const JourneyScreen(), | ||
); | ||
} | ||
} | ||
|
||
class JourneyScreen extends StatelessWidget { | ||
const JourneyScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: _buildAppBar(context), | ||
body: _buildPage(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.push( | ||
context, | ||
MaterialPageRoute(builder: (context) => const HomeView()), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
|
||
Widget _buildPage(BuildContext context) { | ||
return SingleChildScrollView( | ||
child: Center( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
_buildJourney(context), | ||
const SizedBox(height: 80), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget _buildJourney(BuildContext context) { | ||
JourneyViewModel viewModel = Provider.of<JourneyViewModel>(context); | ||
|
||
return Card( | ||
child: Column( | ||
children: [ | ||
ListenableBuilder( | ||
listenable: viewModel.journeyCommand, | ||
builder: (context, child) { | ||
if (viewModel.journeyCommand.isOk) { | ||
return ListView.builder(itemCount: viewModel.journeys.length, itemBuilder: ); | ||
} | ||
else if (viewModel.journeyCommand.isError) { | ||
} | ||
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,50 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_request.dart'; | ||
import 'package:aranduapp/ui/journey/service/journey_service.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class JourneyViewModel extends ChangeNotifier { | ||
final GlobalKey<FormState> formKey; | ||
final TextEditingController titleController; | ||
final TextEditingController descriptionController; | ||
final TextEditingController pointIdController; | ||
|
||
List<JourneyRequest> journeys = []; | ||
|
||
late Command0<void> journeyCommand; | ||
|
||
JourneyViewModel() | ||
: formKey = GlobalKey<FormState>(), | ||
titleController = TextEditingController(), | ||
descriptionController = TextEditingController(), | ||
pointIdController = TextEditingController() { | ||
journeyCommand = Command0(journey); | ||
} | ||
|
||
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); | ||
|
||
await JourneyService.Future(request); | ||
|
||
return Result.value(null); | ||
} | ||
|
||
|
||
|
||
/* Future<void> loadJourneys() async { | ||
try { | ||
journeys = await JourneyService.fetchJourneys(); | ||
notifyListeners(); | ||
} catch (e) { | ||
// Trate o erro conforme necessário | ||
} | ||
} */ | ||
} |
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,14 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class LoadingWidget extends StatelessWidget{ | ||
const LoadingWidget ({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const Center( | ||
child: CircularProgressIndicator(value: null), | ||
); | ||
} | ||
|
||
} |