-
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.
Merge pull request #107 from fga-eps-mds/feat#65/Trilha
Feat#65/trilha
- Loading branch information
Showing
8 changed files
with
226 additions
and
4 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
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/ui/trails/service/trails_service.dart'; | ||
import 'package:aranduapp/ui/trails/viewmodel/trails_viewmodel.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
|
||
void setupTrailsDI() { | ||
|
||
GetIt.instance.registerLazySingleton(() => TrailsService()); | ||
GetIt.instance.registerFactory(() => TrailsViewmodel()); | ||
|
||
} |
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,8 @@ | ||
class TrailsModel { | ||
final String id; | ||
final String name; | ||
final String? contectId; | ||
|
||
TrailsModel({required this.id, required this.name, this.contectId}); | ||
} | ||
|
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,23 @@ | ||
import 'dart:convert'; | ||
|
||
class TrailsRequest { | ||
final String journeyId; | ||
|
||
TrailsRequest({ | ||
required this.journeyId, | ||
}); | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'journeyId': journeyId, | ||
}; | ||
} | ||
|
||
factory TrailsRequest.fromJsonString(String jsonString) { | ||
final json = jsonDecode(jsonString); | ||
|
||
return TrailsRequest( | ||
journeyId: json['journeyId']! 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,31 @@ | ||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:aranduapp/core/network/studio_maker_api.dart'; | ||
import 'package:aranduapp/ui/trails/model/trails_model.dart'; | ||
import 'package:aranduapp/ui/trails/model/trails_request.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class TrailsService { | ||
Future<List<TrailsModel>> getTrails(TrailsRequest trailsRequest) async { | ||
Response response = await StudioMakerApi.getInstance() | ||
.get(path: '/trails/journey/${trailsRequest.journeyId}'); | ||
|
||
List<dynamic> journeyList = response.data as List<dynamic>; | ||
|
||
Log.i(journeyList); | ||
|
||
var res = journeyList.map((e) { | ||
final Map<String, dynamic> trailsMap = e as Map<String, dynamic>; | ||
|
||
final list = trailsMap['contents'] as List<dynamic>; | ||
|
||
return TrailsModel( | ||
id: trailsMap['_id']! as String, | ||
name: trailsMap['name']! as String, | ||
contectId: list.isNotEmpty ? list[0] as String : null, | ||
); | ||
|
||
}).toList(); | ||
|
||
return res; | ||
} | ||
} |
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,120 @@ | ||
import 'package:aranduapp/core/log/log.dart'; | ||
import 'package:aranduapp/ui/content/view/content_view.dart'; | ||
import 'package:aranduapp/ui/journey/model/journey_model.dart'; | ||
import 'package:aranduapp/ui/shared/erro_screen.dart'; | ||
import 'package:aranduapp/ui/shared/loading_widget.dart'; | ||
import 'package:aranduapp/ui/trails/viewmodel/trails_viewmodel.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class Trails extends StatelessWidget { | ||
final JourneyModel journey; | ||
|
||
const Trails({super.key, required this.journey}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider<TrailsViewmodel>.value( | ||
value: GetIt.instance<TrailsViewmodel>(), | ||
child: _TrailsScreen(journey: journey), | ||
); | ||
} | ||
} | ||
|
||
class _TrailsScreen extends StatelessWidget { | ||
final JourneyModel journey; | ||
|
||
const _TrailsScreen({required this.journey}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: _buildAppBar(context), | ||
body: _buildTrails(context), | ||
); | ||
} | ||
|
||
AppBar _buildAppBar(BuildContext context) { | ||
return AppBar( | ||
backgroundColor: Theme.of(context).colorScheme.onPrimary, | ||
scrolledUnderElevation: 0, | ||
title: Text( | ||
journey.title, | ||
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 _buildTrails(BuildContext context) { | ||
TrailsViewmodel viewModel = Provider.of<TrailsViewmodel>(context); | ||
|
||
viewModel.getTrailsCommand.execute(journey.id); | ||
|
||
return RefreshIndicator( | ||
onRefresh: () => viewModel.getTrailsCommand.execute(journey.id), | ||
child: ListenableBuilder( | ||
listenable: viewModel.getTrailsCommand, | ||
builder: (context, child) { | ||
if (viewModel.getTrailsCommand.isOk) { | ||
return _buildListView(context); | ||
} else if (viewModel.getTrailsCommand.isError) { | ||
return ErrorScreen( | ||
message: | ||
"Deslize para baixo\n\n ${viewModel.getTrailsCommand.result!.asError!.error.toString()}"); | ||
} else { | ||
return const LoadingWidget(); | ||
} | ||
}, | ||
), | ||
); | ||
} | ||
|
||
ListView _buildListView(BuildContext context) { | ||
TrailsViewmodel viewModel = Provider.of<TrailsViewmodel>(context); | ||
|
||
return ListView.builder( | ||
itemCount: viewModel.getTrailsCommand.result!.asValue!.value.length, | ||
shrinkWrap: true, | ||
itemBuilder: (context, index) { | ||
var trails = viewModel.getTrailsCommand.result!.asValue!.value[index]; | ||
return ListTile( | ||
leading: Icon( | ||
Icons.collections_bookmark_rounded, | ||
color: Theme.of(context).colorScheme.primary, | ||
size: 32, | ||
), | ||
title: Text(trails.name), | ||
trailing: Icon( | ||
Icons.chevron_right, | ||
color: Theme.of(context).colorScheme.primary, | ||
size: 32, | ||
), | ||
onTap: () { | ||
if (trails.contectId != null) { | ||
Navigator.of(context).push( | ||
MaterialPageRoute( | ||
builder: (context) => ContentView( | ||
contentID: trails.contectId!, | ||
), | ||
), | ||
); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
} |
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,22 @@ | ||
import 'package:aranduapp/core/state/command.dart'; | ||
import 'package:aranduapp/ui/trails/model/trails_model.dart'; | ||
import 'package:aranduapp/ui/trails/model/trails_request.dart'; | ||
import 'package:aranduapp/ui/trails/service/trails_service.dart'; | ||
import 'package:async/async.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
|
||
class TrailsViewmodel extends ChangeNotifier { | ||
late Command1<List<TrailsModel>, String> getTrailsCommand; | ||
|
||
TrailsViewmodel() { | ||
getTrailsCommand = Command1(getTrails); | ||
} | ||
|
||
Future<Result<List<TrailsModel>>> getTrails(String journeyId) async { | ||
List<TrailsModel> res = await GetIt.instance<TrailsService>() | ||
.getTrails(TrailsRequest(journeyId: journeyId)); | ||
|
||
return Result.value(res); | ||
} | ||
} |