Skip to content

Commit 0492baf

Browse files
committed
Fixed map icons, adding locally, added ProfilePage for debugging sign in logic
1 parent 6d64353 commit 0492baf

File tree

8 files changed

+69
-38
lines changed

8 files changed

+69
-38
lines changed

lib/main.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ class _MyAppState extends State<MyApp> {
6565
child: MaterialApp(
6666
title: 'Lost@Pitt | For Students By Students',
6767
debugShowCheckedModeBanner: false,
68-
routes: {
69-
'loginPage': (context) => const LoginPage(),
70-
'mapPage': (context) => const HomePage(),
71-
'/': (context) => const Wrapper()
72-
},
73-
initialRoute: '/',
68+
home: const Wrapper(),
69+
// routes: {
70+
// 'loginPage': (context) => const LoginPage(),
71+
// 'mapPage': (context) => const HomePage(),
72+
// '/': (context) => const Wrapper()
73+
// },
74+
// initialRoute: '/',
7475
theme: AppTheme.getTheme(),
7576
themeMode: themeManager.themeMode));
7677
}

lib/pages/home_page.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import 'package:lost_found_steelhacks/models/item.dart';
77
import 'package:lost_found_steelhacks/pages/list_page.dart';
88
import 'package:lost_found_steelhacks/pages/login_page.dart';
99
import 'package:lost_found_steelhacks/pages/map_page.dart';
10+
import 'package:lost_found_steelhacks/pages/profile_page.dart';
1011
import 'package:lost_found_steelhacks/routing/wrapper.dart';
1112
import 'package:lost_found_steelhacks/services/auth.dart';
1213
import 'package:lost_found_steelhacks/services/data.dart';
1314
import 'package:lost_found_steelhacks/themes/app_theme.dart';
15+
import 'package:lost_found_steelhacks/widgets/loading_animation.dart';
1416
import 'package:multiple_stream_builder/multiple_stream_builder.dart';
1517

1618
/**
@@ -28,11 +30,11 @@ class HomePageState extends State<HomePage> {
2830
int selectedPage = 0;
2931
AsyncSnapshot<QuerySnapshot> lostSnapshot = const AsyncSnapshot.nothing();
3032
AsyncSnapshot<QuerySnapshot> foundSnapshot = const AsyncSnapshot.nothing();
31-
List<Widget> pages = const <Widget>[
33+
List<Widget> pages = <Widget>[
3234
MapPage(),
3335
ListPage(mode: true),
3436
Center(child: Text("Chat")),
35-
Center(child: Text("Profile")),
37+
ProfilePage(),
3638
LoginPage()
3739
];
3840

@@ -118,7 +120,7 @@ class HomePageState extends State<HomePage> {
118120
/* Check if the snapshot can be parsed */
119121
if (!isValidSnapshot(lostSnapshot) ||
120122
!isValidSnapshot(foundSnapshot)) {
121-
return const Wrapper();
123+
return const Loading();
122124
}
123125

124126
/* Update the item collections */

