Skip to content

Commit

Permalink
Add ability to upload shipment receipts (#240)
Browse files Browse the repository at this point in the history
* Add ability to upload shipment receipts

* Add ability to upload delivery receipts
  • Loading branch information
harsimranmaan committed Jan 7, 2021
1 parent 6a33a66 commit 18ddd5d
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 149 deletions.
23 changes: 23 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ PODS:
- Firebase/Messaging (6.33.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 4.7.0)
- Firebase/Storage (6.33.0):
- Firebase/CoreOnly
- FirebaseStorage (~> 3.9.0)
- firebase_analytics (6.3.0):
- Firebase/Analytics (~> 6.33.0)
- Firebase/CoreOnly (~> 6.33.0)
Expand All @@ -37,6 +40,11 @@ PODS:
- Firebase/Messaging (~> 6.33.0)
- firebase_core
- Flutter
- firebase_storage (5.2.0):
- Firebase/CoreOnly (~> 6.33.0)
- Firebase/Storage (~> 6.33.0)
- firebase_core
- Flutter
- FirebaseAnalytics (6.8.3):
- FirebaseCore (~> 6.10)
- FirebaseInstallations (~> 1.6)
Expand Down Expand Up @@ -84,6 +92,9 @@ PODS:
- GoogleUtilities/Reachability (~> 6.7)
- GoogleUtilities/UserDefaults (~> 6.7)
- Protobuf (>= 3.9.2, ~> 3.9)
- FirebaseStorage (3.9.1):
- FirebaseCore (~> 6.10)
- GTMSessionFetcher/Core (~> 1.1)
- Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1):
- Flutter
Expand Down Expand Up @@ -115,6 +126,8 @@ PODS:
- GoogleUtilities/UserDefaults (6.7.2):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (1.5.0)
- image_picker (0.0.1):
- Flutter
- nanopb (1.30906.0):
- nanopb/decode (= 1.30906.0)
- nanopb/encode (= 1.30906.0)
Expand All @@ -131,8 +144,10 @@ DEPENDENCIES:
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_crashlytics (from `.symlinks/plugins/firebase_crashlytics/ios`)
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- firebase_storage (from `.symlinks/plugins/firebase_storage/ios`)
- Flutter (from `Flutter`)
- flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`)
- image_picker (from `.symlinks/plugins/image_picker/ios`)
- package_info (from `.symlinks/plugins/package_info/ios`)

SPEC REPOS:
Expand All @@ -146,6 +161,7 @@ SPEC REPOS:
- FirebaseInstallations
- FirebaseInstanceID
- FirebaseMessaging
- FirebaseStorage
- GoogleAppMeasurement
- GoogleDataTransport
- GoogleUtilities
Expand All @@ -165,10 +181,14 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/firebase_crashlytics/ios"
firebase_messaging:
:path: ".symlinks/plugins/firebase_messaging/ios"
firebase_storage:
:path: ".symlinks/plugins/firebase_storage/ios"
Flutter:
:path: Flutter
flutter_keyboard_visibility:
:path: ".symlinks/plugins/flutter_keyboard_visibility/ios"
image_picker:
:path: ".symlinks/plugins/image_picker/ios"
package_info:
:path: ".symlinks/plugins/package_info/ios"

Expand All @@ -179,6 +199,7 @@ SPEC CHECKSUMS:
firebase_core: 5d6a02f3d85acd5f8321c2d6d62877626a670659
firebase_crashlytics: 7b37f8e79a82175606a3447852c9efa8e10034b3
firebase_messaging: 738982b5b4110cdc7a72449544123f6fcdb65604
firebase_storage: a023e199edb807d8481c8aa722c8516f462ffab2
FirebaseAnalytics: 5dd088bd2e67bb9d13dbf792d1164ceaf3052193
FirebaseAuth: c92d49ada7948d1a23466e3db17bc4c2039dddc3
FirebaseCore: d889d9e12535b7f36ac8bfbf1713a0836a3012cd
Expand All @@ -187,12 +208,14 @@ SPEC CHECKSUMS:
FirebaseInstallations: 466c7b4d1f58fe16707693091da253726a731ed2
FirebaseInstanceID: bd3ffc24367f901a43c063b36c640b345a4a5dd1
FirebaseMessaging: 5eca4ef173de76253352511aafef774caa1cba2a
FirebaseStorage: 15e0f15ef3c7fec3d1899d68623e47d4447066b4
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
GoogleAppMeasurement: 966e88df9d19c15715137bb2ddaf52373f111436
GoogleDataTransport: f56af7caa4ed338dc8e138a5d7c5973e66440833
GoogleUtilities: 7f2f5a07f888cdb145101d6042bc4422f57e70b3
GTMSessionFetcher: b3503b20a988c4e20cc189aa798fd18220133f52
image_picker: 9c3312491f862b28d21ecd8fdf0ee14e601b3f09
nanopb: 59317e09cf1f1a0af72f12af412d54edf52603fc
package_info: 873975fc26034f0b863a300ad47e7f1ac6c7ec62
PromisesObjC: 8c196f5a328c2cba3e74624585467a557dcb482f
Expand Down
2 changes: 2 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>NSCameraUsageDescription</key>
<string>Camera access is required to upload images for actions like proof of delivery.</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
2 changes: 1 addition & 1 deletion lib/data/auth/remote_auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class RemoteAuthRepository extends AuthRepository {
}

Future<void> _registerDeviceToken(api.User user) async {
if (user.role != api.UserRole.none) {
if (user.role == api.UserRole.none) {
return;
}
final client = await apiClient();
Expand Down
1 change: 1 addition & 0 deletions lib/data/shipment/shipment_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ abstract class ShipmentRepository {
Future<Shipment> fetchShipment(String id);
Future<Shipment> createShipment(Shipment shipment);
Future<Shipment> updateShipment(String id, Shipment shipment);

Future<List<Shipment>> fetchShipments(
{int? page = 1,
ShipmentType? shipmentType,
Expand Down
26 changes: 10 additions & 16 deletions lib/extensions/shipment_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ extension ShipmentPercent on ShipmentStatus {
case ShipmentStatus.inTransit:
return 0.2;
case ShipmentStatus.arrived:
return 0.3;
case ShipmentStatus.assigned:
return 0.4;
case ShipmentStatus.accepted:
return 0.5;
case ShipmentStatus.assigned:
return 0.55;
case ShipmentStatus.rejected:
return 0.6;
case ShipmentStatus.loaded:
return 0.7;
case ShipmentStatus.unloaded:
return 0.60;
case ShipmentStatus.accepted:
return 0.8;
case ShipmentStatus.abandoned:
case ShipmentStatus.loaded:
return 0.9;
case ShipmentStatus.delivered:
return 1;
}
}
Expand All @@ -60,9 +58,7 @@ extension ShipmentStatusExtension on ShipmentStatus {
return MdiIcons.accessPointMinus;
case ShipmentStatus.loaded:
return MdiIcons.accessPointMinus;
case ShipmentStatus.unloaded:
return MdiIcons.accessPointMinus;
case ShipmentStatus.abandoned:
case ShipmentStatus.delivered:
return MdiIcons.accessPointMinus;
}
}
Expand All @@ -83,10 +79,8 @@ extension ShipmentStatusExtension on ShipmentStatus {
return Colors.red;
case ShipmentStatus.loaded:
return baseColor;
case ShipmentStatus.unloaded:
return baseColor;
case ShipmentStatus.abandoned:
return baseColor;
case ShipmentStatus.delivered:
return Colors.green;
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/screens/none_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class NoneHome extends StatelessWidget {
return ShipantherScaffold(
user,
bottomNavigationBar: null,
title: ShipantherLocalizations.of(context)!.tenantsTitle(2),
title: ShipantherLocalizations.of(context)!.shipantherTitle,
actions: const [],
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(ShipantherLocalizations.of(context)!.helloParam(user.name)),
Text(ShipantherLocalizations.of(context)!.tenantLessUserMessage),
Expand Down
41 changes: 38 additions & 3 deletions lib/screens/shipment/driver_list.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import 'dart:io';

import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';

import 'package:shipanther/bloc/shipment/shipment_bloc.dart';

Expand All @@ -25,6 +30,37 @@ class DriverShipmentList extends StatefulWidget {

class _DriverShipmentListState extends State<DriverShipmentList> {
int _currentIndex = 0;

Future<void> handleDelivery(User driver, Shipment t) async {
late PickedFile file;
try {
file = await ImagePicker()
.getImage(source: ImageSource.camera, imageQuality: 50);
} catch (e) {
print('hsm $e');
}
//ignore:unnecessary_null_comparison
if (file == null) {
return;
}
final ref = FirebaseStorage.instance
.ref()
.child('files/${t.tenantId}/${t.customerId}')
.child('/${t.id}.jpg');
final metadata = SettableMetadata(
contentType: 'image/jpeg',
customMetadata: {'picked-file-path': file.path});
late UploadTask uploadTask;
if (kIsWeb) {
uploadTask = ref.putData(await file.readAsBytes(), metadata);
} else {
uploadTask = ref.putFile(File(file.path), metadata);
}
await uploadTask;
t.status = ShipmentStatus.delivered;
widget.shipmentBloc.add(UpdateShipment(t.id, t));
}

@override
Widget build(BuildContext context) {
void showAlertDialog(BuildContext context, Shipment t) {
Expand Down Expand Up @@ -79,7 +115,7 @@ class _DriverShipmentListState extends State<DriverShipmentList> {
element.status == ShipmentStatus.accepted ||
element.status == ShipmentStatus.assigned)
: widget.shipmentsLoadedState.shipments
.where((element) => element.status == ShipmentStatus.arrived);
.where((element) => element.status == ShipmentStatus.delivered);

final body = items.isEmpty
? Center(
Expand Down Expand Up @@ -150,8 +186,7 @@ class _DriverShipmentListState extends State<DriverShipmentList> {
FlatButton(
color: Colors.green,
onPressed: () {
t.status = ShipmentStatus.arrived;
widget.shipmentBloc.add(UpdateShipment(t.id, t));
handleDelivery(widget.loggedInUser, t);
},
child: Text(ShipantherLocalizations.of(context)!
.shipmentDelivered),
Expand Down
Loading

0 comments on commit 18ddd5d

Please sign in to comment.