-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Добавлена возможность поделиться постом #410
base: develop
Are you sure you want to change the base?
Changes from 7 commits
e4d86ba
1e9d1a9
5f21e62
78f5d67
9ec2a6c
8f64aab
9c5f599
dcde74d
9baf5f5
ca1c5a8
f54e1f7
e9cd277
2f5901a
db91adc
972ad76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import 'package:intl/intl.dart'; | |
import 'package:unn_mobile/core/misc/app_settings.dart'; | ||
import 'package:unn_mobile/core/misc/custom_bb_tags.dart'; | ||
import 'package:unn_mobile/core/models/rating_list.dart'; | ||
import 'package:unn_mobile/core/viewmodels/attached_file_view_model.dart'; | ||
import 'package:unn_mobile/core/viewmodels/feed_post_view_model.dart'; | ||
import 'package:unn_mobile/core/viewmodels/profile_view_model.dart'; | ||
import 'package:unn_mobile/core/viewmodels/reaction_view_model.dart'; | ||
|
@@ -18,6 +19,9 @@ import 'package:unn_mobile/ui/views/main_page/feed/widgets/attached_file.dart'; | |
import 'package:unn_mobile/ui/views/main_page/main_page_routing.dart'; | ||
import 'package:unn_mobile/ui/widgets/shimmer.dart'; | ||
import 'package:unn_mobile/ui/widgets/shimmer_loading.dart'; | ||
import 'package:share_plus/share_plus.dart'; | ||
|
||
import 'dart:io'; | ||
|
||
const idkWhatColor = Color(0xFF989EA9); | ||
|
||
|
@@ -246,6 +250,39 @@ class _FeedPostState extends State<FeedPost> { | |
), | ||
), | ||
), | ||
const SizedBox(width: 12), | ||
GestureDetector( | ||
onTap: () async { | ||
sharePressed( | ||
context, | ||
model.postText, | ||
model.profileViewModel.fullname, | ||
model.postTime, | ||
model.attachedFileViewModels, | ||
); | ||
}, | ||
child: Container( | ||
padding: const EdgeInsets.symmetric( | ||
horizontal: 12, | ||
vertical: 6, | ||
).copyWith(right: 8), | ||
decoration: BoxDecoration( | ||
color: idkWhatColor.withOpacity(0.1), | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
child: const Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Icon( | ||
Icons.share, | ||
color: idkWhatColor, | ||
size: 23, | ||
), | ||
SizedBox(width: 6), | ||
], | ||
), | ||
), | ||
), | ||
], | ||
), | ||
], | ||
|
@@ -260,6 +297,42 @@ class _FeedPostState extends State<FeedPost> { | |
} | ||
} | ||
|
||
void sharePressed( | ||
BuildContext context, | ||
String postText, | ||
String authorName, | ||
DateTime postTime, | ||
List<AttachedFileViewModel> attachedFiles, | ||
) async { | ||
final String text = | ||
'$authorName\n${DateFormat('d MMMM yyyy, HH:mm', 'ru_RU').format(postTime)}\n\n$postText'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Андрею такое точно бы не понравилось :D Не уверен, что здесь это прям лучше будет, так что пункт про тройные кавычки - на твоё усмотрение |
||
|
||
final List<XFile> xFiles = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
for (final fileViewModel in attachedFiles) { | ||
final File? file = await fileViewModel.getFile(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут ведь файлы должны скачиваться, очень долго наверно делиться постами с большим числом файлов. И наверно будет классно, когда несколько раз поделиться нажмёшь, пока они качаются Надо потестить будет |
||
if (file != null && file.existsSync()) { | ||
xFiles.add(XFile(file.path)); | ||
} | ||
} | ||
|
||
// ignore: use_build_context_synchronously | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Мы обычно это обходим через if (context.mounted) |
||
final RenderBox box = context.findRenderObject() as RenderBox; | ||
|
||
if (xFiles.isNotEmpty) { | ||
Share.shareXFiles( | ||
xFiles, | ||
text: text, | ||
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Namxobick у нас приложение под айпады работает? https://pub.dev/documentation/share_plus/latest/share_plus/Share/shareXFiles.html |
||
); | ||
} else { | ||
Share.share( | ||
text, | ||
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size, | ||
); | ||
} | ||
} | ||
|
||
class _PostHeader extends StatelessWidget { | ||
final DateTime postTime; | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Подозреваю, это из другого реквеста? (из #407 ?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если хочешь, можешь попробовать посмотреть на git revert, чтобы откатить изменения в этом файле) Хэши коммитов у тебя в гитхабе написаны There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ладно, в той ветке вероятно еще будут изменения, так что настоятельно рекомендую этот один коммит откатить в этой ветке |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я бы сам метод сделал
Future<void> sharePressed
или дажеFuture<ShareResult> sharePressed
Перед
Share.share
иShare.shareXFiles
добавил бы await (если сделаешь типFuture<ShareResult>
то вообщеreturn await Share.<...>
)И там, где его вызываешь сделал бы await sharePressed. Если будешь делать с ShareResult, то снаружи как-то обработай этот результат.
И наверно не мешало бы отловить исключения, хотя бы самого Share. Но старайся блоком try...catch охватывать как можно меньше кода. И при исключении используй LoggerService для сообщений об ошибке