Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CH1NRU5T committed Jul 30, 2023
1 parent 9c48991 commit bbbcfd2
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 74 deletions.
2 changes: 2 additions & 0 deletions lib/features/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class Api {
Map<String, String>? headers}) async {
http.Response response;
try {
print('coded: ${jsonEncode(body)}');
response = await http.post(Uri.parse(url),
headers: headers, body: jsonEncode(body));

if (response.statusCode == 200) {
return (null, jsonDecode(response.body));
} else {
Expand Down
94 changes: 93 additions & 1 deletion lib/features/itinerary/screens/itinerary_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:travel_planner_pro/constants/extensions/extensions.dart';
import 'package:travel_planner_pro/customWidgets/loader.dart';
import 'package:travel_planner_pro/features/itinerary/services/itinerary_service.dart';
import 'package:travel_planner_pro/models/itinerary_model.dart';

class ItineraryScreen extends StatefulWidget {
const ItineraryScreen({super.key, required this.itid});
Expand All @@ -9,11 +14,98 @@ class ItineraryScreen extends StatefulWidget {
}

class _ItineraryScreenState extends State<ItineraryScreen> {
ItineraryService itineraryService = ItineraryService();
Itinerary? itinerary;
@override
void initState() {
super.initState();
getItinerary();
}

void getItinerary() async {
(String?, Itinerary?) record =
await itineraryService.getItinerary(context, widget.itid);
if (record.$1 == null) {
setState(() {
itinerary = record.$2;
});
} else {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(record.$1!)));
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(widget.itid),
child: itinerary == null
? const Loader()
: Column(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(itinerary!.planName,
style: const TextStyle(
fontSize: 30, fontWeight: FontWeight.bold)),
const Divider(),
Text(itinerary!.destination,
style: const TextStyle(
fontSize: 30, fontWeight: FontWeight.bold)),
5.height,
Text(
'${DateFormat('dd MMM yyyy').format(itinerary!.travelStartDate)} - ${DateFormat('dd MMM yyyy').format(itinerary!.travelEndDate)}',
style: Theme.of(context).textTheme.titleLarge),
5.height,
Text('Travel mode: ${itinerary!.travelMode}',
style: Theme.of(context).textTheme.titleLarge),
5.height,
Text('Cost: ₹ ${itinerary!.estimatedCost}',
style: Theme.of(context).textTheme.titleLarge),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (int i = 0;
i < itinerary!.items.length;
i++)
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
const Divider(),
Text(
'${i + 1}. ${itinerary!.items[i].dayDetail}',
style: Theme.of(context)
.textTheme
.bodyLarge,
),
const Expanded(
child: Padding(
padding:
EdgeInsets.symmetric(horizontal: 5),
child: Divider(),
)),
Text(
DateFormat('d MMM yyyy')
.format(itinerary!.items[i].date),
style: Theme.of(context)
.textTheme
.bodyLarge,
),
],
),
],
),
]),
],
),
],
),
),
);
}
Expand Down
29 changes: 26 additions & 3 deletions lib/features/itinerary/services/itinerary_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
class ItineraryService{

}
import 'package:flutter/material.dart';

import '../../../env/env.dart';
import '../../../models/itinerary_model.dart';
import '../../api/api.dart';

