Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'dev-history' into 'master'
Browse files Browse the repository at this point in the history
Dev history

See merge request asl-proyectos/cazdata-frontend!3
  • Loading branch information
ADRIAN LOPEZ GUERRERO committed Apr 13, 2020
2 parents 72aaf1e + 46dbac0 commit 0242b94
Show file tree
Hide file tree
Showing 14 changed files with 602 additions and 20 deletions.
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart"
}
]
}
51 changes: 51 additions & 0 deletions lib/model/journey.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class JourniesList{
final List<Journey> journies;

JourniesList({this.journies});

factory JourniesList.fromJson(List<dynamic> parsedJson) {

List<Journey> journies = new List<Journey>();
journies = parsedJson.map((i)=>Journey.fromJson(i)).toList();

return new JourniesList(
journies: journies
);
}
}

class Journey {
final String id;
final String title;
final String startTime;
final String endTime;
final int distance;
final int minutes;
final int calories;

Journey(
{this.id, this.title, this.startTime, this.endTime,this.distance, this.minutes, this.calories});

Map toJson() {
return {
'id': this.id,
'title': this.title,
'starts_at': this.startTime,
'ends_at': this.endTime,
'distance': this.distance,
'calories': calories
};
}


factory Journey.fromJson(Map<String, dynamic> json) {
return new Journey(
id: json['id'],
title: json['title'],
startTime: json['starts_at'],
endTime: json['ends_at'],
distance: json['distance'],
calories: json['calories'],
);
}
}
37 changes: 37 additions & 0 deletions lib/services/bloc/journey.bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:async';

import 'package:cazdata_frontend/model/journey.dart';
import 'package:cazdata_frontend/services/networking/index.dart';
import 'package:cazdata_frontend/services/repository/journey.repository.dart';
import 'package:rxdart/subjects.dart';

class JourneyBloc {
JourneyRepository _journeyRepository;
StreamController _journeyController;

StreamSink<Response<dynamic>> get journeySinkJourneys =>
_journeyController.sink;
Stream<Response<dynamic>> get journeyStreamJourneys =>
_journeyController.stream;

JourneyBloc() {
_journeyRepository = new JourneyRepository();
_journeyController = BehaviorSubject<Response<dynamic>>();
}

getJournies() async {
_journeyController.add(Response.loading('Get journeys.'));
try {
JourniesList journeyResponse = await _journeyRepository.getJournies();

_journeyController.add(Response.completed(journeyResponse));
} catch (e) {
_journeyController.add(Response.error(e.toString()));
print(e);
}
}

dispose() {
_journeyController?.close();
}
}
33 changes: 27 additions & 6 deletions lib/services/networking/api-provider.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import 'package:cazdata_frontend/services/networking/custom-exception.dart';
import 'package:cazdata_frontend/util/url.dart';

import 'package:cazdata_frontend/services/networking/custom-exception.dart';
import 'package:http/http.dart' as http;
import 'dart:io';
import 'dart:convert';
import 'dart:async';

