'Why is SliverFillRemaining expanding too much?
I'm trying to make a SliverAppBar that reacts to its height, showing different things depending if it's expanded or not.
I've based it on https://medium.com/flutter-community/flutter-sliverappbar-snap-those-headers-544e097248c0, but I'm having an issue:
The empty space at the end of the list is way too long.
Removing SliverFillRemaining is not necessary if the number of items is high, but changing the numberOfItems to e.g. 3 items (instead of 30), the SliverFillRemaining is necessary.
Check out this dartpad for the code: https://dartpad.dev/2c434ddf2d4d1e87bd4b421f0a673c2d
CustomScrollView(
physics: AlwaysScrollableScrollPhysics(),
controller: _controller,
slivers: [
SliverAppBar(
pinned: true,
backgroundColor: Colors.grey[100],
stretch: true,
automaticallyImplyLeading: false,
flexibleSpace: Header(
maxHeight: maxHeight,
minHeight: minHeight,
),
collapsedHeight: minimizedHeight,
expandedHeight: maxHeight - MediaQuery.of(context).padding.top,
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return _buildCard(index);
},
childCount: numberOfItems,
),
),
SliverFillRemaining(
hasScrollBody: true), // ** <-- this will add space, but too much **
],
),
Solution 1:[1]
make the hasScrollBody value to be false like this:
SliverFillRemaining(
hasScrollBody: false
),
Solution 2:[2]
to play audios i use this library audioplayers: ^0.19.1 declare this variable to access audio
String audioCorrect = "audio/access_granted.mp3";
String audioInCorrect = "audio/access_denied.mp3";
method for init player
void initPlayer() {
advancedPlayer = new AudioPlayer();
audioCache = new AudioCache(fixedPlayer: advancedPlayer);
}
call initPlayer in initState method play the audio this way
audioCache.play(audioCorrect);
Solution 3:[3]
It's played Now I was missing that the file extension is aac not acc
so it should be
await _audioPlayer!.startPlayer(
fromURI: 'https://URL/TestFiles/sssssssss.aac',
);
} catch (e) {
print(e);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MwBakker |
| Solution 2 | Elvis Salabarria Aquino |
| Solution 3 |
