Skip to content

Commit 4695966

Browse files
committed
fix(ui): improve end fade visibility in SourceCategoryRow
- Add post-frame callback to determine if end fade is needed - Optimize fade-in/out logic for better performance - Refactor fade visibility checks for clarity
1 parent ce0e73c commit 4695966

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/discover/view/discover_page.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,21 @@ class _SourceCategoryRow extends StatefulWidget {
123123

124124
class _SourceCategoryRowState extends State<_SourceCategoryRow> {
125125
final _scrollController = ScrollController();
126+
bool _showEndFade = false;
126127

127128
@override
128129
void initState() {
129130
super.initState();
130131
_scrollController.addListener(() => setState(() {}));
132+
WidgetsBinding.instance.addPostFrameCallback((_) {
133+
if (mounted &&
134+
_scrollController.hasClients &&
135+
_scrollController.position.maxScrollExtent > 0) {
136+
setState(() {
137+
_showEndFade = true;
138+
});
139+
}
140+
});
131141
}
132142

133143
@override
@@ -201,13 +211,13 @@ class _SourceCategoryRowState extends State<_SourceCategoryRow> {
201211
if (_scrollController.hasClients &&
202212
_scrollController.position.maxScrollExtent > 0) {
203213
final pixels = _scrollController.position.pixels;
204-
final minScroll = _scrollController.position.minScrollExtent;
205-
final maxScroll = _scrollController.position.maxScrollExtent;
206214

207-
if (pixels > minScroll) {
215+
if (pixels > _scrollController.position.minScrollExtent) {
208216
showStartFade = true;
209217
}
210-
if (pixels < maxScroll) {
218+
if (pixels < _scrollController.position.maxScrollExtent) {
219+
showEndFade = true;
220+
} else {
211221
showEndFade = true;
212222
}
213223
}
@@ -216,7 +226,7 @@ class _SourceCategoryRowState extends State<_SourceCategoryRow> {
216226
if (showStartFade) Colors.transparent,
217227
Colors.black,
218228
Colors.black,
219-
if (showEndFade) Colors.transparent,
229+
if (_showEndFade) Colors.transparent,
220230
];
221231

222232
final stops = <double>[

0 commit comments

Comments
 (0)