class ApiProvider {
final String _baseUrl = Url.exchangeBaseUrl;
Future<dynamic> get(String url, {String header}) async {
var responseJson;

try {
final response = await http.get(
url,
headers: {HttpHeaders.authorizationHeader: '$header'},
);
responseJson = _response(response);
} on SocketException {
throw FetchDataException('No Internet connection');
}
return responseJson;
}

Future<dynamic> get(String url) async {
Future<dynamic> post(String url, String body, String header) async {
var responseJson;

try {
final response = await http.get(_baseUrl + url);
final response = await http.post(url,
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.authorizationHeader: '$header'
},
body: body);

responseJson = _response(response);
} on SocketException {
throw FetchDataException('No Internet connection');
Expand All @@ -25,8 +43,11 @@ class ApiProvider {
switch (response.statusCode) {
case 200:
var responseJson = json.decode(response.body);

return responseJson;

case 204:
return true;
case 400:
throw BadRequestException(response.body);
case 401:
Expand Down
18 changes: 18 additions & 0 deletions lib/services/repository/journey.repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:cazdata_frontend/model/journey.dart';
import 'package:cazdata_frontend/services/networking/index.dart';
import 'package:cazdata_frontend/util/url.dart';


class JourneyRepository {
ApiProvider _provider = ApiProvider();

Future<JourniesList> getJournies() async {
final response =
await _provider.get(Url.apiBaseUrl + "/journeys");


JourniesList journiesList = JourniesList.fromJson(response);

return journiesList;
}
}
145 changes: 145 additions & 0 deletions lib/ui/pages/details-journey.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import 'package:cazdata_frontend/model/journey.dart';
import 'package:cazdata_frontend/ui/widget/data-on-map.widget.dart';
import 'package:cazdata_frontend/util/colors.dart';
import 'package:flutter/material.dart';

class DetailsJourney extends StatelessWidget {

final Journey journey;

const DetailsJourney({
this.journey,
Key key,
}) : super(key: key);

@override
Widget build(BuildContext context) {

DateTime startTime = DateTime.parse(journey.startTime);
DateTime endTime = DateTime.parse(journey.endTime);
final int difference = endTime.difference(startTime).inMinutes;

return Scaffold(
appBar: AppBar(
title: Text('CazData'),
),
body: DefaultTextStyle(
style: TextStyle(
inherit: true,
fontSize: 14.0,
fontWeight: FontWeight.normal,
fontFamily: 'Montserrat',
decoration: TextDecoration.none,
decorationColor: Colors.black,
decorationStyle: TextDecorationStyle.solid,
color: Colors.black),
child: Center(
child: Container(
margin: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 3,
child: Text(
'Detalle Jornada',
style: TextStyle(
fontSize: 32, fontWeight: FontWeight.bold),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
'Informaci贸n',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
journey.title,
style: TextStyle(fontSize: 20),
),
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
journey.startTime.substring(0,10),
style: TextStyle(fontSize: 20),
),
),
],
),
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Card(
color: Color.fromARGB(255, 241, 243, 246),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
)
),
child: Center(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
DataOnMapWidget(
distance: journey.distance.toString(),
time: difference.toString(),
calories: journey.calories.toString()
)
],
),
Row(
children: <Widget>[
SizedBox(
width: MediaQuery.of(context).size.width - 78,
height: MediaQuery.of(context).size.height - 440,
)
],
),
],
)
)
),
),
)
],
),
Row(
children: <Widget>[
Expanded(
child: FlatButton(
onPressed: () {
/*...*/
},
color: greenLight,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0)),
child: Text("Compartir jornada",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17)),
),
)
],)
],
),
),
),
),
);
}
}
52 changes: 42 additions & 10 deletions lib/ui/pages/history.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cazdata_frontend/ui/widget/journey-list.widget.dart';
import 'package:flutter/material.dart';

class History extends StatelessWidget {
Expand All @@ -7,17 +8,48 @@ class History extends StatelessWidget {
appBar: AppBar(
title: Text('CazData'),
),
body: Center(
body: DefaultTextStyle(
style: TextStyle(
inherit: true,
fontSize: 14.0,
fontWeight: FontWeight.normal,
fontFamily: 'Montserrat',
decoration: TextDecoration.none,
decorationColor: Colors.black,
decorationStyle: TextDecorationStyle.solid,
color: Colors.black),
child: Center(
child: Container(
alignment: Alignment.center,
height: 300,
width: 300,
child: Text(
"Historial",
style: TextStyle(color: Colors.white, fontSize: 30),
margin: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Expanded(
flex: 3,
child: Text(
'Historial',
style: TextStyle(
fontSize: 32, fontWeight: FontWeight.bold),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Text(
'Listado Jornadas',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24),
),
),
JourneysList()
],
),
),
),
color: Colors.blue,
)),
),
);
}
}
}
Loading

0 comments on commit 0242b94

Please sign in to comment.