class ItineraryService {
Future<(String?, Itinerary?)> getItinerary(
BuildContext context,
String id,
) async {
(String?, Map<String, dynamic>?) response = await Api.postRequest(
url: '${Env.baseUrl}/api/v1/see-itenery',
headers: {'Content-Type': 'application/json'},
body: {
'iteneryId': id,
},
) as (String?, Map<String, dynamic>?);
if (response.$1 == null) {
return (null, Itinerary.fromMap(response.$2!));
} else {
print('err${response.$1}');
return (response.$1, null);
}
}
}
2 changes: 1 addition & 1 deletion lib/features/itinerary_list/widgets/itinerary_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ItineraryDialog extends StatelessWidget {
final int cost;
final String travelMode;
//TODO: Change this to the actual link
final String shareBaseLink = 'http://localhost:62671/';
final String shareBaseLink = 'http://localhost:65250/';
@override
Widget build(BuildContext context) {
int length = dateAndDetail.length;
Expand Down
6 changes: 4 additions & 2 deletions lib/models/itinerary_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ class Itinerary {

factory Itinerary.fromMap(Map<String, dynamic> map) {
return Itinerary(
id: map['id'] as String,
id: map['id'] == null ? map['_id'] as String : map['id'] as String,
planName: map['planName'] as String,
destination: map['destination'] as String,
travelStartDate: DateTime.parse(map['travelStartDate'] as String),
travelEndDate: DateTime.parse(map['travelEndDate'] as String),
travelMode: map['travelMode'] as String,
items: (map['details'] as List<dynamic>)
.map((e) => DateAndDetail.fromMap(e as Map<String, dynamic>))
.map(
(e) => DateAndDetail.fromMap(e as Map<String, dynamic>),
)
.toList(),
estimatedCost: map['estimatedCost'] as int,
);
Expand Down
64 changes: 0 additions & 64 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.1"
flutter_svg:
dependency: "direct main"
description:
name: flutter_svg
sha256: "8c5d68a82add3ca76d792f058b186a0599414f279f00ece4830b9b231b570338"
url: "https://pub.dev"
source: hosted
version: "2.0.7"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -528,14 +520,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
path_parsing:
dependency: transitive
description:
name: path_parsing
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
url: "https://pub.dev"
source: hosted
version: "1.0.1"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -584,14 +568,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.7"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
url: "https://pub.dev"
source: hosted
version: "5.4.0"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -797,14 +773,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.1"
timeline_tile:
dependency: "direct main"
description:
name: timeline_tile
sha256: "85ec2023c67137397c2812e3e848b2fb20b410b67cd9aff304bb5480c376fc0c"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
timing:
dependency: transitive
description:
Expand Down Expand Up @@ -885,30 +853,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.7"
vector_graphics:
dependency: transitive
description:
name: vector_graphics
sha256: "670f6e07aca990b4a2bcdc08a784193c4ccdd1932620244c3a86bb72a0eac67f"
url: "https://pub.dev"
source: hosted
version: "1.1.7"
vector_graphics_codec:
dependency: transitive
description:
name: vector_graphics_codec
sha256: "7451721781d967db9933b63f5733b1c4533022c0ba373a01bdd79d1a5457f69f"
url: "https://pub.dev"
source: hosted
version: "1.1.7"
vector_graphics_compiler:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: "80a13c613c8bde758b1464a1755a7b3a8f2b6cec61fbf0f5a53c94c30f03ba2e"
url: "https://pub.dev"
source: hosted
version: "1.1.7"
vector_math:
dependency: transitive
description:
Expand Down Expand Up @@ -949,14 +893,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.1"
xml:
dependency: transitive
description:
name: xml
sha256: "5bc72e1e45e941d825fd7468b9b4cc3b9327942649aeb6fc5cdbf135f0a86e84"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
yaml:
dependency: transitive
description:
Expand Down
3 changes: 0 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ dependencies:
flutter:
sdk: flutter
flutter_rating_bar: ^4.0.1
flutter_svg: ^2.0.7
google_fonts: ^5.1.0
google_maps_flutter: ^2.4.0
http: ^1.1.0
intl: ^0.18.1
lottie: ^2.5.0
provider: null
shared_preferences: ^2.2.0
timeline_tile: ^2.0.0
url_launcher: ^6.1.12

dev_dependencies:
Expand All @@ -63,7 +61,6 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- assets/lottie/
- assets/images/svgs/
- assets/images/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down

0 comments on commit bbbcfd2

Please sign in to comment.