From 60033fdef38c71a042e19632b0944bf3b673ab81 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 6 Oct 2024 01:42:51 +0800 Subject: [PATCH] :bug: Fix platform specific bugs & crashes --- lib/platform.dart | 2 + lib/screens/account/profile_edit.dart | 61 ++++++++++--------- lib/screens/chat.dart | 6 +- lib/screens/realms/realm_organize.dart | 61 ++++++++++--------- .../attachments/attachment_editor.dart | 3 +- .../navigation/app_navigation_rail.dart | 6 ++ macos/Runner/Info.plist | 6 ++ 7 files changed, 85 insertions(+), 60 deletions(-) diff --git a/lib/platform.dart b/lib/platform.dart index 61f2918..80d4db9 100644 --- a/lib/platform.dart +++ b/lib/platform.dart @@ -29,6 +29,8 @@ abstract class PlatformInfo { static bool get canRateTheApp => isIOS || isMacOS; + static bool get canCropImage => isIOS || isAndroid || isWeb; + static bool get canRecord => (isMobile || isMacOS); static bool get canPushNotification => isAndroid || isIOS || isMacOS; diff --git a/lib/screens/account/profile_edit.dart b/lib/screens/account/profile_edit.dart index feb529f..0f14056 100644 --- a/lib/screens/account/profile_edit.dart +++ b/lib/screens/account/profile_edit.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:gap/gap.dart'; @@ -9,6 +7,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:intl/intl.dart'; import 'package:solian/exts.dart'; import 'package:solian/models/attachment.dart'; +import 'package:solian/platform.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/providers/content/attachment.dart'; import 'package:solian/services.dart'; @@ -77,36 +76,42 @@ class _PersonalizeScreenState extends State { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; + XFile file; + final image = await _imagePicker.pickImage(source: ImageSource.gallery); if (image == null) return; - CroppedFile? croppedFile = await ImageCropper().cropImage( - sourcePath: image.path, - uiSettings: [ - AndroidUiSettings( - toolbarTitle: 'cropImage'.tr, - toolbarColor: Theme.of(context).colorScheme.primary, - toolbarWidgetColor: Theme.of(context).colorScheme.onPrimary, - aspectRatioPresets: [ - if (position == 'avatar') CropAspectRatioPreset.square, - if (position == 'banner') _BannerCropAspectRatioPreset(), - ], - ), - IOSUiSettings( - title: 'cropImage'.tr, - aspectRatioPresets: [ - if (position == 'avatar') CropAspectRatioPreset.square, - if (position == 'banner') _BannerCropAspectRatioPreset(), - ], - ), - WebUiSettings( - context: context, - ), - ], - ); + if (PlatformInfo.canCropImage) { + CroppedFile? croppedFile = await ImageCropper().cropImage( + sourcePath: image.path, + uiSettings: [ + AndroidUiSettings( + toolbarTitle: 'cropImage'.tr, + toolbarColor: Theme.of(context).colorScheme.primary, + toolbarWidgetColor: Theme.of(context).colorScheme.onPrimary, + aspectRatioPresets: [ + if (position == 'avatar') CropAspectRatioPreset.square, + if (position == 'banner') _BannerCropAspectRatioPreset(), + ], + ), + IOSUiSettings( + title: 'cropImage'.tr, + aspectRatioPresets: [ + if (position == 'avatar') CropAspectRatioPreset.square, + if (position == 'banner') _BannerCropAspectRatioPreset(), + ], + ), + WebUiSettings( + context: context, + ), + ], + ); - if (croppedFile == null) return; - final file = File(croppedFile.path); + if (croppedFile == null) return; + file = XFile(croppedFile.path); + } else { + file = XFile(image.path); + } setState(() => _isBusy = true); diff --git a/lib/screens/chat.dart b/lib/screens/chat.dart index 5afce72..e798aa5 100644 --- a/lib/screens/chat.dart +++ b/lib/screens/chat.dart @@ -289,7 +289,7 @@ class _ChatListState extends State { ..._realmChannels.values.expand((x) => x), ]), selfId: selfId, - useReplace: false, + useReplace: AppTheme.isLargeScreen(context), ), ), RefreshIndicator( @@ -297,7 +297,7 @@ class _ChatListState extends State { child: ChannelListWidget( channels: _directChannels, selfId: selfId, - useReplace: false, + useReplace: AppTheme.isLargeScreen(context), ), ), ...realms.availableRealms.map( @@ -306,7 +306,7 @@ class _ChatListState extends State { child: ChannelListWidget( channels: _realmChannels[x.alias] ?? [], selfId: selfId, - useReplace: false, + useReplace: AppTheme.isLargeScreen(context), ), ), ), diff --git a/lib/screens/realms/realm_organize.dart b/lib/screens/realms/realm_organize.dart index 85f2786..7d78969 100644 --- a/lib/screens/realms/realm_organize.dart +++ b/lib/screens/realms/realm_organize.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:flutter/material.dart'; import 'package:flutter_animate/flutter_animate.dart'; import 'package:get/get.dart'; @@ -8,6 +6,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:solian/exts.dart'; import 'package:solian/models/attachment.dart'; import 'package:solian/models/realm.dart'; +import 'package:solian/platform.dart'; import 'package:solian/providers/auth.dart'; import 'package:solian/providers/content/attachment.dart'; import 'package:solian/router.dart'; @@ -84,36 +83,42 @@ class _RealmOrganizeScreenState extends State { final AuthProvider auth = Get.find(); if (auth.isAuthorized.isFalse) return; + XFile file; + final image = await _imagePicker.pickImage(source: ImageSource.gallery); if (image == null) return; - CroppedFile? croppedFile = await ImageCropper().cropImage( - sourcePath: image.path, - uiSettings: [ - AndroidUiSettings( - toolbarTitle: 'cropImage'.tr, - toolbarColor: Theme.of(context).colorScheme.primary, - toolbarWidgetColor: Theme.of(context).colorScheme.onPrimary, - aspectRatioPresets: [ - if (position == 'avatar') CropAspectRatioPreset.square, - if (position == 'banner') _BannerCropAspectRatioPreset(), - ], - ), - IOSUiSettings( - title: 'cropImage'.tr, - aspectRatioPresets: [ - if (position == 'avatar') CropAspectRatioPreset.square, - if (position == 'banner') _BannerCropAspectRatioPreset(), - ], - ), - WebUiSettings( - context: context, - ), - ], - ); + if (PlatformInfo.canCropImage) { + CroppedFile? croppedFile = await ImageCropper().cropImage( + sourcePath: image.path, + uiSettings: [ + AndroidUiSettings( + toolbarTitle: 'cropImage'.tr, + toolbarColor: Theme.of(context).colorScheme.primary, + toolbarWidgetColor: Theme.of(context).colorScheme.onPrimary, + aspectRatioPresets: [ + if (position == 'avatar') CropAspectRatioPreset.square, + if (position == 'banner') _BannerCropAspectRatioPreset(), + ], + ), + IOSUiSettings( + title: 'cropImage'.tr, + aspectRatioPresets: [ + if (position == 'avatar') CropAspectRatioPreset.square, + if (position == 'banner') _BannerCropAspectRatioPreset(), + ], + ), + WebUiSettings( + context: context, + ), + ], + ); - if (croppedFile == null) return; - final file = File(croppedFile.path); + if (croppedFile == null) return; + file = XFile(croppedFile.path); + } else { + file = XFile(image.path); + } setState(() => _isBusy = true); diff --git a/lib/widgets/attachments/attachment_editor.dart b/lib/widgets/attachments/attachment_editor.dart index e764ccd..2fa3ea5 100644 --- a/lib/widgets/attachments/attachment_editor.dart +++ b/lib/widgets/attachments/attachment_editor.dart @@ -396,7 +396,8 @@ class _AttachmentEditorPopupState extends State { ), if (!element.isCompleted && element.error == null && - canBeCrop) + canBeCrop && + PlatformInfo.canCropImage) Obx( () => IconButton( color: Colors.teal, diff --git a/lib/widgets/navigation/app_navigation_rail.dart b/lib/widgets/navigation/app_navigation_rail.dart index 8f46936..523d56c 100644 --- a/lib/widgets/navigation/app_navigation_rail.dart +++ b/lib/widgets/navigation/app_navigation_rail.dart @@ -1,4 +1,7 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:solian/router.dart'; import 'package:solian/widgets/navigation/app_navigation.dart'; @@ -54,6 +57,9 @@ class _AppNavigationRailState extends State { setState(() => _currentIndex = idx); AppRouter.instance.goNamed(AppNavigation.destinations[idx].page); }, + ).paddingOnly( + top: max(16, MediaQuery.of(context).padding.top), + bottom: max(16, MediaQuery.of(context).padding.bottom), ); } } diff --git a/macos/Runner/Info.plist b/macos/Runner/Info.plist index ae66573..a61083c 100644 --- a/macos/Runner/Info.plist +++ b/macos/Runner/Info.plist @@ -57,5 +57,11 @@ INStartCallIntent INSendMessageIntent + NSCameraUsageDescription + Allow you take photo/video for your message or post + NSMicrophoneUsageDescription + Allow you record audio for your message or post + NSPhotoLibraryUsageDescription + Allow you add photo to your message or post