improve build
This commit is contained in:
+57
-48
@@ -77,24 +77,27 @@ class _TabDraggable extends HookConsumerWidget {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
final tab = (suggestedContainerId != null)
|
// Cache the tab widget to avoid rebuilding
|
||||||
? SuggestedSingleTabPreview(
|
final tab = useMemoized(() {
|
||||||
key: ValueKey(entity.tabId),
|
return (suggestedContainerId != null)
|
||||||
tabId: entity.tabId,
|
? SuggestedSingleTabPreview(
|
||||||
activeTabId: activeTab,
|
key: ValueKey(entity.tabId),
|
||||||
containerId: suggestedContainerId!,
|
tabId: entity.tabId,
|
||||||
)
|
activeTabId: activeTab,
|
||||||
: SingleTabPreview(
|
containerId: suggestedContainerId!,
|
||||||
key: ValueKey(entity.tabId),
|
)
|
||||||
tabId: entity.tabId,
|
: SingleTabPreview(
|
||||||
activeTabId: activeTab,
|
key: ValueKey(entity.tabId),
|
||||||
onClose: onClose,
|
tabId: entity.tabId,
|
||||||
sourceSearchQuery: switch (entity) {
|
activeTabId: activeTab,
|
||||||
DefaultTabEntity _ => null,
|
onClose: onClose,
|
||||||
final SearchResultTabEntity entity => entity.searchQuery,
|
sourceSearchQuery: switch (entity) {
|
||||||
TabTreeEntity _ => throw UnimplementedError(),
|
DefaultTabEntity _ => null,
|
||||||
},
|
final SearchResultTabEntity entity => entity.searchQuery,
|
||||||
);
|
TabTreeEntity _ => throw UnimplementedError(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}, [entity.tabId, activeTab, suggestedContainerId]);
|
||||||
|
|
||||||
return switch (dragData) {
|
return switch (dragData) {
|
||||||
ContainerDropData() => Opacity(
|
ContainerDropData() => Opacity(
|
||||||
@@ -381,7 +384,7 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
],
|
],
|
||||||
body: HookConsumer(
|
body: HookConsumer(
|
||||||
builder: (context, ref, child) {
|
builder: (context, ref, child) {
|
||||||
final gridViewKey = useMemoized(() => GlobalKey());
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
final containerId = ref.watch(selectedContainerProvider);
|
final containerId = ref.watch(selectedContainerProvider);
|
||||||
|
|
||||||
@@ -421,24 +424,24 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
|
|
||||||
final crossAxisCount = useMemoized(() {
|
final crossAxisCount = useMemoized(() {
|
||||||
final calculatedCount = _calculateCrossAxisItemCount(
|
final calculatedCount = _calculateCrossAxisItemCount(
|
||||||
screenWidth: MediaQuery.of(context).size.width,
|
screenWidth: screenWidth,
|
||||||
horizontalPadding: 4.0,
|
horizontalPadding: 4.0,
|
||||||
crossAxisSpacing: 8.0,
|
crossAxisSpacing: 8.0,
|
||||||
);
|
);
|
||||||
|
|
||||||
return math.max(math.min(calculatedCount, itemCount), 2);
|
return math.max(math.min(calculatedCount, itemCount), 2);
|
||||||
}, [MediaQuery.of(context).size.width, itemCount]);
|
}, [screenWidth, itemCount]);
|
||||||
|
|
||||||
final itemHeight = useMemoized(
|
final itemHeight = useMemoized(
|
||||||
() => _calculateItemHeight(
|
() => _calculateItemHeight(
|
||||||
screenWidth: MediaQuery.of(context).size.width,
|
screenWidth: screenWidth,
|
||||||
childAspectRatio: 0.75,
|
childAspectRatio: 0.75,
|
||||||
horizontalPadding: 4.0,
|
horizontalPadding: 4.0,
|
||||||
mainAxisSpacing: 8.0,
|
mainAxisSpacing: 8.0,
|
||||||
crossAxisSpacing: 8.0,
|
crossAxisSpacing: 8.0,
|
||||||
crossAxisCount: crossAxisCount,
|
crossAxisCount: crossAxisCount,
|
||||||
),
|
),
|
||||||
[MediaQuery.of(context).size.width, crossAxisCount],
|
[screenWidth, crossAxisCount],
|
||||||
);
|
);
|
||||||
|
|
||||||
final lastScroll = useRef<String?>(null);
|
final lastScroll = useRef<String?>(null);
|
||||||
@@ -473,28 +476,6 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
return null;
|
return null;
|
||||||
}, [filteredTabEntities, activeTab]);
|
}, [filteredTabEntities, activeTab]);
|
||||||
|
|
||||||
final tabs = useMemoized(() {
|
|
||||||
return [
|
|
||||||
...filteredTabEntities.value.map(
|
|
||||||
(entity) => CustomDraggable(
|
|
||||||
key: Key(entity.tabId),
|
|
||||||
data: TabDragData(entity.tabId),
|
|
||||||
child: _TabDraggable(entity: entity, onClose: onClose),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
...suggestedTabEntities.value.map(
|
|
||||||
(entity) => CustomDraggable(
|
|
||||||
key: Key('suggested_${entity.tabId}'),
|
|
||||||
child: _TabDraggable(
|
|
||||||
entity: entity,
|
|
||||||
onClose: onClose,
|
|
||||||
suggestedContainerId: containerId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}, [filteredTabEntities, suggestedTabEntities]);
|
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
child: FadingScroll(
|
child: FadingScroll(
|
||||||
@@ -563,7 +544,6 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
},
|
},
|
||||||
childBuilder: (itemBuilder) {
|
childBuilder: (itemBuilder) {
|
||||||
return GridView.builder(
|
return GridView.builder(
|
||||||
key: gridViewKey,
|
|
||||||
controller: controller,
|
controller: controller,
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
//Sync values for itemHeight calculation _calculateItemHeight
|
//Sync values for itemHeight calculation _calculateItemHeight
|
||||||
@@ -573,8 +553,37 @@ class ViewTabsSheetWidget extends HookConsumerWidget {
|
|||||||
crossAxisCount: crossAxisCount,
|
crossAxisCount: crossAxisCount,
|
||||||
),
|
),
|
||||||
itemCount: itemCount,
|
itemCount: itemCount,
|
||||||
itemBuilder: (context, index) =>
|
itemBuilder: (context, index) {
|
||||||
itemBuilder(tabs[index], index),
|
final Widget tab;
|
||||||
|
if (index < filteredTabEntities.value.length) {
|
||||||
|
final entity = filteredTabEntities.value[index];
|
||||||
|
tab = CustomDraggable(
|
||||||
|
key: Key(entity.tabId),
|
||||||
|
data: TabDragData(entity.tabId),
|
||||||
|
child: _TabDraggable(
|
||||||
|
entity: entity,
|
||||||
|
onClose: onClose,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final suggestedIndex =
|
||||||
|
index - filteredTabEntities.value.length;
|
||||||
|
final entity =
|
||||||
|
suggestedTabEntities.value[suggestedIndex];
|
||||||
|
tab = CustomDraggable(
|
||||||
|
key: Key('suggested_${entity.tabId}'),
|
||||||
|
child: _TabDraggable(
|
||||||
|
entity: entity,
|
||||||
|
onClose: onClose,
|
||||||
|
suggestedContainerId: ref.watch(
|
||||||
|
selectedContainerProvider,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemBuilder(tab, index);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user