diff --git a/lib/main.dart b/lib/main.dart index 20ef9ae..b973d8c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -33,32 +33,39 @@ void main() async { appRunner: () async { WidgetsFlutterBinding.ensureInitialized(); - if (!PlatformInfo.isWeb) { - await protocolHandler.register('solink'); - } - - await Firebase.initializeApp( - options: DefaultFirebaseOptions.currentPlatform, - ); - - if (PlatformInfo.isDesktop) { - await Window.initialize(); - - if (PlatformInfo.isMacOS) { - await Window.hideTitle(); - await Window.hideCloseButton(); - await Window.hideMiniaturizeButton(); - await Window.hideZoomButton(); - await Window.makeTitlebarTransparent(); - await Window.enableFullSizeContentView(); - } - } + _initializeFirebase(); + _initializePlatformComponents(); runApp(const SolianApp()); }, ); } +Future _initializeFirebase() async { + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); +} + +Future _initializePlatformComponents() async { + if (!PlatformInfo.isWeb) { + await protocolHandler.register('solink'); + } + + if (PlatformInfo.isDesktop) { + await Window.initialize(); + + if (PlatformInfo.isMacOS) { + await Future.wait([ + Window.hideTitle(), + Window.hideCloseButton(), + Window.hideMiniaturizeButton(), + Window.hideZoomButton(), + Window.makeTitlebarTransparent(), + Window.enableFullSizeContentView(), + ]); + } + } +} + class SolianApp extends StatelessWidget { const SolianApp({super.key}); @@ -75,33 +82,7 @@ class SolianApp extends StatelessWidget { translations: SolianMessages(), locale: Get.deviceLocale, fallbackLocale: const Locale('en', 'US'), - onInit: () { - Get.lazyPut(() => AuthProvider()); - Get.lazyPut(() => FriendProvider()); - Get.lazyPut(() => PostProvider()); - Get.lazyPut(() => AttachmentProvider()); - Get.lazyPut(() => ChatProvider()); - Get.lazyPut(() => AccountProvider()); - Get.lazyPut(() => StatusProvider()); - Get.lazyPut(() => ChannelProvider()); - Get.lazyPut(() => RealmProvider()); - Get.lazyPut(() => ChatCallProvider()); - - final AuthProvider auth = Get.find(); - auth.isAuthorized.then((value) async { - if (value) { - Get.find().connect(); - Get.find().connect(); - - try { - Get.find().registerPushNotifications(); - } catch (err) { - context.showSnackbar('pushNotifyRegisterFailed' - .trParams({'reason': err.toString()})); - } - } - }); - }, + onInit: () => _initializeProviders(context), builder: (context, child) { return ListenerShell( child: ScaffoldMessenger( @@ -111,4 +92,33 @@ class SolianApp extends StatelessWidget { }, ); } + + void _initializeProviders(BuildContext context) { + Get.lazyPut(() => AuthProvider()); + Get.lazyPut(() => FriendProvider()); + Get.lazyPut(() => PostProvider()); + Get.lazyPut(() => AttachmentProvider()); + Get.lazyPut(() => ChatProvider()); + Get.lazyPut(() => AccountProvider()); + Get.lazyPut(() => StatusProvider()); + Get.lazyPut(() => ChannelProvider()); + Get.lazyPut(() => RealmProvider()); + Get.lazyPut(() => ChatCallProvider()); + + final AuthProvider auth = Get.find(); + auth.isAuthorized.then((value) async { + if (value) { + Get.find().connect(); + Get.find().connect(); + + try { + Get.find().registerPushNotifications(); + } catch (err) { + context.showSnackbar( + 'pushNotifyRegisterFailed'.trParams({'reason': err.toString()}), + ); + } + } + }); + } } diff --git a/lib/screens/auth/signup.dart b/lib/screens/auth/signup.dart index 572bf65..718f442 100644 --- a/lib/screens/auth/signup.dart +++ b/lib/screens/auth/signup.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:solian/exts.dart'; -import 'package:solian/router.dart'; import 'package:solian/services.dart'; class SignUpPopup extends StatefulWidget { diff --git a/lib/widgets/attachments/attachment_item.dart b/lib/widgets/attachments/attachment_item.dart index d327617..0818f47 100644 --- a/lib/widgets/attachments/attachment_item.dart +++ b/lib/widgets/attachments/attachment_item.dart @@ -46,7 +46,9 @@ class _AttachmentItemState extends State { _chewieController = ChewieController( aspectRatio: widget.item.metadata?['ratio'] ?? 16 / 9, videoPlayerController: _videoPlayerController!, - customControls: const MaterialControls(showPlayButton: true), + customControls: PlatformInfo.isMobile + ? const MaterialControls() + : const MaterialDesktopControls(), materialProgressColors: ChewieProgressColors( playedColor: Theme.of(context).colorScheme.primary, handleColor: Theme.of(context).colorScheme.primary, diff --git a/lib/widgets/attachments/attachment_list.dart b/lib/widgets/attachments/attachment_list.dart index fb8b543..5a48439 100644 --- a/lib/widgets/attachments/attachment_list.dart +++ b/lib/widgets/attachments/attachment_list.dart @@ -102,79 +102,81 @@ class _AttachmentListState extends State { } Widget buildEntry(Attachment element, int idx) { - return GestureDetector( - child: Container( - width: widget.width ?? MediaQuery.of(context).size.width, - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.surfaceContainerHigh, - ), - child: Stack( - fit: StackFit.expand, - children: [ - AttachmentItem( - parentId: widget.parentId, - key: Key('a${element.uuid}'), - item: element, - badge: _attachmentsMeta.length > 1 - ? '${idx + 1}/${_attachmentsMeta.length}' - : null, - showHideButton: !element.isMature || _showMature, - onHide: () { - setState(() => _showMature = false); - }, - ), - if (element.isMature && !_showMature) - BackdropFilter( - filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100), - child: Container( - decoration: BoxDecoration( - color: Colors.black.withOpacity(0.5), - ), - ), - ), - if (element.isMature && !_showMature) - Center( - child: Container( - constraints: const BoxConstraints(maxWidth: 280), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Icon(Icons.visibility_off, - color: Colors.white, size: 32), - const SizedBox(height: 8), - Text( - 'matureContent'.tr, - style: const TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - fontSize: 16), - ), - Text( - 'matureContentCaption'.tr, - style: const TextStyle(color: Colors.white), - textAlign: TextAlign.center, - ), - ], - ), - ), - ), - ], - ), - ), - onTap: () { - if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) { - setState(() => _showMature = true); - } else if (['image'].contains(element.mimetype.split('/').first)) { - Navigator.of(context, rootNavigator: true).push( - MaterialPageRoute( - builder: (context) => AttachmentListFullScreen( + return RepaintBoundary( + child: GestureDetector( + child: Container( + width: widget.width ?? MediaQuery.of(context).size.width, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surfaceContainerHigh, + ), + child: Stack( + fit: StackFit.expand, + children: [ + AttachmentItem( parentId: widget.parentId, - attachment: element, + key: Key('a${element.uuid}'), + item: element, + badge: _attachmentsMeta.length > 1 + ? '${idx + 1}/${_attachmentsMeta.length}' + : null, + showHideButton: !element.isMature || _showMature, + onHide: () { + setState(() => _showMature = false); + }, ), - ), - ); - } - }, + if (element.isMature && !_showMature) + BackdropFilter( + filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100), + child: Container( + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.5), + ), + ), + ), + if (element.isMature && !_showMature) + Center( + child: Container( + constraints: const BoxConstraints(maxWidth: 280), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.visibility_off, + color: Colors.white, size: 32), + const SizedBox(height: 8), + Text( + 'matureContent'.tr, + style: const TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 16), + ), + Text( + 'matureContentCaption'.tr, + style: const TextStyle(color: Colors.white), + textAlign: TextAlign.center, + ), + ], + ), + ), + ), + ], + ), + ), + onTap: () { + if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) { + setState(() => _showMature = true); + } else if (['image'].contains(element.mimetype.split('/').first)) { + Navigator.of(context, rootNavigator: true).push( + MaterialPageRoute( + builder: (context) => AttachmentListFullScreen( + parentId: widget.parentId, + attachment: element, + ), + ), + ); + } + }, + ), ); } diff --git a/lib/widgets/posts/post_list.dart b/lib/widgets/posts/post_list.dart index 04dd1f7..45c58f4 100644 --- a/lib/widgets/posts/post_list.dart +++ b/lib/widgets/posts/post_list.dart @@ -26,29 +26,31 @@ class PostListWidget extends StatelessWidget { pagingController: controller, builderDelegate: PagedChildBuilderDelegate( itemBuilder: (context, item, index) { - return GestureDetector( - child: PostItem( - key: Key('p${item.alias}'), - item: item, - isShowEmbed: isShowEmbed, - isClickable: isNestedClickable, - ).paddingSymmetric(vertical: 8), - onTap: () { - if (!isClickable) return; - AppRouter.instance.pushNamed( - 'postDetail', - pathParameters: {'alias': item.alias}, - ); - }, - onLongPress: () { - showModalBottomSheet( - useRootNavigator: true, - context: context, - builder: (context) => PostAction(item: item), - ).then((value) { - if (value != null) controller.refresh(); - }); - }, + return RepaintBoundary( + child: GestureDetector( + child: PostItem( + key: Key('p${item.alias}'), + item: item, + isShowEmbed: isShowEmbed, + isClickable: isNestedClickable, + ).paddingSymmetric(vertical: 8), + onTap: () { + if (!isClickable) return; + AppRouter.instance.pushNamed( + 'postDetail', + pathParameters: {'alias': item.alias}, + ); + }, + onLongPress: () { + showModalBottomSheet( + useRootNavigator: true, + context: context, + builder: (context) => PostAction(item: item), + ).then((value) { + if (value != null) controller.refresh(); + }); + }, + ), ); }, ),