⚡ Basic optimization of repainting
This commit is contained in:
parent
867b024285
commit
20a82da2fa
104
lib/main.dart
104
lib/main.dart
@ -33,32 +33,39 @@ void main() async {
|
|||||||
appRunner: () async {
|
appRunner: () async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
if (!PlatformInfo.isWeb) {
|
_initializeFirebase();
|
||||||
await protocolHandler.register('solink');
|
_initializePlatformComponents();
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
runApp(const SolianApp());
|
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 {
|
class SolianApp extends StatelessWidget {
|
||||||
const SolianApp({super.key});
|
const SolianApp({super.key});
|
||||||
|
|
||||||
@ -75,33 +82,7 @@ class SolianApp extends StatelessWidget {
|
|||||||
translations: SolianMessages(),
|
translations: SolianMessages(),
|
||||||
locale: Get.deviceLocale,
|
locale: Get.deviceLocale,
|
||||||
fallbackLocale: const Locale('en', 'US'),
|
fallbackLocale: const Locale('en', 'US'),
|
||||||
onInit: () {
|
onInit: () => _initializeProviders(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()}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
builder: (context, child) {
|
builder: (context, child) {
|
||||||
return ListenerShell(
|
return ListenerShell(
|
||||||
child: ScaffoldMessenger(
|
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()}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:solian/exts.dart';
|
import 'package:solian/exts.dart';
|
||||||
import 'package:solian/router.dart';
|
|
||||||
import 'package:solian/services.dart';
|
import 'package:solian/services.dart';
|
||||||
|
|
||||||
class SignUpPopup extends StatefulWidget {
|
class SignUpPopup extends StatefulWidget {
|
||||||
|
@ -46,7 +46,9 @@ class _AttachmentItemState extends State<AttachmentItem> {
|
|||||||
_chewieController = ChewieController(
|
_chewieController = ChewieController(
|
||||||
aspectRatio: widget.item.metadata?['ratio'] ?? 16 / 9,
|
aspectRatio: widget.item.metadata?['ratio'] ?? 16 / 9,
|
||||||
videoPlayerController: _videoPlayerController!,
|
videoPlayerController: _videoPlayerController!,
|
||||||
customControls: const MaterialControls(showPlayButton: true),
|
customControls: PlatformInfo.isMobile
|
||||||
|
? const MaterialControls()
|
||||||
|
: const MaterialDesktopControls(),
|
||||||
materialProgressColors: ChewieProgressColors(
|
materialProgressColors: ChewieProgressColors(
|
||||||
playedColor: Theme.of(context).colorScheme.primary,
|
playedColor: Theme.of(context).colorScheme.primary,
|
||||||
handleColor: Theme.of(context).colorScheme.primary,
|
handleColor: Theme.of(context).colorScheme.primary,
|
||||||
|
@ -102,79 +102,81 @@ class _AttachmentListState extends State<AttachmentList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget buildEntry(Attachment element, int idx) {
|
Widget buildEntry(Attachment element, int idx) {
|
||||||
return GestureDetector(
|
return RepaintBoundary(
|
||||||
child: Container(
|
child: GestureDetector(
|
||||||
width: widget.width ?? MediaQuery.of(context).size.width,
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
width: widget.width ?? MediaQuery.of(context).size.width,
|
||||||
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
decoration: BoxDecoration(
|
||||||
),
|
color: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||||
child: Stack(
|
),
|
||||||
fit: StackFit.expand,
|
child: Stack(
|
||||||
children: [
|
fit: StackFit.expand,
|
||||||
AttachmentItem(
|
children: [
|
||||||
parentId: widget.parentId,
|
AttachmentItem(
|
||||||
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,
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,29 +26,31 @@ class PostListWidget extends StatelessWidget {
|
|||||||
pagingController: controller,
|
pagingController: controller,
|
||||||
builderDelegate: PagedChildBuilderDelegate<Post>(
|
builderDelegate: PagedChildBuilderDelegate<Post>(
|
||||||
itemBuilder: (context, item, index) {
|
itemBuilder: (context, item, index) {
|
||||||
return GestureDetector(
|
return RepaintBoundary(
|
||||||
child: PostItem(
|
child: GestureDetector(
|
||||||
key: Key('p${item.alias}'),
|
child: PostItem(
|
||||||
item: item,
|
key: Key('p${item.alias}'),
|
||||||
isShowEmbed: isShowEmbed,
|
item: item,
|
||||||
isClickable: isNestedClickable,
|
isShowEmbed: isShowEmbed,
|
||||||
).paddingSymmetric(vertical: 8),
|
isClickable: isNestedClickable,
|
||||||
onTap: () {
|
).paddingSymmetric(vertical: 8),
|
||||||
if (!isClickable) return;
|
onTap: () {
|
||||||
AppRouter.instance.pushNamed(
|
if (!isClickable) return;
|
||||||
'postDetail',
|
AppRouter.instance.pushNamed(
|
||||||
pathParameters: {'alias': item.alias},
|
'postDetail',
|
||||||
);
|
pathParameters: {'alias': item.alias},
|
||||||
},
|
);
|
||||||
onLongPress: () {
|
},
|
||||||
showModalBottomSheet(
|
onLongPress: () {
|
||||||
useRootNavigator: true,
|
showModalBottomSheet(
|
||||||
context: context,
|
useRootNavigator: true,
|
||||||
builder: (context) => PostAction(item: item),
|
context: context,
|
||||||
).then((value) {
|
builder: (context) => PostAction(item: item),
|
||||||
if (value != null) controller.refresh();
|
).then((value) {
|
||||||
});
|
if (value != null) controller.refresh();
|
||||||
},
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user