lib/pages/item_request.dart

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:typed_data';
22
import 'package:flutter/material.dart';
33
import 'package:google_maps_flutter/google_maps_flutter.dart';
44
import 'package:lost_found_steelhacks/models/item.dart';
5-
import 'package:lost_found_steelhacks/models/item.dart';
65
import 'package:lost_found_steelhacks/pages/map_page.dart';
76
import 'package:cloud_firestore/cloud_firestore.dart';
87
import 'package:firebase_storage/firebase_storage.dart';
@@ -113,16 +112,12 @@ class _ItemRequestState extends State<ItemRequest> {
113112

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

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

128123
@override

lib/pages/list_page.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: slash_for_doc_comments
2+
13
import 'package:flutter/material.dart';
24
import 'package:lost_found_steelhacks/services/data.dart';
35
import 'package:lost_found_steelhacks/widgets/post_card.dart';

lib/pages/map_page.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import 'package:lost_found_steelhacks/utils.dart';
1515
* Displays the posted items on a Google map
1616
*/
1717
class MapPage extends StatefulWidget {
18-
static BitmapDescriptor get lostMarkerIcon => BitmapDescriptor.defaultMarker;
19-
static BitmapDescriptor get foundMarkerIcon => BitmapDescriptor.defaultMarker;
2018
const MapPage({super.key});
2119

2220
@override
2321
State<MapPage> createState() => MapPageState();
2422
}
2523

2624
class MapPageState extends State<MapPage> {
25+
BitmapDescriptor lostMarkerIcon = BitmapDescriptor.defaultMarker;
26+
BitmapDescriptor foundMarkerIcon = BitmapDescriptor.defaultMarker;
2727
late List<Item> currentLostItems;
2828
late List<Item> currentFoundItems;
2929
late GoogleMapController mapController;
@@ -36,21 +36,21 @@ class MapPageState extends State<MapPage> {
3636
currentLostItems = DataService.instance.lostItems;
3737
currentFoundItems = DataService.instance.foundItems;
3838

39-
// BitmapDescriptor.fromAssetImage(
40-
// const ImageConfiguration(size: Size(40, 40)),
41-
// 'assets/location-pin.png')
42-
// .then((icon) {
43-
// setState(() {
44-
// foundMarkerIcon = icon;
45-
// });
46-
// });
47-
// BitmapDescriptor.fromAssetImage(
48-
// const ImageConfiguration(size: Size(40, 40)), 'assets/lost-pin.png')
49-
// .then((icon) {
50-
// setState(() {
51-
// lostMarkerIcon = icon;
52-
// });
53-
// });
39+
BitmapDescriptor.fromAssetImage(
40+
const ImageConfiguration(size: Size(40, 40)),
41+
'assets/location-pin.png')
42+
.then((icon) {
43+
setState(() {
44+
foundMarkerIcon = icon;
45+
});
46+
});
47+
BitmapDescriptor.fromAssetImage(
48+
const ImageConfiguration(size: Size(40, 40)), 'assets/lost-pin.png')
49+
.then((icon) {
50+
setState(() {
51+
lostMarkerIcon = icon;
52+
});
53+
});
5454
}
5555

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

6464
// creating a new MARKER
6565
final Marker marker = Marker(
66-
markerId: markerId, icon: MapPage.lostMarkerIcon, position: coords);
66+
markerId: markerId, icon: lostMarkerIcon, position: coords);
6767
counter++;
6868
setState(() {
6969
markers[markerId] = marker;
@@ -78,7 +78,7 @@ class MapPageState extends State<MapPage> {
7878
final MarkerId markerId = MarkerId(item.id);
7979
final Marker marker = Marker(
8080
markerId: markerId,
81-
icon: lost ? MapPage.lostMarkerIcon : MapPage.foundMarkerIcon,
81+
icon: lost ? lostMarkerIcon : foundMarkerIcon,
8282
position: LatLng(geo.latitude, geo.longitude),
8383
onTap: () => routeSubpage(PostPage(item: item), context));
8484
markers[markerId] = marker;

lib/pages/profile_page.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// ignore_for_file: slash_for_doc_comments
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:lost_found_steelhacks/services/auth.dart';
5+
6+
/**
7+
* UI to display the user's profile.
8+
* Currently just is a text box for debugging purposes
9+
*/
10+
class ProfilePage extends StatefulWidget {
11+
const ProfilePage({super.key});
12+
13+
@override
14+
ProfilePageState createState() => ProfilePageState();
15+
}
16+
17+
class ProfilePageState extends State<ProfilePage> {
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return Center(child: Text(AuthService.instance.user?.firstName ?? "null"));
22+
}
23+
24+
}

lib/routing/wrapper.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class Wrapper extends StatelessWidget {
1919
builder: (_, AsyncSnapshot<User?> snapshot) {
2020
if (snapshot.connectionState == ConnectionState.active) {
2121
final User? user = snapshot.data;
22-
return user == null ? const LoginPage() : const HomePage();
22+
if (user != null) {
23+
AuthService.instance.updateAppUser(user.uid);
24+
return const HomePage();
25+
}
26+
return const LoginPage();
2327
} else {
2428
return const Scaffold(
2529
body: Center(child: CircularProgressIndicator()),

lib/services/auth.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ class AuthService extends ChangeNotifier {
1616
static final AuthService instance = AuthService._internal();
1717
factory AuthService() => instance;
1818
AuthService._internal();
19+
AppUser? user;
1920

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

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

25+
Future<void> updateAppUser(String uid) async => user = await FirebaseService.instance.getUser(uid);
26+
2527
Stream<User?> get authUser => FirebaseAuth.instance.authStateChanges();
2628

2729
Future registerWithEmailAndPassword(
@@ -47,7 +49,8 @@ class AuthService extends ChangeNotifier {
4749
Future signInWithEmailAndPassword(String email, String password) async {
4850
UserCredential result = await FirebaseAuth.instance
4951
.signInWithEmailAndPassword(email: email, password: password);
50-
return await FirebaseService.instance.getUser(result.user!.uid);
52+
user = await FirebaseService.instance.getUser(result.user!.uid);
53+
return user;
5154
}
5255

5356
Future signInWithGoogle() async {

0 commit comments

Comments
 (0)