Skip to content

Commit

Permalink
update to flutter 2
Browse files Browse the repository at this point in the history
  • Loading branch information
redevrx committed Mar 10, 2021
1 parent 0c8aca8 commit 7577402
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 247 deletions.
169 changes: 89 additions & 80 deletions .packages

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:http/http.dart' as http;

void main() async {
await http
.get(
"http://172.19.128.1:8080/resocial/api/v1/generate/token?channelName=redev&uid=0&role=publisher&expireTime=3600")
.get(Uri.http("http://172.19.128.1:8080/resocial/api/v1/generate",
"/token?channelName=redev&uid=0&role=publisher&expireTime=3600"))
.then((token) {
Map t = jsonDecode(token.body);
print('${t['token']}');
Expand Down
9 changes: 4 additions & 5 deletions lib/Profile/AddProfile/bloc/add_profile_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ class AddProfileBloc extends Bloc<AddProfileEvent, AddProfileState> {
//check image file
if (_preferences.getString("imageProfile") != null) {
//upload image to data storage
final StorageReference mRef =
FirebaseStorage().ref().child("Profile Image").child("Images");
final StorageUploadTask uploadTask =
mRef.child("${uid}" + ".jpg").putFile(data.image);
final mRef =
FirebaseStorage.instance.ref().child("Profile Image").child("Images");
final uploadTask = mRef.child("${uid}" + ".jpg").putFile(data.image);

//download image url
var dowurl = await (await uploadTask.onComplete).ref.getDownloadURL();
var dowurl = await uploadTask.snapshot.ref.getDownloadURL();
var url = dowurl.toString();

//update user info
Expand Down
4 changes: 2 additions & 2 deletions lib/Profile/AddProfile/screen/add_info_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class addProfile extends StatelessWidget {
//get varialble permission camera
var status = Permission.camera;

if (await status.status.isUndetermined) {
if (await status.status.isDenied) {
//request permission
if (await status.request().isGranted) {
//result that request permission
Expand Down Expand Up @@ -113,7 +113,7 @@ class addProfile extends StatelessWidget {
BuildContext context, AddProfileBloc profileBloc) async {
var status = await Permission.storage;

if (await status.status.isUndetermined) {
if (await status.status.isDenied) {
//request permission
if (await status.request().isGranted) {
//result that request permission
Expand Down
4 changes: 2 additions & 2 deletions lib/Profile/EditPtofile/bloc/edit_profile_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class EditProfileBloc extends Bloc<EditProfileEvent, EditProfileState> {
FirebaseStorage.instance.ref().child("Profile Image/Backgrounds");
final uploadTask = _sRef.child("${uid}" + ".jpg").putFile(event.image);

var url = await (await uploadTask.onComplete).ref.getDownloadURL();
var url = await uploadTask.snapshot.ref.getDownloadURL();

final it = await updateUserImageBackground(uid, url.toString());

Expand All @@ -202,7 +202,7 @@ class EditProfileBloc extends Bloc<EditProfileEvent, EditProfileState> {
final _sRef = FirebaseStorage.instance.ref().child("Profile Image/Images");
final uploadTask = _sRef.child("${uid}" + ".jpg").putFile(event.image);

var url = await (await uploadTask.onComplete).ref.getDownloadURL();
var url = await uploadTask.snapshot.ref.getDownloadURL();

var it = await updateUserinfo(uid, url.toString());

Expand Down
4 changes: 2 additions & 2 deletions lib/Profile/EditPtofile/screen/user_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ Future<void> _checkCamerPermission(
BuildContext context, EditProfileBloc editProfileBloc, int type) async {
final camera = await Permission.camera;

if (await camera.status.isUndetermined) {
if (await camera.status.isDenied) {
//user not permission
if (await camera.request().isGranted) {
// //result that request permission
Expand All @@ -1246,7 +1246,7 @@ Future<void> _checkGalleryPermission(
BuildContext context, EditProfileBloc editProfileBloc, int type) async {
final gallery = await Permission.storage;

if (await gallery.status.isUndetermined) {
if (await gallery.status.isDenied) {
if (await gallery.request().isGranted) {
//user permission grant
}
Expand Down
4 changes: 2 additions & 2 deletions lib/call/permission.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Permissions {
return true;
}

if (status[Permission.camera].isUndetermined ||
status[Permission.microphone].isUndetermined) {
if (status[Permission.camera].isPermanentlyDenied ||
status[Permission.microphone].isPermanentlyDenied) {
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/call/repository/call_agora_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ class CallAgoraRepository implements CallRepository {
String receiverPic = "";
String tokenCall = "";

await http
.get(
"http://172.24.176.1:8080/resocial/api/v1/generate/token?channelName=$channelName&uid=0&role=publisher&expireTime=3600")
await http.Client()
.get(Uri.http("http://172.24.176.1:8080/resocial/api/v1/generate",
"/token?channelName=$channelName&uid=0&role=publisher&expireTime=3600"))
.then((token) {
Map t = jsonDecode(token.body);
tokenCall = t['token'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class MessageRepository {

//http post to FCM

await http.post('https://fcm.googleapis.com/fcm/send',
await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: {
'Authorization': 'key=$token',
'Content-Type': 'application/json'
Expand Down
2 changes: 1 addition & 1 deletion lib/comments/repository/comment_user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class CommentRepository {
notifyHead['notification'] = notifyData;

//http post to FCM
await http.post('https://fcm.googleapis.com/fcm/send',
await http.Client().post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: {
'Authorization': 'key=$token',
'Content-Type': 'application/json'
Expand Down
4 changes: 2 additions & 2 deletions lib/editPost/screen/edit_user_post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class __EditPostState extends State<_EditPost> {
Future<void> _checkGalleryPermission(PostBloc postBloc) async {
var gallery = await Permission.storage;

if (await gallery.status.isUndetermined) {
if (await gallery.status.isDenied) {
//not grant
if (await gallery.request().isGranted) {
// permission grant
Expand All @@ -102,7 +102,7 @@ class __EditPostState extends State<_EditPost> {
Future<void> _checkCameraPermission(PostBloc postBloc) async {
var camera = await Permission.camera;

if (await camera.status.isUndetermined) {
if (await camera.status.isDenied) {
//not grant
if (await camera.request().isGranted) {
// permission grant
Expand Down
4 changes: 2 additions & 2 deletions lib/home/screen/look_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LookImage extends StatelessWidget {
Future checkStoragePermission(BuildContext context, String imageUrl) async {
var storage = await Permission.storage;

if (await storage.status.isUndetermined) {
if (await storage.status.isDenied) {
if (await storage.request().isGranted) {
//downloadImage(imageUrl);
}
Expand Down Expand Up @@ -53,7 +53,7 @@ class LookImage extends StatelessWidget {
}
}

var response = await http.get(imageUrl);
var response = await http.Client().get(Uri.parse(imageUrl));
File file = new File(join(path + "/resocial", "image${i}.png"));
await file.writeAsBytesSync(response.bodyBytes);
print('object :${file}');
Expand Down
111 changes: 80 additions & 31 deletions lib/notifications/PushNotificationService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'dart:async';
import 'package:shared_preferences/shared_preferences.dart';

class PushNotificationService {
final FirebaseMessaging _fcm = FirebaseMessaging();
final FirebaseMessaging _fcm = FirebaseMessaging.instance;
final showNotify = ShowNotifyService();

Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
Expand All @@ -27,36 +27,83 @@ class PushNotificationService {
print("onBackgriundMessage");
}

Future initialise() {
Future initialise() async {
if (Platform.isIOS) {
_fcm.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_fcm.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
//ios request permission about notifications

await _fcm
.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
)
.then((notification) {
print(
'User granted permission IOS : ${notification.authorizationStatus}');
}).catchError((e) {
print('User granted permission IOS Error: ${e}');
});
}

//android request permission about notification
await _fcm
.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
)
.then((notification) {
print(
'User granted permission Android : ${notification.authorizationStatus}');
}).catchError((e) {
print('User granted permission Android Error: ${e}');
});

//create notify ios and android
showNotify.initialNotify();

_fcm.configure(
// onBackgroundMessage: myBackgroundMessageHandler,
onMessage: (message) {
if (message["title"].toString() == "chat") {
showNotify.showNotifyMessage(message);
} else {
//post notidy
showNotify.showNotifyPost(message);
}
},
onLaunch: (Map<String, dynamic> message) async {
print("onBackgriundMessage: $message");
showNotify.showNotifyPost(message);
},
onResume: (message) {
print("onResume: $message");
},
);
//this event will work while open
FirebaseMessaging.onMessage.listen((message) {
if (message.data["title"].toString() == "chat") {
showNotify.showNotifyMessage(message.data);
} else {
//post notidy
showNotify.showNotifyPost(message.data);
}
});

//this event will wok close app
FirebaseMessaging.onBackgroundMessage((message) {
if (message.data["title"].toString() == "chat") {
showNotify.showNotifyMessage(message.data);
} else {
//post notidy
showNotify.showNotifyPost(message.data);
}
});

//this event will work when user click
FirebaseMessaging.onMessageOpenedApp.listen((message) {
if (message.data["title"].toString() == "chat") {
// showNotify.showNotifyMessage(message.data);
//go to chat screen
} else {
//post notidy
// showNotify.showNotifyPost(message.data);
//go to home page
}
});
//notification and go to app
//check data from notification
//and give go that screen ?
}

getDeviceToken() async {
Expand Down Expand Up @@ -143,7 +190,7 @@ class ShowNotifyService {
);

var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIos);
android: initializationSettingsAndroid, iOS: initializationSettingsIos);

flutterNotify.initialize(
initializationSettings,
Expand All @@ -166,16 +213,17 @@ class ShowNotifyService {
messages: <Message>[Message(message['body'], null, null)],
conversationTitle: "New messages.",
),
importance: Importance.Max,
priority: Priority.High,
importance: Importance.high,
priority: Priority.high,
);

//create ios setting notify
var iOSPlatformChannelSpecifics = IOSNotificationDetails();

//create platform ios android noify
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
android: androidPlatformChannelSpecifics,
iOS: iOSPlatformChannelSpecifics);

//show notify
//id notify_post 1
Expand All @@ -190,16 +238,17 @@ class ShowNotifyService {
"notify_post",
"post",
"show notify to friends",
importance: Importance.Max,
priority: Priority.High,
importance: Importance.high,
priority: Priority.high,
);

//create ios setting notify
var iOSPlatformChannelSpecifics = IOSNotificationDetails();

//create platform ios android noify
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
android: androidPlatformChannelSpecifics,
iOS: iOSPlatformChannelSpecifics);

//show notify
//id notify_post 1
Expand Down
14 changes: 6 additions & 8 deletions lib/userPost/repository/post_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:intl/intl.dart';
import 'package:http/http.dart' as http;
import 'package:workmanager/workmanager.dart';

class PostRepository {
//update user post
Expand Down Expand Up @@ -46,13 +45,12 @@ class PostRepository {
print('update post image');

final _mRefFile =
FirebaseStorage().ref().child("Post Image").child("Images");
FirebaseStorage.instance.ref().child("Post Image").child("Images");

//save image to data storage
final uploadTask = _mRefFile.child(postId).putFile(image);

String urlImage =
await (await uploadTask.onComplete).ref.getDownloadURL();
String urlImage = await uploadTask.snapshot.ref.getDownloadURL();

//make map to json
mapBody["uid"] = uid;
Expand Down Expand Up @@ -127,7 +125,7 @@ class PostRepository {
Future<void> removePost(String postId) async {
final _mRef = FirebaseFirestore.instance;
final _mRefFile =
FirebaseStorage().ref().child("Post Image").child("Images");
FirebaseStorage.instance.ref().child("Post Image").child("Images");

try {
await _mRefFile
Expand Down Expand Up @@ -165,7 +163,7 @@ class PostRepository {

final _mRef = FirebaseFirestore.instance;
final _mRefFile =
FirebaseStorage().ref().child("Post Image").child("Images");
FirebaseStorage.instance.ref().child("Post Image").child("Images");

final key = _mRef.collection("Post").doc().id;
Map mapBody = HashMap<String, dynamic>();
Expand All @@ -185,7 +183,7 @@ class PostRepository {
//save image to data storage
final uploadTask = _mRefFile.child(key).putFile(image);

String url = await (await uploadTask.onComplete).ref.getDownloadURL();
String url = await uploadTask.snapshot.ref.getDownloadURL();

//make map to json
mapBody["uid"] = uid;
Expand Down Expand Up @@ -373,7 +371,7 @@ type:''

//http post to FCM

await http.post('https://fcm.googleapis.com/fcm/send',
await http.post(Uri.parse("https://fcm.googleapis.com/fcm/send"),
headers: {
'Authorization': 'key=$token',
'Content-Type': 'application/json'
Expand Down
Loading

0 comments on commit 7577402

Please sign in to comment.