Skip to content

Commit f32b7ae

Browse files
committed
⚡️ Slightly enhance performance with widgets layout
1 parent b593d5e commit f32b7ae

15 files changed

+484
-555
lines changed

example/lib/pages/custom_picker_page.dart

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -704,56 +704,50 @@ class FileAssetPickerBuilder
704704
final double maxHeight = Screens.height * 0.825;
705705
return Selector<FileAssetPickerProvider, bool>(
706706
selector: (_, FileAssetPickerProvider p) => p.isSwitchingPath,
707-
builder: (_, bool isSwitchingPath, __) {
708-
return AnimatedPositioned(
707+
builder: (_, bool isSwitchingPath, Widget? w) => AnimatedPositioned(
708+
duration: switchingPathDuration,
709+
curve: switchingPathCurve,
710+
top: isAppleOS
711+
? !isSwitchingPath
712+
? -maxHeight
713+
: appBarHeight
714+
: -(!isSwitchingPath ? maxHeight : 1.0),
715+
child: AnimatedOpacity(
709716
duration: switchingPathDuration,
710717
curve: switchingPathCurve,
711-
top: isAppleOS
712-
? !isSwitchingPath
713-
? -maxHeight
714-
: appBarHeight
715-
: -(!isSwitchingPath ? maxHeight : 1.0),
716-
child: AnimatedOpacity(
717-
duration: switchingPathDuration,
718-
curve: switchingPathCurve,
719-
opacity: !isAppleOS || isSwitchingPath ? 1.0 : 0.0,
720-
child: Container(
721-
width: Screens.width,
722-
height: maxHeight,
723-
decoration: BoxDecoration(
724-
borderRadius: isAppleOS
725-
? const BorderRadius.only(
726-
bottomLeft: Radius.circular(10.0),
727-
bottomRight: Radius.circular(10.0),
728-
)
729-
: null,
730-
color: theme.colorScheme.background,
731-
),
732-
child:
733-
Selector<FileAssetPickerProvider, Map<Directory, Uint8List?>>(
734-
selector: (_, FileAssetPickerProvider p) => p.pathEntityList,
735-
builder: (_, Map<Directory, Uint8List?> pathEntityList, __) {
736-
return ListView.separated(
737-
padding: const EdgeInsets.only(top: 1.0),
738-
itemCount: pathEntityList.length,
739-
itemBuilder: (BuildContext _, int index) {
740-
return pathEntityWidget(
741-
context,
742-
pathEntityList.keys.elementAt(index),
743-
);
744-
},
745-
separatorBuilder: (BuildContext _, int __) => Container(
746-
margin: const EdgeInsets.only(left: 60.0),
747-
height: 1.0,
748-
color: theme.canvasColor,
749-
),
750-
);
751-
},
752-
),
718+
opacity: !isAppleOS || isSwitchingPath ? 1.0 : 0.0,
719+
child: Container(
720+
width: Screens.width,
721+
height: maxHeight,
722+
decoration: BoxDecoration(
723+
borderRadius: isAppleOS
724+
? const BorderRadius.vertical(bottom: Radius.circular(10.0))
725+
: null,
726+
color: theme.colorScheme.background,
753727
),
728+
child: w,
754729
),
755-
);
756-
},
730+
),
731+
),
732+
child: Selector<FileAssetPickerProvider, Map<Directory, Uint8List?>>(
733+
selector: (_, FileAssetPickerProvider p) => p.pathEntityList,
734+
builder: (_, Map<Directory, Uint8List?> pathEntityList, __) {
735+
return ListView.separated(
736+
padding: const EdgeInsets.only(top: 1.0),
737+
itemCount: pathEntityList.length,
738+
itemBuilder: (_, int index) => pathEntityWidget(
739+
context: context,
740+
list: pathEntityList,
741+
index: index,
742+
),
743+
separatorBuilder: (_, __) => Container(
744+
margin: const EdgeInsets.only(left: 60.0),
745+
height: 1.0,
746+
color: theme.canvasColor,
747+
),
748+
);
749+
},
750+
),
757751
);
758752
}
759753

@@ -817,15 +811,18 @@ class FileAssetPickerBuilder
817811
}
818812

