Skip to content

Commit

Permalink
Fixed map icons, adding locally, added ProfilePage for debugging sign…
Browse files Browse the repository at this point in the history
… in logic
  • Loading branch information
tbeidlershenk committed Dec 28, 2023
1 parent 6d64353 commit 0492baf
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 38 deletions.
13 changes: 7 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ class _MyAppState extends State<MyApp> {
child: MaterialApp(
title: 'Lost@Pitt | For Students By Students',
debugShowCheckedModeBanner: false,
routes: {
'loginPage': (context) => const LoginPage(),
'mapPage': (context) => const HomePage(),
'/': (context) => const Wrapper()
},
initialRoute: '/',
home: const Wrapper(),
// routes: {
// 'loginPage': (context) => const LoginPage(),
// 'mapPage': (context) => const HomePage(),
// '/': (context) => const Wrapper()
// },
// initialRoute: '/',
theme: AppTheme.getTheme(),
themeMode: themeManager.themeMode));
}
Expand Down
8 changes: 5 additions & 3 deletions lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:lost_found_steelhacks/models/item.dart';
import 'package:lost_found_steelhacks/pages/list_page.dart';
import 'package:lost_found_steelhacks/pages/login_page.dart';
import 'package:lost_found_steelhacks/pages/map_page.dart';
import 'package:lost_found_steelhacks/pages/profile_page.dart';
import 'package:lost_found_steelhacks/routing/wrapper.dart';
import 'package:lost_found_steelhacks/services/auth.dart';
import 'package:lost_found_steelhacks/services/data.dart';
import 'package:lost_found_steelhacks/themes/app_theme.dart';
import 'package:lost_found_steelhacks/widgets/loading_animation.dart';
import 'package:multiple_stream_builder/multiple_stream_builder.dart';

/**
Expand All @@ -28,11 +30,11 @@ class HomePageState extends State<HomePage> {
int selectedPage = 0;
AsyncSnapshot<QuerySnapshot> lostSnapshot = const AsyncSnapshot.nothing();
AsyncSnapshot<QuerySnapshot> foundSnapshot = const AsyncSnapshot.nothing();
List<Widget> pages = const <Widget>[
List<Widget> pages = <Widget>[
MapPage(),
ListPage(mode: true),
Center(child: Text("Chat")),
Center(child: Text("Profile")),
ProfilePage(),
LoginPage()
];

Expand Down Expand Up @@ -118,7 +120,7 @@ class HomePageState extends State<HomePage> {
/* Check if the snapshot can be parsed */
if (!isValidSnapshot(lostSnapshot) ||
!isValidSnapshot(foundSnapshot)) {
return const Wrapper();
return const Loading();
}

