Skip to content

Commit

Permalink
Merge pull request #10 from CH1NRU5T/exploreMaps
Browse files Browse the repository at this point in the history
Explore maps
  • Loading branch information
CH1NRU5T authored Jul 29, 2023
2 parents d2a84b3 + aa0438c commit f9ff43d
Show file tree
Hide file tree
Showing 22 changed files with 891 additions and 191 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ jobs:
run: flutter pub get
- name: "Create .env file"
run: touch .env
- name: "Write to .env file"
- name: "Write baseUrl to .env file"
run: echo "BASEURL=${{secrets.BASEURL}}" | cat >> .env
- name: "Write key to .env file"
run: echo "KEY=${{secrets.KEY}}" | cat >> .env
- name: "Run build_runner build"
run: flutter pub run build_runner build --delete-conflicting-outputs
- name: "Build Web App"
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ jobs:
run: flutter pub get
- name: "Create .env file"
run: touch .env
- name: "Write to .env file"
- name: "Write baseUrl to .env file"
run: echo "BASEURL=${{secrets.BASEURL}}" | cat >> .env
- name: "Write key to .env file"
run: echo "KEY=${{secrets.KEY}}" | cat >> .env
- name: "Run build_runner build"
run: flutter pub run build_runner build --delete-conflicting-outputs
- name: "Build Web App"
Expand Down
50 changes: 30 additions & 20 deletions lib/customWidgets/custom_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ class CustomTextFormField extends StatelessWidget {
label: label,
controller: controller,
)
: TextFormField(
controller: controller,
keyboardType: keyboardType,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: label,
: AutofillGroup(
child: TextFormField(
autofillHints: [
keyboardType == TextInputType.emailAddress
? AutofillHints.username
: AutofillHints.name
],
controller: controller,
keyboardType: keyboardType,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: label,
),
),
);
}
Expand All @@ -47,20 +54,23 @@ class _PasswordFieldState extends State<PasswordField> {
bool obscure = true;
@override
Widget build(BuildContext context) {
return TextFormField(
controller: widget.controller,
obscureText: obscure,
keyboardType: widget.keyboardType,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: widget.label,
suffixIcon: IconButton(
onPressed: () {
setState(() {
obscure = !obscure;
});
},
icon: Icon(obscure ? Icons.visibility : Icons.visibility_off),
return AutofillGroup(
child: TextFormField(
autofillHints: const [AutofillHints.password],
controller: widget.controller,
obscureText: obscure,
keyboardType: widget.keyboardType,
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: widget.label,
suffixIcon: IconButton(
onPressed: () {
setState(() {
obscure = !obscure;
});
},
icon: Icon(obscure ? Icons.visibility : Icons.visibility_off),
),
),
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ part 'env.g.dart';
abstract class Env {
@EnviedField(varName: 'BASEURL', obfuscate: true)
static String baseUrl = _Env.baseUrl;
@EnviedField(varName: 'KEY', obfuscate: true)
static String key = _Env.key;
}
17 changes: 16 additions & 1 deletion lib/features/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:http/http.dart' as http;
import '../../models/user_model.dart';

class Api {
static Future<(String?, User?)> postRequest(
static Future<(String?, dynamic)> postRequest(
{required String url,
Map<String, dynamic>? body,
Map<String, String>? headers}) async {
Expand All @@ -22,4 +22,19 @@ class Api {
return (e.toString(), null);
}
}

static Future<(String?, dynamic)> getRequest(
{required String url, Map<String, String>? headers}) async {
http.Response response;
try {
response = await http.get(Uri.parse(url), headers: headers);
if (response.statusCode == 200) {
return (null, jsonDecode(response.body));
} else {
return (jsonDecode(response.body)['error'] as String, null);
}
} catch (e) {
return (e.toString(), null);
}
}
}
4 changes: 2 additions & 2 deletions lib/features/auth/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AuthService {
return await Api.postRequest(
url: '${Env.baseUrl}/api/v1/signin',
headers: {'Content-Type': 'application/json'},
body: {'email': email, 'password': password});
body: {'email': email, 'password': password}) as (String?, User?);
}

Future<(String?, User?)> signUp({
Expand All @@ -26,6 +26,6 @@ class AuthService {
'name': name,
'phone': phone,
'userName': userName
});
}) as (String?, User?);
}
}
144 changes: 140 additions & 4 deletions lib/features/explore_maps/screens/explore_maps_screen.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,148 @@
import 'dart:async';

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
import 'package:travel_planner_pro/features/explore_maps/widgets/destination_container.dart';

import '../../../models/destination_model.dart';
import '../../../providers/map_provider.dart';

class ExploreMapsScreen extends StatelessWidget {
class ExploreMapsScreen extends StatefulWidget {
const ExploreMapsScreen({super.key});

@override
Widget build(BuildContext context) {
return const Center(
child: Text('Explore Maps Screen'),
State<ExploreMapsScreen> createState() => _ExploreMapsScreenState();
}

class _ExploreMapsScreenState extends State<ExploreMapsScreen> {
final Completer<GoogleMapController> _controller =
Completer<GoogleMapController>();
(String?, List<Destination>?)? locationList;
@override
void initState() {
super.initState();
fetchLocationList();
}

void onTap(int index) async {
final GoogleMapController controller = await _controller.future;
await controller.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(double.parse(locationList!.$2![index].latitude),
double.parse(locationList!.$2![index].longitude)),
zoom: 14.4746),
),
);
}

void fetchLocationList() {
context.read<MapProvider>().fetchLocationList(context).then((value) {
locationList = value;
if (value.$1 == null) {
makeMarkers(value.$2);
}
setState(() {});
});
}

(List<Marker>?, List<CameraPosition>?) makeMarkers(
List<Destination>? destinations) {
List<Marker> markers = [];
List<CameraPosition> cameraPositions = [];
for (var element in destinations!) {
markers.add(Marker(
markerId: MarkerId(element.destinationName),
position: LatLng(
double.parse(element.latitude),
double.parse(element.longitude),
),
infoWindow: InfoWindow(
title: element.destinationName,
snippet: element.cityName,
),
));
cameraPositions.add(CameraPosition(
target: LatLng(
double.parse(element.latitude),
double.parse(element.longitude),
),
zoom: 14.4746,
));
}
return (markers, cameraPositions);
}

@override
Widget build(BuildContext context) {
return locationList == null
? const CircularProgressIndicator()
: locationList!.$1 == null
? Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
flex: 4,
child: GoogleMap(
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
markers:
Set<Marker>.of(makeMarkers(locationList!.$2!).$1!),
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: LatLng(
double.parse(locationList!.$2!.first.latitude),
double.parse(
locationList!.$2!.first.longitude,
),
),
zoom: 14.4746,
),
),
),
Expanded(
flex: 2,
child: CarouselSlider.builder(
itemCount: locationList!.$2!.length,
itemBuilder: (context, index, realIndex) {
return DestinationContainer(
index: index,
onTap: (int val) {
onTap(val);
},
src: locationList!.$2![index].images.first,
placeName:
locationList!.$2![index].destinationName,
averageTravelExpenses:
locationList!.$2![index].avgTravelExpenses);
},
options: CarouselOptions(
viewportFraction: 1 / 4,
scrollPhysics: const BouncingScrollPhysics(),
enableInfiniteScroll: false,
))
// FlutterCarousel.builder(
// itemCount: locationList!.$2!.length,
// itemBuilder: (context, index, realIndex) {
// return DestinationContainer(
// src: locationList!.$2![index].images.first,
// placeName: locationList!.$2![index].destinationName,
// averageTravelExpenses:
// locationList!.$2![index].avgTravelExpenses);
// },
// options: CarouselOptions(
// disableCenter: true,
// physics: const BouncingScrollPhysics(),
// viewportFraction: 0.3,
// scrollDirection: Axis.horizontal,
// ),
// ),
)
],
)
: Text(locationList!.$1!);
}
}
Loading

0 comments on commit f9ff43d

Please sign in to comment.