Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
M
Mapping-Software-Efficient-Routing-Algorithm
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
h703249754
Mapping-Software-Efficient-Routing-Algorithm
Commits
c2c69eec
Commit
c2c69eec
authored
Oct 05, 2025
by
aleenaasghar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Implement user-specific addresses
parent
101cfa5c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
delivery_address.dart
lib/models/delivery_address.dart
+6
-0
admin_dashboard_screen.dart
lib/screens/admin_dashboard_screen.dart
+12
-2
firestore_service.dart
lib/services/firestore_service.dart
+8
-4
add_edit_address_dialog.dart
lib/widgets/add_edit_address_dialog.dart
+8
-1
No files found.
lib/models/delivery_address.dart
View file @
c2c69eec
...
@@ -2,6 +2,7 @@ import 'package:uuid/uuid.dart';
...
@@ -2,6 +2,7 @@ import 'package:uuid/uuid.dart';
class
DeliveryAddress
{
class
DeliveryAddress
{
final
String
id
;
final
String
id
;
final
String
userId
;
final
String
streetAddress
;
final
String
streetAddress
;
final
String
city
;
final
String
city
;
final
String
state
;
final
String
state
;
...
@@ -13,6 +14,7 @@ class DeliveryAddress {
...
@@ -13,6 +14,7 @@ class DeliveryAddress {
DeliveryAddress
({
DeliveryAddress
({
String
?
id
,
String
?
id
,
required
this
.
userId
,
required
this
.
streetAddress
,
required
this
.
streetAddress
,
required
this
.
city
,
required
this
.
city
,
required
this
.
state
,
required
this
.
state
,
...
@@ -30,6 +32,7 @@ class DeliveryAddress {
...
@@ -30,6 +32,7 @@ class DeliveryAddress {
Map
<
String
,
dynamic
>
toJson
()
=>
{
Map
<
String
,
dynamic
>
toJson
()
=>
{
'id'
:
id
,
'id'
:
id
,
'userId'
:
userId
,
'streetAddress'
:
streetAddress
,
'streetAddress'
:
streetAddress
,
'city'
:
city
,
'city'
:
city
,
'state'
:
state
,
'state'
:
state
,
...
@@ -42,6 +45,7 @@ class DeliveryAddress {
...
@@ -42,6 +45,7 @@ class DeliveryAddress {
factory
DeliveryAddress
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
DeliveryAddress
(
factory
DeliveryAddress
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
DeliveryAddress
(
id:
json
[
'id'
],
id:
json
[
'id'
],
userId:
json
[
'userId'
],
streetAddress:
json
[
'streetAddress'
],
streetAddress:
json
[
'streetAddress'
],
city:
json
[
'city'
],
city:
json
[
'city'
],
state:
json
[
'state'
],
state:
json
[
'state'
],
...
@@ -53,6 +57,7 @@ class DeliveryAddress {
...
@@ -53,6 +57,7 @@ class DeliveryAddress {
);
);
DeliveryAddress
copyWith
({
DeliveryAddress
copyWith
({
String
?
userId
,
String
?
streetAddress
,
String
?
streetAddress
,
String
?
city
,
String
?
city
,
String
?
state
,
String
?
state
,
...
@@ -62,6 +67,7 @@ class DeliveryAddress {
...
@@ -62,6 +67,7 @@ class DeliveryAddress {
String
?
notes
,
String
?
notes
,
})
=>
DeliveryAddress
(
})
=>
DeliveryAddress
(
id:
id
,
id:
id
,
userId:
userId
??
this
.
userId
,
streetAddress:
streetAddress
??
this
.
streetAddress
,
streetAddress:
streetAddress
??
this
.
streetAddress
,
city:
city
??
this
.
city
,
city:
city
??
this
.
city
,
state:
state
??
this
.
state
,
state:
state
??
this
.
state
,
...
...
lib/screens/admin_dashboard_screen.dart
View file @
c2c69eec
...
@@ -40,16 +40,22 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
...
@@ -40,16 +40,22 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
}
}
void
_showAddEditAddressDialog
({
DeliveryAddress
?
address
})
{
void
_showAddEditAddressDialog
({
DeliveryAddress
?
address
})
{
if
(
_user
==
null
)
return
;
showDialog
(
showDialog
(
context:
context
,
context:
context
,
builder:
(
context
)
=>
AddEditAddressDialog
(
builder:
(
context
)
=>
AddEditAddressDialog
(
address:
address
,
address:
address
,
onSave:
(
address
)
=>
_firestoreService
.
saveAddress
(
address
),
userId:
_user
!.
uid
,
onSave:
(
address
)
{
_firestoreService
.
saveAddress
(
address
);
},
),
),
);
);
}
}
Future
<
void
>
_showUploadCsvDialog
()
async
{
Future
<
void
>
_showUploadCsvDialog
()
async
{
if
(
_user
==
null
)
return
;
try
{
try
{
final
result
=
await
FilePicker
.
platform
.
pickFiles
(
final
result
=
await
FilePicker
.
platform
.
pickFiles
(
type:
FileType
.
custom
,
type:
FileType
.
custom
,
...
@@ -72,6 +78,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
...
@@ -72,6 +78,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
final
addresses
=
list
.
map
((
row
)
{
final
addresses
=
list
.
map
((
row
)
{
try
{
try
{
return
DeliveryAddress
(
return
DeliveryAddress
(
userId:
_user
!.
uid
,
streetAddress:
row
[
0
].
toString
(),
streetAddress:
row
[
0
].
toString
(),
city:
row
[
1
].
toString
(),
city:
row
[
1
].
toString
(),
state:
row
[
2
].
toString
(),
state:
row
[
2
].
toString
(),
...
@@ -194,6 +201,9 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
...
@@ -194,6 +201,9 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
}
}
Widget
_buildLoggedInView
(
BuildContext
context
)
{
Widget
_buildLoggedInView
(
BuildContext
context
)
{
if
(
_user
==
null
)
{
return
const
Center
(
child:
CircularProgressIndicator
());
}
return
Padding
(
return
Padding
(
padding:
const
EdgeInsets
.
all
(
16.0
),
padding:
const
EdgeInsets
.
all
(
16.0
),
child:
Column
(
child:
Column
(
...
@@ -229,7 +239,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
...
@@ -229,7 +239,7 @@ class _AdminDashboardScreenState extends State<AdminDashboardScreen> {
child:
AddressList
(
child:
AddressList
(
onEdit:
(
address
)
=>
_showAddEditAddressDialog
(
address:
address
),
onEdit:
(
address
)
=>
_showAddEditAddressDialog
(
address:
address
),
onDelete:
_deleteAddress
,
onDelete:
_deleteAddress
,
addressesStream:
_firestoreService
.
getAddresses
(),
addressesStream:
_firestoreService
.
getAddresses
(
_user
!.
uid
),
),
),
),
),
const
SizedBox
(
height:
16
),
const
SizedBox
(
height:
16
),
...
...
lib/services/firestore_service.dart
View file @
c2c69eec
...
@@ -5,10 +5,14 @@ class FirestoreService {
...
@@ -5,10 +5,14 @@ class FirestoreService {
final
FirebaseFirestore
_db
=
FirebaseFirestore
.
instance
;
final
FirebaseFirestore
_db
=
FirebaseFirestore
.
instance
;
final
String
_collectionPath
=
'addresses'
;
final
String
_collectionPath
=
'addresses'
;
// Get a stream of all addresses
// Get a stream of addresses for a specific user
Stream
<
List
<
DeliveryAddress
>>
getAddresses
()
{
Stream
<
List
<
DeliveryAddress
>>
getAddresses
(
String
userId
)
{
return
_db
.
collection
(
_collectionPath
).
snapshots
().
map
((
snapshot
)
=>
return
_db
snapshot
.
docs
.
map
((
doc
)
=>
DeliveryAddress
.
fromJson
(
doc
.
data
())).
toList
());
.
collection
(
_collectionPath
)
.
where
(
'userId'
,
isEqualTo:
userId
)
.
snapshots
()
.
map
((
snapshot
)
=>
snapshot
.
docs
.
map
((
doc
)
=>
DeliveryAddress
.
fromJson
(
doc
.
data
())).
toList
());
}
}
// Add or update an address
// Add or update an address
...
...
lib/widgets/add_edit_address_dialog.dart
View file @
c2c69eec
...
@@ -3,9 +3,15 @@ import '../models/delivery_address.dart';
...
@@ -3,9 +3,15 @@ import '../models/delivery_address.dart';
class
AddEditAddressDialog
extends
StatefulWidget
{
class
AddEditAddressDialog
extends
StatefulWidget
{
final
DeliveryAddress
?
address
;
final
DeliveryAddress
?
address
;
final
String
userId
;
final
Function
(
DeliveryAddress
)
onSave
;
final
Function
(
DeliveryAddress
)
onSave
;
const
AddEditAddressDialog
({
super
.
key
,
this
.
address
,
required
this
.
onSave
});
const
AddEditAddressDialog
({
super
.
key
,
this
.
address
,
required
this
.
userId
,
required
this
.
onSave
,
});
@override
@override
State
<
AddEditAddressDialog
>
createState
()
=>
_AddEditAddressDialogState
();
State
<
AddEditAddressDialog
>
createState
()
=>
_AddEditAddressDialogState
();
...
@@ -98,6 +104,7 @@ class _AddEditAddressDialogState extends State<AddEditAddressDialog> {
...
@@ -98,6 +104,7 @@ class _AddEditAddressDialogState extends State<AddEditAddressDialog> {
if
(
_formKey
.
currentState
!.
validate
())
{
if
(
_formKey
.
currentState
!.
validate
())
{
final
address
=
DeliveryAddress
(
final
address
=
DeliveryAddress
(
id:
widget
.
address
?.
id
,
// Keep original ID if editing
id:
widget
.
address
?.
id
,
// Keep original ID if editing
userId:
widget
.
userId
,
streetAddress:
_streetController
.
text
,
streetAddress:
_streetController
.
text
,
city:
_cityController
.
text
,
city:
_cityController
.
text
,
state:
_stateController
.
text
,
state:
_stateController
.
text
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment