diff --git a/lib/ui/views/main_page/feed/widgets/feed_post.dart b/lib/ui/views/main_page/feed/widgets/feed_post.dart index a49c9ee6..cffe047f 100644 --- a/lib/ui/views/main_page/feed/widgets/feed_post.dart +++ b/lib/ui/views/main_page/feed/widgets/feed_post.dart @@ -4,10 +4,13 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_bbcode/flutter_bbcode.dart'; import 'package:go_router/go_router.dart'; +import 'package:injector/injector.dart'; 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/services/interfaces/logger_service.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 +21,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 +252,42 @@ class _FeedPostState extends State { ), ), ), + const SizedBox(width: 12), + GestureDetector( + onTap: () async { + if (widget.showingComments) { + return; + } + await 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 +302,51 @@ class _FeedPostState extends State { } } +Future sharePressed( + BuildContext context, + String postText, + String authorName, + DateTime postTime, + List attachedFiles, +) async { + final logger = Injector.appInstance.get(); + + try { + final String formattedDate = + DateFormat('d MMMM yyyy, HH:mm', 'ru_RU').format(postTime); + final String text = '$authorName\n$formattedDate\n\n$postText'; + + final List xFiles = []; + + for (final fileViewModel in attachedFiles) { + final File? file = await fileViewModel.getFile(); + if (file != null && file.existsSync()) { + xFiles.add(XFile(file.path)); + } + } + + if (!context.mounted) { + return ShareResult.unavailable; + } + final RenderBox box = context.findRenderObject() as RenderBox; + if (xFiles.isNotEmpty) { + return await Share.shareXFiles( + xFiles, + text: text, + sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size, + ); + } else { + return await Share.share( + text, + sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size, + ); + } + } catch (e, stackTrace) { + logger.logError('Ошибка при попытке поделиться постом: $e', stackTrace); + rethrow; + } +} + class _PostHeader extends StatelessWidget { final DateTime postTime; diff --git a/lib/ui/views/main_page/main_page_navigation_bar.dart b/lib/ui/views/main_page/main_page_navigation_bar.dart index 40773483..cf047c13 100644 --- a/lib/ui/views/main_page/main_page_navigation_bar.dart +++ b/lib/ui/views/main_page/main_page_navigation_bar.dart @@ -1,4 +1,3 @@ -import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:unn_mobile/core/viewmodels/main_page_view_model.dart'; @@ -18,17 +17,13 @@ class MainPageNavigationBar extends StatelessWidget { return Stack( alignment: Alignment.bottomCenter, children: [ - ClipRect( - child: BackdropFilter( - filter: ImageFilter.blur( - sigmaX: 6.0, - sigmaY: 6.0, - ), - child: Container( - width: double.maxFinite, - height: 60, - color: Colors.transparent, - ), + Positioned( + top: 0, + left: 0, + right: 0, + child: Container( + height: 0.3, + color: Colors.grey.withOpacity(0.5), ), ), NavigationBar( diff --git a/pubspec.yaml b/pubspec.yaml index e9122b01..966a019c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,9 @@ name: unn_mobile description: A mobile application for UNN Portal website publish_to: 'none' -version: 0.2.3+228 + +version: 0.2.3+229 + environment: sdk: '>=3.1.2 <4.0.0' @@ -10,7 +12,7 @@ environment: dependencies: flutter: sdk: flutter - + share_plus: ^10.0.2 webview_flutter: ^4.9.0 flutter_secure_storage: ^9.2.2 http: ^1.1.0