Basic optimization of repainting

This commit is contained in:
LittleSheep 2024-07-05 23:37:54 +08:00
parent 867b024285
commit 20a82da2fa
5 changed files with 158 additions and 143 deletions

View File

@ -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<void> _initializeFirebase() async {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
}
Future<void> _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<AccountProvider>().connect();
Get.find<ChatProvider>().connect();
try {
Get.find<AccountProvider>().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<AccountProvider>().connect();
Get.find<ChatProvider>().connect();
try {
Get.find<AccountProvider>().registerPushNotifications();
} catch (err) {
context.showSnackbar(
'pushNotifyRegisterFailed'.trParams({'reason': err.toString()}),
);
}
}
});
}
}

View File

@ -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 {

View File

@ -46,7 +46,9 @@ class _AttachmentItemState extends State<AttachmentItem> {
_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,

View File

@ -102,79 +102,81 @@ class _AttachmentListState extends State<AttachmentList> {
}
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,
),
),
);
}
},
),
);
}

View File

@ -26,29 +26,31 @@ class PostListWidget extends StatelessWidget {
pagingController: controller,
builderDelegate: PagedChildBuilderDelegate<Post>(
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();
});
},
),
);
},
),