819813
@override
820-
Widget pathEntityWidget(BuildContext context, Directory path) {
821-
Widget builder(
822-
BuildContext context,
823-
Map<Directory, Uint8List?> pathEntityList,
824-
Widget? child,
825-
) {
826-
final Uint8List? thumbData = pathEntityList[path];
827-
if (thumbData != null) {
828-
return Image.memory(thumbData, fit: BoxFit.cover);
814+
Widget pathEntityWidget({
815+
required BuildContext context,
816+
required Map<Directory, Uint8List?> list,
817+
required int index,
818+
bool isAudio = false,
819+
}) {
820+
final Directory path = list.keys.elementAt(index);
821+
final Uint8List? data = list.values.elementAt(index);
822+
823+
Widget builder() {
824+
if (data != null) {
825+
return Image.memory(data, fit: BoxFit.cover);
829826
} else {
830827
return ColoredBox(
831828
color: theme.colorScheme.primary.withOpacity(0.12),
@@ -843,18 +840,7 @@ class FileAssetPickerBuilder
843840
child: Row(
844841
children: <Widget>[
845842
RepaintBoundary(
846-
child: AspectRatio(
847-
aspectRatio: 1.0,
848-
child: Selector<FileAssetPickerProvider,
849-
Map<Directory, Uint8List?>>(
850-
selector: (
851-
BuildContext _,
852-
FileAssetPickerProvider provider,
853-
) =>
854-
provider.pathEntityList,
855-
builder: builder,
856-
),
857-
),
843+
child: AspectRatio(aspectRatio: 1.0, child: builder()),
858844
),
859845
Expanded(
860846
child: Padding(
@@ -1096,9 +1082,9 @@ class FileAssetPickerViewerBuilderDelegate
10961082
}
10971083

10981084
void updateAnimation(ExtendedImageGestureState state) {
1099-
final double begin = state.gestureDetails.totalScale;
1100-
final double end = state.gestureDetails.totalScale == 1.0 ? 3.0 : 1.0;
1101-
final Offset pointerDownPosition = state.pointerDownPosition;
1085+
final double begin = state.gestureDetails!.totalScale!;
1086+
final double end = state.gestureDetails!.totalScale! == 1.0 ? 3.0 : 1.0;
1087+
final Offset pointerDownPosition = state.pointerDownPosition!;
11021088

11031089
_doubleTapAnimation?.removeListener(_doubleTapListener);
11041090
_doubleTapAnimationController

example/lib/pages/splash_page.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ class _SplashPageState extends State<SplashPage> {
2727
() {
2828
Navigator.of(context).pushReplacement(
2929
PageRouteBuilder<void>(
30-
pageBuilder: (
31-
BuildContext _,
32-
Animation<double> __,
33-
Animation<double> ___,
34-
) {
35-
return const HomePage();
36-
},
30+
pageBuilder: (_, __, ___) => const HomePage(),
3731
transitionsBuilder: (
38-
BuildContext _,
32+
_,
3933
Animation<double> animation,
4034
Animation<double> secondaryAnimation,
4135
Widget child,

example/pubspec.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name: wechat_assets_picker_demo
22
description: A new Flutter project.
33
version: 1.0.0+1
4+
publish_to: none
45

56
environment:
6-
sdk: ">=2.12.0-0 <3.0.0"
7-
flutter: ">=1.17.0 <2.0.0"
7+
sdk: ">=2.12.0 <3.0.0"
8+
flutter: ">=2.0.0"
89

910
dependencies:
1011
flutter:
@@ -14,13 +15,10 @@ dependencies:
1415
path: ../
1516
wechat_camera_picker: ^2.0.0-nullsafety.4
1617

17-
extended_image: ^1.5.0
18+
extended_image: ^3.0.0
1819
path: ^1.8.0
1920
path_provider: ^2.0.0
20-
provider: ^5.0.0-nullsafety.5
21-
22-
dependency_overrides:
23-
path_provider: ^2.0.0
21+
provider: ^5.0.0
2422

2523
flutter:
2624
uses-material-design: true

0 commit comments

Comments
 (0)