/* Update the item collections */
Expand Down
9 changes: 2 additions & 7 deletions lib/pages/item_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:lost_found_steelhacks/models/item.dart';
import 'package:lost_found_steelhacks/models/item.dart';
import 'package:lost_found_steelhacks/pages/map_page.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
Expand Down Expand Up @@ -113,16 +112,12 @@ class _ItemRequestState extends State<ItemRequest> {

Future<void> addLost() async {
Item item = Item(id: "", userId: AuthService.instance.user!.uid, timeCreated: Timestamp.now(), description: description, itemName: category, location: GeoPoint(lat, long),phone: phone, picture: _imgName);
DocumentReference ref = await FirebaseFirestore.instance.collection('lost').add(item.toFirestore());
item.id = ref.id;
DataService.instance.lostItems.add(item);
await FirebaseFirestore.instance.collection('lost').add(item.toFirestore());
}

Future<void> addFound() async {
Item item = Item(id: "", userId: AuthService.instance.user!.uid, timeCreated: Timestamp.now(), description: description, itemName: category, location: GeoPoint(lat, long),phone: phone, picture: _imgName);
DocumentReference ref = await FirebaseFirestore.instance.collection('found').add(item.toFirestore());
item.id = ref.id;
DataService.instance.foundItems.add(item);
await FirebaseFirestore.instance.collection('found').add(item.toFirestore());
}

@override
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/list_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: slash_for_doc_comments

import 'package:flutter/material.dart';
import 'package:lost_found_steelhacks/services/data.dart';
import 'package:lost_found_steelhacks/widgets/post_card.dart';
Expand Down
38 changes: 19 additions & 19 deletions lib/pages/map_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import 'package:lost_found_steelhacks/utils.dart';
* Displays the posted items on a Google map
*/
class MapPage extends StatefulWidget {
static BitmapDescriptor get lostMarkerIcon => BitmapDescriptor.defaultMarker;
static BitmapDescriptor get foundMarkerIcon => BitmapDescriptor.defaultMarker;
const MapPage({super.key});

@override
State<MapPage> createState() => MapPageState();
}

class MapPageState extends State<MapPage> {
BitmapDescriptor lostMarkerIcon = BitmapDescriptor.defaultMarker;
BitmapDescriptor foundMarkerIcon = BitmapDescriptor.defaultMarker;
late List<Item> currentLostItems;
late List<Item> currentFoundItems;
late GoogleMapController mapController;
Expand All @@ -36,21 +36,21 @@ class MapPageState extends State<MapPage> {
currentLostItems = DataService.instance.lostItems;
currentFoundItems = DataService.instance.foundItems;

// BitmapDescriptor.fromAssetImage(
// const ImageConfiguration(size: Size(40, 40)),
// 'assets/location-pin.png')
// .then((icon) {
// setState(() {
// foundMarkerIcon = icon;
// });
// });
// BitmapDescriptor.fromAssetImage(
// const ImageConfiguration(size: Size(40, 40)), 'assets/lost-pin.png')
// .then((icon) {
// setState(() {
// lostMarkerIcon = icon;
// });
// });
BitmapDescriptor.fromAssetImage(
const ImageConfiguration(size: Size(40, 40)),
'assets/location-pin.png')
.then((icon) {
setState(() {
foundMarkerIcon = icon;
});
});
BitmapDescriptor.fromAssetImage(
const ImageConfiguration(size: Size(40, 40)), 'assets/lost-pin.png')
.then((icon) {
setState(() {
lostMarkerIcon = icon;
});
});
}

void _onMapCreated(GoogleMapController controller) {
Expand All @@ -63,7 +63,7 @@ class MapPageState extends State<MapPage> {

// creating a new MARKER
final Marker marker = Marker(
markerId: markerId, icon: MapPage.lostMarkerIcon, position: coords);
markerId: markerId, icon: lostMarkerIcon, position: coords);
counter++;
setState(() {
markers[markerId] = marker;
Expand All @@ -78,7 +78,7 @@ class MapPageState extends State<MapPage> {
final MarkerId markerId = MarkerId(item.id);
final Marker marker = Marker(
markerId: markerId,
icon: lost ? MapPage.lostMarkerIcon : MapPage.foundMarkerIcon,
icon: lost ? lostMarkerIcon : foundMarkerIcon,
position: LatLng(geo.latitude, geo.longitude),
onTap: () => routeSubpage(PostPage(item: item), context));
markers[markerId] = marker;
Expand Down
24 changes: 24 additions & 0 deletions lib/pages/profile_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ignore_for_file: slash_for_doc_comments

import 'package:flutter/material.dart';
import 'package:lost_found_steelhacks/services/auth.dart';

/**
* UI to display the user's profile.
* Currently just is a text box for debugging purposes
*/
class ProfilePage extends StatefulWidget {
const ProfilePage({super.key});

@override
ProfilePageState createState() => ProfilePageState();
}

class ProfilePageState extends State<ProfilePage> {

@override
Widget build(BuildContext context) {
return Center(child: Text(AuthService.instance.user?.firstName ?? "null"));
}

}
6 changes: 5 additions & 1 deletion lib/routing/wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class Wrapper extends StatelessWidget {
builder: (_, AsyncSnapshot<User?> snapshot) {
if (snapshot.connectionState == ConnectionState.active) {
final User? user = snapshot.data;
return user == null ? const LoginPage() : const HomePage();
if (user != null) {
AuthService.instance.updateAppUser(user.uid);
return const HomePage();
}
return const LoginPage();
} else {
return const Scaffold(
body: Center(child: CircularProgressIndicator()),
Expand Down
7 changes: 5 additions & 2 deletions lib/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ class AuthService extends ChangeNotifier {
static final AuthService instance = AuthService._internal();
factory AuthService() => instance;
AuthService._internal();
AppUser? user;

final GeoPoint defaultGeopoint = const GeoPoint(40.4440279, -79.9700647);
AppUser? user;

bool isSignedIn() => FirebaseAuth.instance.currentUser != null;

Future<void> updateAppUser(String uid) async => user = await FirebaseService.instance.getUser(uid);

Stream<User?> get authUser => FirebaseAuth.instance.authStateChanges();

Future registerWithEmailAndPassword(
Expand All @@ -47,7 +49,8 @@ class AuthService extends ChangeNotifier {
Future signInWithEmailAndPassword(String email, String password) async {
UserCredential result = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
return await FirebaseService.instance.getUser(result.user!.uid);
user = await FirebaseService.instance.getUser(result.user!.uid);
return user;
}

Future signInWithGoogle() async {
Expand Down

0 comments on commit 0492baf

Please sign in to comment.