Skip to content

Commit

Permalink
image sharing support
Browse files Browse the repository at this point in the history
  • Loading branch information
im-Amitto committed Aug 17, 2020
1 parent 66b4662 commit e31e26a
Showing 1 changed file with 51 additions and 64 deletions.
115 changes: 51 additions & 64 deletions lib/screens/telehealth/chat.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import 'dart:async';
// import 'dart:collection';
// import 'dart:io';
// import 'dart:math';
import 'dart:io';

import 'package:cloud_firestore/cloud_firestore.dart';
// import 'package:firebase_auth/firebase_auth.dart';
// import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// import 'package:image_picker/image_picker.dart';
import 'package:image_picker/image_picker.dart';
import 'package:intl/intl.dart';
import 'package:dash_chat/dash_chat.dart';
import 'package:getwidget/getwidget.dart';
Expand All @@ -20,7 +17,6 @@ class ChatScreen extends StatefulWidget {
final String userId;
final String userName;


ChatScreen(
{Key key,
@required this.messagesId,
Expand Down Expand Up @@ -89,31 +85,22 @@ class _ChatScreenState extends State<ChatScreen> {
}

void uploadImage(result) async {
// final StorageReference storageRef =
// FirebaseStorage.instance.ref().child("chat_images");

// StorageUploadTask uploadTask = storageRef.putFile(
// result,
// StorageMetadata(
// contentType: 'image/jpg',
// ),
// );
// StorageTaskSnapshot download = await uploadTask.onComplete;

// String url = await download.ref.getDownloadURL();

// ChatMessage message = ChatMessage(text: "", user: user, image: url);

// var documentReference = Firestore.instance
// .collection('messages')
// .document(DateTime.now().millisecondsSinceEpoch.toString());

// Firestore.instance.runTransaction((transaction) async {
// await transaction.set(
// documentReference,
// message.toJson(),
// );
// });
final StorageReference storageRef = FirebaseStorage.instance
.ref()
.child(widget.userId + "-" + DateTime.now().toString());

StorageUploadTask uploadTask = storageRef.putFile(
result,
StorageMetadata(
contentType: 'image/jpg',
),
);
StorageTaskSnapshot download = await uploadTask.onComplete;

String url = await download.ref.getDownloadURL();

ChatMessage message = ChatMessage(text: "", user: chatUser, image: url);
onSend(message);
}

@override
Expand Down Expand Up @@ -201,38 +188,38 @@ class _ChatScreenState extends State<ChatScreen> {
},
shouldShowLoadEarlier: false,
showTraillingBeforeSend: true,
// trailing: <Widget>[
// IconButton(
// icon: Icon(Icons.camera_alt),
// onPressed: () async {
// File result = await ImagePicker.pickImage(
// source: ImageSource.camera,
// imageQuality: 80,
// maxHeight: 400,
// maxWidth: 400,
// );

// if (result != null) {
// uploadImage(result);
// }
// },
// ),
// IconButton(
// icon: Icon(Icons.photo),
// onPressed: () async {
// File result = await ImagePicker.pickImage(
// source: ImageSource.gallery,
// imageQuality: 80,
// maxHeight: 400,
// maxWidth: 400,
// );

// if (result != null) {
// uploadImage(result);
// }
// },
// ),
// ],
trailing: <Widget>[
IconButton(
icon: Icon(Icons.camera_alt),
onPressed: () async {
File result = await ImagePicker.pickImage(
source: ImageSource.camera,
imageQuality: 80,
maxHeight: 400,
maxWidth: 400,
);

if (result != null) {
uploadImage(result);
}
},
),
IconButton(
icon: Icon(Icons.photo),
onPressed: () async {
File result = await ImagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 80,
maxHeight: 400,
maxWidth: 400,
);

if (result != null) {
uploadImage(result);
}
},
),
],
);
}
}));
Expand Down

0 comments on commit e31e26a

Please sign in to comment.